System Labels: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
Line 6: Line 6:
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <tr>
     <tr>
       <td valign="top"><apll>⎕PRO:</apll></td>
       <td valign="top"><apll>⎕ID:</apll></td>
      <td></td>
      <td></td>
      <td>is called when an identity element is needed as in <apll>foo/R</apll> where <apll>R</apll> is empty.</td>
    </tr>
 
    <tr>
      <td valign="top"><apll>⎕MS:</apll></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td>is called where a prototype element is needed as in <apll>foo¨R</apll> where <apll>R</apll> is empty, or <apll>L foo¨R</apll> where one of both of <apll>L</apll> or <apll>R</apll> is empty and the other is conformable.</td>
       <td>is called when a user-defined function/operator is invoked by the [[Multisets|Multiset Operator]].</td>
     </tr>
     </tr>
     <tr>
     <tr>
       <td valign="top"><apll>⎕ID:</apll></td>
       <td valign="top"><apll>⎕PRO:</apll></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td>is called where an identity element is needed as in <apll>foo/R</apll> where <apll>R</apll> is empty.</td>
       <td>is called when a prototype element is needed as in <apll>foo¨R</apll> where <apll>R</apll> is empty, or <apll>L foo¨R</apll> where one of both of <apll>L</apll> or <apll>R</apll> is empty and the other is conformable.</td>
     </tr>
     </tr>
   </table>
   </table>
Line 24: Line 32:
<p>For example,</p>
<p>For example,</p>


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


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕fmt foo/⍬<br />
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕fmt foo/⍬<br />
┌──────────┐<br />
┌──────────────┐<br />
│┌8───────┐│<br />
│┌8───────────┐│<br />
││Identity││<br />
││Identity 2 2││<br />
│└────────┘2<br />
│└────────────┘2<br />
└∊─────────┘<br />
└∊─────────────┘<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo⍦ 1<br />
Multiset 0 2<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 foo⍦ 1<br />
Multiset 2 2<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕fmt 1 foo¨⍬<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕fmt 1 foo¨⍬<br />
┌0──────────┐<br />
┌0──────────────┐<br />
│┌9────────┐│<br />
│┌11───────────┐│<br />
││&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;││<br />
││&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 0││<br />
│└─────────┘2<br />
│└─────────────┘2<br />
└∊──────────┘<br />
└∊──────────────┘<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo/¨0⍴⊂⍬<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo/¨0⍴⊂⍬<br />
NONCE ERROR<br />
NONCE ERROR<br />
Line 48: Line 61:


* <p>In the Identity element case, the function is called with the reduction function's right argument prototype as the right argument to the user-defined function/operator; the left argument is undefined.  For example, in <apll>foo/3 0⍴⊂⍳4</apll>, the (right) argument passed to the function is <apll>0 0 0 0</apll>.  The return value from the function 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 function is called with the reduction function's right argument prototype as the right argument to the user-defined function/operator; the left argument is undefined.  For example, in <apll>foo/3 0⍴⊂⍳4</apll>, the (right) argument passed to the function is <apll>0 0 0 0</apll>.  The return value from the function 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 Multiset case, the user-defined function/operator is called with the same argument(s) as the multiset derived function.</p>


* <p>In the Prototype case, the user-defined function/operator is called with arguments that are the prototypes of the respective arguments; in the monadic case, the left argument is undefined.</p>
* <p>In the Prototype case, the user-defined function/operator is called with arguments that are the prototypes of the respective arguments; in the monadic case, the left argument is undefined.</p>

Revision as of 10:44, 22 April 2014

Normally, execution of a user-defined function/operator starts execution at line one. However, in certain contexts, execution may start at a different line depending upon the context and the presence of a System Label. These special labels start with a quad symbol so as to present no confusion with 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 a user-defined function/operator 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,

    ∇ 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
    ∇

      ⎕fmt foo/⍬
┌──────────────┐
│┌8───────────┐│
││Identity 2 2││
│└────────────┘2
└∊─────────────┘
      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 function is called with the reduction function's right argument prototype as the right argument to the user-defined function/operator; the left argument is undefined. For example, in foo/3 0⍴⊂⍳4, the (right) argument passed to the function is 0 0 0 0. The return value from the function 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 user-defined function/operator is called with the same argument(s) as the multiset derived function.

  • In the Prototype case, the user-defined function/operator 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.