Please enable JavaScript to view this site.

A-Shell Reference

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 .SPLICE statement and the special .SUBLIST qualifier.  The first method involves iterating through the destination list to the element you want to attach a sublist to, and then using the .SPLICE as in the following example which splices the first 3 elements of the $mpets() list into the $mkids() list as a sublist of the element whose value is "blake":

foreach $$i in $mkids()

    if $$i = "blake" then

        .splice $$i.sublist, $mpets(), 3   

        exit

    endif

next $$i

 

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, iterate to the parent element and then assign its sublist to .NULL, as in the following example which removes the sublist (whether it existed or not) from the element whose value is "something"...

foreach $$i in $m()

    if $$i = "something" then

        $$i.SUBLIST = .NULL       ! delete just the sublist

        ! $m(.REF($$i)) = .NULL   ! delete the element and its sublist

        exit

    endif

next $$

 

Assigning an element to .NULL (as in the commented-out line in the example above) deletes both the element and any sublist attached to it.

See Also

Example program MLIST2.BP in EXLIB:[907,53]