Search code examples
eachoperator-keywordapl

APL2, order of processing each operator arguments


Assuming the user function:

∇ f b
[1] b
∇

and the following is executed: f¨1 2 3

Three lines will display, 1 digit per line. In APLX the order is 1 2 3. Is there any APL2 guarantee the order the digits will be displayed?

This can be critical if the user function has side-effects. I'd think this would be documented somewhere, but heck if I can find it.


Solution

  • The APL Language Reference says:

    ⁝
    Z←0ρV
    L1:→(0=ρV)/L1X
    Z←Z,⊂F↑V
    V←1↓V
    →L1
    L1X:
    ⁝
    

    The above loop can be replaced by:

    Z←F¨ V
    

    This clearly implies that ¨ runs in reliable order.

    Furthermore, the ISO/IEC 13751 (2001) Programming language Extended APL, which is based on APL2, says:

     Create Z, an array having the same shape-list as B.
     For each I in the index-set of the ravel-list of Z:
      For form B,
       Set X to item I of the ravel-list of B.
       Evaluate-Monadic-Function with fX giving token T.

    This clearly specifies that the operand is to be applied in sequence, its evaluation needing completion before proceding to the next item in the ravel order.