System Labels

From NARS2000
Revision as of 13:24, 30 August 2009 by WikiSysop (talk | contribs)
Jump to navigationJump to search

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.

⎕PROTOTYPE: is called where a prototype element is needed as in foo¨R where R is empty.
⎕IDENTITY: is called where an identity element is needed as in foo/R where R is empty.


For example,

    ∇ Z←L foo R
[1]   Z←L,R ⋄ →0
[2]   ⎕PROTOTYPE:Z←'Prototype' ⋄ →0
[3]   ⎕IDENTITY:Z←'Identity'
    ∇

      ⎕fmt foo/⍳0
┌──────────┐
│┌8───────┐│
││Identity││
│└────────┘2
└∊─────────┘
      ⎕fmt 1 foo¨⍬
┌0──────────┐
│┌9────────┐│
││Prototype││
│└─────────┘2
└∊──────────┘

In the Identity element case for reduction, the function is called with the reduction function's right argument's 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.

In the Identity element case for inner product, the function is called with the inner product function's left argument's prototype as the left argument and the right argument's prototype as the right argument to the user-defined function/operator. For example, in (3 0⍴⊂⍳4)foo.+0 2⍴⊂⍳2, the left argument passed to the function is 0 0 0 0 and the right argument is 0 0.

In both of the above cases, the ⎕IDENTITY entry point is called only once even though the result may have multiple copies of the identity element.

In the Prototype case, the user-defined function/operator is called with arguments that are the prototypes of the respective arguments.