System Labels: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
Line 32: Line 32:
<p>For example, as a UDFO</p>
<p>For example, as a UDFO</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;∇ Z←{L} foo R<br />
<apll><pre>
[1]&nbsp;&nbsp;&nbsp;Z←L,R ⋄ →0<br />
    ∇ Z←{L} foo R
[2]&nbsp;&nbsp;&nbsp;⎕ID :Z←'Identity' ,(⎕NC 'L'),(⎕NC 'R') ⋄ →0<br />
[1]   Z←L,R ⋄ →0
[3]&nbsp;&nbsp;&nbsp;⎕MS :Z←'Multiset' ,(⎕NC 'L'),(⎕NC 'R') ⋄ →0<br />
[2]   ⎕ID :Z←'Identity' ,(⎕NC 'L'),(⎕NC 'R') ⋄ →0
[4]&nbsp;&nbsp;&nbsp;⎕PRO:Z←'Prototype',(⎕NC 'L'),(⎕NC 'R') ⋄ →0<br />
[3]   ⎕MS :Z←'Multiset' ,(⎕NC 'L'),(⎕NC 'R') ⋄ →0
&nbsp;&nbsp;&nbsp;&nbsp;∇<br /></apll>
[4]   ⎕PRO:Z←'Prototype',(⎕NC 'L'),(⎕NC 'R') ⋄ →0
   
</pre></apll>


or equivalently as an AFO
or equivalently as an AFO


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo←{<br />
<apll><pre>
<span style="color:blue;">➥</span>0:⍺←0 ⋄ ⍺,⍵<br />
      foo←{
<span style="color:blue;">➥</span>⋄ ⎕ID :'Identity' ,(⎕NC '⍺'),⎕NC '⍵'<br />
<span style="color:blue;">➥</span>0:⍺←0 ⋄ ⍺,⍵
<span style="color:blue;">➥</span>⋄ ⎕MS :'Multiset' ,(⎕NC '⍺'),⎕NC '⍵'<br />
<span style="color:blue;">➥</span>⋄ ⎕ID :'Identity' ,(⎕NC '⍺'),⎕NC '⍵'
<span style="color:blue;">➥</span>⋄ ⎕PRO:'Prototype',(⎕NC '⍺'),⎕NC '⍵'}<br />
<span style="color:blue;">➥</span>⋄ ⎕MS :'Multiset' ,(⎕NC '⍺'),⎕NC '⍵'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕fmt foo/⍬<br />
<span style="color:blue;">➥</span>⋄ ⎕PRO:'Prototype',(⎕NC '⍺'),⎕NC '⍵'}
┌──────────────┐<br />
      ⎕FMT foo/⍬
│┌8───────────┐│<br />
┌──────────────┐
││Identity 0 2││<br />
│┌8───────────┐│
│└────────────┘2<br />
││Identity 0 2││
└∊─────────────┘<br />
│└────────────┘2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{⍺+÷⍵ ⋄ ⎕ID:∞}/⍬<br />
└∊─────────────┘
<br />
      {⍺+÷⍵ ⋄ ⎕ID:∞}/⍬
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{⍺+÷⍵ ⋄ ⎕ID:∞}\7⍴1<br />
1 2 1.5 1.666666667 1.6 1.625 1.615384615<br />
      {⍺+÷⍵ ⋄ ⎕ID:∞}\7⍴1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo⍦ 1<br />
1 2 1.5 1.666666667 1.6 1.625 1.615384615
Multiset 0 2<br />
      foo⍦ 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 foo⍦ 1<br />
Multiset 0 2
Multiset 2 2<br />
      2 foo⍦ 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕fmt 1 foo¨⍬<br />
Multiset 2 2
┌0──────────────┐<br />
      ⎕FMT 1 foo¨⍬
│┌11───────────┐│<br />
┌0──────────────┐
││&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 0││<br />
│┌11───────────┐│
│└─────────────┘2<br />
││         0 0││
└∊──────────────┘<br />
│└─────────────┘2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo/¨0⍴⊂⍬<br />
└∊──────────────┘
NONCE ERROR<br />
      foo/¨0⍴⊂⍬
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo/¨0⍴⊂⍬<br />
NONCE ERROR
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;∧</apll>
      foo/¨0⍴⊂⍬
        ∧
</pre></apll>


* <p>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 <apll>foo/3 0⍴⊂⍳4</apll>, the (right) argument passed to the <apll>⎕ID:</apll> entry point is <apll>0 0 0 0</apll>.  The return value from the AFO/UDFO is used as the common item in the result.  Thus, the <apll>⎕ID</apll> entry point is called only once even though the result may have multiple copies of the return value.</p>
* <p>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 <apll>foo/3 0⍴⊂⍳4</apll>, the (right) argument passed to the <apll>⎕ID:</apll> entry point is <apll>0 0 0 0</apll>.  The return value from the AFO/UDFO is used as the common item in the result.  Thus, the <apll>⎕ID</apll> entry point is called only once even though the result may have multiple copies of the return value.</p>

Revision as of 11:36, 28 April 2018

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.

⎕ID: is called when an identity element is needed as in foo/R where R is empty.
⎕MS: is called when an AFO/UDFO is invoked by the Multiset Operator.
⎕PRO: is called when a prototype element is needed as in foo¨R where R is empty, or L foo¨R where one of both of L or R is empty and the other is conformable.


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.