Multi-level List Operations

The sublists in an MLIST structure are themselves MLISTs, so all of the above operations work the same way on sublists. However, you do need a special dot-member, .SUBLIST, to specify when you are referring to the sublist for an element, rather than to the element as a member of the parent list.

There are two ways to create a sublist, both involving the use of the special .SUBLIST qualifier.

Documentation on the first method is not yet ready for publication.

~~~~======= !=== <this first method doesn't yet work> === ~~~~=======

The first way to create a sublist is to splice elements from another list on to the .SUBLIST member of an element in the destination list, for example:

.SPLICE $m(.BACK).SUBLIST, $m2()

The above statement splices the list $m2() as a sublist of the last element in $m(). Note that without the .SUBLIST modifier, the $m2() list would have been spliced on to the $m() list, just before the last element.

foreach $$i in $m()

    if $$i = "something" then

        .SPLICE $$i.SUBLIST, $m2, 3

        exit

    endif

next $$i

 

In the above example, we scan the $m() list for an element with value "something", and then splice the first 3 elements of the $m2() list as a sublist of that target element.

~~~~~~~~~======= !=== <this method works> === ~~~~~~~~~=======

The second way to create a sublist involves passing it as a parameter to a function or procedure, which is dealt with in a separate section below, after the discussion of deleting sublists.

To delete a sublist, assign .NULL to the target element, either using one of the dot-variable pseudo-keys, or using an iterator to target the element:

$m(.BACK) = .NULL      ! delete sublist from last element of $m()

 

foreach $$i in $m()

    if $$i = "something" then

        $$i.SUBLIST = .NULL

        exit

    endif

next $$

 

The above examples delete the sublist without deleting the element itself. Deleting the element will also delete any sublist(s) attached to it.