System Labels
Normally, execution of an Anonymous Function/Operator (AFO) or User-Defined Function/Operator (UDFO) starts execution at line one. However, in certain contexts, execution may start at a different place depending upon the context and the presence of a System Label. These special labels start with a quad symbol so as to distinguish them from normal labels. The following table lists the system labels defined so far and the special context in which they are used.
|
For example, as a UDFO
∇ Z←{L} foo R [1] Z←L,R ⋄ →0 [2] ⎕ID :Z←'Identity' ,(⎕NC 'L'),(⎕NC 'R') ⋄ →0 [3] ⎕MS :Z←'Multiset' ,(⎕NC 'L'),(⎕NC 'R') ⋄ →0 [4] ⎕PRO:Z←'Prototype',(⎕NC 'L'),(⎕NC 'R') ⋄ →0 ∇
or equivalently as an AFO
foo←{ ➥0:⍺←0 ⋄ ⍺,⍵ ➥⋄ ⎕ID :'Identity' ,(⎕NC '⍺'),⎕NC '⍵' ➥⋄ ⎕MS :'Multiset' ,(⎕NC '⍺'),⎕NC '⍵' ➥⋄ ⎕PRO:'Prototype',(⎕NC '⍺'),⎕NC '⍵'} ⎕FMT foo/⍬ ┌──────────────┐ │┌8───────────┐│ ││Identity 0 2││ │└────────────┘2 └∊─────────────┘ {⍺+÷⍵ ⋄ ⎕ID:∞}/⍬ ∞ {⍺+÷⍵ ⋄ ⎕ID:∞}\7⍴1 1 2 1.5 1.666666667 1.6 1.625 1.615384615 foo⍦ 1 Multiset 0 2 2 foo⍦ 1 Multiset 2 2 ⎕FMT 1 foo¨⍬ ┌0──────────────┐ │┌11───────────┐│ ││ 0 0││ │└─────────────┘2 └∊──────────────┘ foo/¨0⍴⊂⍬ NONCE ERROR foo/¨0⍴⊂⍬ ∧
In the Identity element case, the AFO/UDFO is called with the Reduction function's right argument prototype as the right argument to the AFO/UDFO; the left argument is undefined. For example, in foo/3 0⍴⊂⍳4, the (right) argument passed to the ⎕ID: entry point is 0 0 0 0. The return value from the AFO/UDFO is used as the common item in the result. Thus, the ⎕ID entry point is called only once even though the result may have multiple copies of the return value.
In the Multiset case, the AFO/UDFO is called with the same argument(s) as the Multiset derived function.
In the Prototype case, the AFO/UDFO is called with arguments that are the prototypes of the respective arguments; in the monadic case, the left argument is undefined.
For the moment, if two or more system labels would be called at the same time (such as the last example above), a NONCE ERROR is signaled.
- This idea was taken from the paper by David A. Rabenhorst, "APL function variants and system labels", ACM SIGAPL APL Quote Quad, APL83, Volume 13, Issue 3 (March 1983), pp. 281-284.