Please enable JavaScript to view this site.

A-Shell Reference

MLISTs can be passed by reference to functions and procedures. This is similar to the way it works with Ordered Maps except that with MLISTs there is also a variation for passing sublists.

To pass a regular MLIST to a function or procedure, use the following syntax (nearly identical to that for ORDMAPs except for the "AS" clause):

call Proc( $m() )   ! passing the entire $m list by reference

 

Procedure Proc( $mloc() as MLIST(varstr) )

    $mloc(.PUSHBACK) = "new element"

EndProcedure

 

The above example adds the element "new element" to the MLIST $m(). Note that the local list $mloc() is effectively just an alias for the $m() list. As with passing ORDMAP arrays and other DIMX arrays by reference, you have to initialize the array first in the calling routine.

The pre-initialization requirement does not apply to sublists though, which are automatically initalized when passing them to another routine:

call Proc( $m(.back).SUBLIST )

In the above example, the SUBLIST for the last element of the $m() list is passed to the Proc procedure (given in the previous example). Note that the procedure does not know, or care, that the caller passed a sublist rather than an MLIST base reference; they are indistinguishable from the perspective of the procedure. Also note that since the sublist gets auto-initialized if necessary, the same syntax works regardless of whether the sublist initially exists.

You can also pass a sublist of an iterator, e.g.

foreach $$i in $m()

    if $$i = "something" then

        call Proc($$i.sublist)

    endif

next $$i

 

In the above example, for each element in the MLIST $m() whose value is "something", we pass the sublist to the Proc procedure, which adds a "new element" to the end of that sublist.