System Function NC: Difference between revisions

From NARS2000
Jump to navigationJump to search
m minor wording
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
{{BoxStart|<apll>Z←⎕NC R</apll>
{{BoxStart|<apll>Z←⎕NC R</apll>
|⎕Name Classification. &nbsp; &nbsp; Argument <apll>R</apll> should be a '''string, vector or matrix''' of workspace names to show names classes for.}}
|⎕Name Classification. &nbsp; &nbsp; Argument <apll>R</apll> should be a '''string, vector or matrix''' of workspace names to show names classes for.}}
{{BoxLine|<apll>R</apll> is &nbsp; a '''character Scalar, Vector or character string Matrix''' &nbsp; - to <u>''enumerate'' name classes for</u>.}}
{{BoxLine|<apll>R</apll> is a character Scalar, Vector or Matrix of Names}}
{{BoxEnd|<apll>Z</apll> (returned) is a scalar or vector of name class results - e.g. a scalar or vector of integers.}}
{{BoxEnd|<apll>Z</apll> is a integer scalar or vector of name classes}}
<br>
 
System function ⎕NC takes as its right argument a character string specifying a name, vector of names, or character matrix of names. It returns a numeric result which is the classification of each name:<br>
System function ⎕NC takes as its right argument a character string specifying a name, vector of names, or character matrix of names. It returns a numeric result which is the classification of each name.  If called from within a user-defined function/operator/hyperator, ⎕NC returns the name class of the most local instance of the name:
<u>'''Z''' will contain:</u><br>
{| class="wikitable"
'''1 = line label''' (if ⎕NC called from WITHIN a user function)<br>
|-
'''2 = variable''' (global variable name class, or if ⎕NC used IN a user function then local variable names class)<br>
|&nbsp;1|| &nbsp;&nbsp; User line label
'''3 = function''' (for function name(s))<br>
|-
'''4 = operator'''<br>
|&nbsp;2|| &nbsp;&nbsp; User variable
'''0 = name not in use'''<br>
|-
'''¯1 = invalid name'''<br>
|&nbsp;3|| &nbsp;&nbsp; User-defined function
|-
|&nbsp;4|| &nbsp;&nbsp; User-defined operator
|-
|&nbsp;5|| &nbsp;&nbsp; System variable
|-
|&nbsp;6|| &nbsp;&nbsp; System function
|-
|7-20|| &nbsp;&nbsp; <i>Unused</i>
|-
|21 || &nbsp;&nbsp; System label
|-
|22 || &nbsp;&nbsp; <i>Unused</i>
|-
|23 || &nbsp;&nbsp; Magic function
|-
|24 || &nbsp;&nbsp; Magic operator
|-
|25 || &nbsp;&nbsp; Magic hyperator
|-
|26 || &nbsp;&nbsp; User-defined hyperator
|-
|&nbsp;0 || &nbsp;&nbsp; Name not in use
|-
|¯1 || &nbsp;&nbsp; Invalid name
|}


<p>Examples, working with '''⎕NC:'''</p>
<p>Examples, working with '''⎕NC:'''</p>
Line 19: Line 44:
       )VARS        ⍝Show which global variables exists in the current NARS APL workspace
       )VARS        ⍝Show which global variables exists in the current NARS APL workspace
A B C              ⍝3 global variables names exist - A, B and C
A B C              ⍝3 global variables names exist - A, B and C
       ⎕NC 3 2⍴'A B C '    ⍝Same use of ⎕NC with a MATRIX right argument
       ⎕NC 3 2⍴'A B C '    ⍝Sample use of ⎕NC with a MATRIX right argument(3 names 'A ', 'B ' and 'C ' to enumerate/check)
2 2 2                    ⍝ 2 = global variable
2 2 2                    ⍝ 2 = global variable <--> all 3 names WERE FOUND.
       ⎕NC 3 1⍴'ABC'      ⍝Matrix right argument, compare to first call to ⎕NC, just above - {3 2⍴} vs {3 1⍴}
       ⎕NC 3 1⍴'ABC'      ⍝Matrix right argument, compare to first call to ⎕NC, just above - {3 2⍴} vs {3 1⍴}
2 2 2                    ⍝Same correct results(2 2 2) = global variable names class
2 2 2                    ⍝Same correct results(2 2 2) = global variable names class
Line 30: Line 55:
¯1 ¯1 2 0      ⍝Names '⍳ ' and '⍴' are NOT validly constructed(¯1); Variable A IS Found(2), ZZ is validly constructed but Not Found(0).
¯1 ¯1 2 0      ⍝Names '⍳ ' and '⍴' are NOT validly constructed(¯1); Variable A IS Found(2), ZZ is validly constructed but Not Found(0).
</pre>
</pre>
<font color=green><strong>
⎕NC can be used to determine the presence(=2) or absence(=0) of an optional braced argument e.g. {L arg} FuncName R &nbsp; &nbsp; argument in a user function call through ⎕NC usage WITHIN the user function itself, e.g. ⎕NC 'ArgName' !</strong></font>  Ref. [[User-Defined_Functions/Operators/Hyperators|User Defined Functions/Operators/Hyperators.]]
<br>
<br>
See also: [[System_Function_NL|Quad Name List ⎕NL]]
See also: [[System_Function_NL|Quad Name List ⎕NL]]


{{System Variables}}
{{System Variables}}

Latest revision as of 19:47, 9 March 2019

Name Classification - ⎕NC (System Function) - available in monadic form only:

Monadic Function

Z←⎕NC R ⎕Name Classification.     Argument R should be a string, vector or matrix of workspace names to show names classes for.
R is a character Scalar, Vector or Matrix of Names
Z is a integer scalar or vector of name classes

System function ⎕NC takes as its right argument a character string specifying a name, vector of names, or character matrix of names. It returns a numeric result which is the classification of each name. If called from within a user-defined function/operator/hyperator, ⎕NC returns the name class of the most local instance of the name:

 1    User line label
 2    User variable
 3    User-defined function
 4    User-defined operator
 5    System variable
 6    System function
7-20    Unused
21    System label
22    Unused
23    Magic function
24    Magic operator
25    Magic hyperator
26    User-defined hyperator
 0    Name not in use
¯1    Invalid name

Examples, working with ⎕NC:

      )VARS        ⍝Show which global variables exists in the current NARS APL workspace
A B C              ⍝3 global variables names exist - A, B and C
      ⎕NC 3 2⍴'A B C '    ⍝Sample use of ⎕NC with a MATRIX right argument(3 names 'A ', 'B ' and 'C ' to enumerate/check)
2 2 2                     ⍝ 2 = global variable <--> all 3 names WERE FOUND.
      ⎕NC 3 1⍴'ABC'       ⍝Matrix right argument, compare to first call to ⎕NC, just above - {3 2⍴} vs {3 1⍴}
2 2 2                     ⍝Same correct results(2 2 2) = global variable names class
      ⎕NC ⊃'A ' 'B' 'B'  ⍝Call with a disclosed Nested Vector - note the extra space after variable named 'A' >> 'A '
2 2 2
      ⎕NC ⊃'A' 'B' 'C'   ⍝This call FAILS(returns 0=name not in use) because APL sees ⎕NC 'ABC'; there is NO variable named 'ABC'.
0                        ⍝ Name 'ABC' NOT FOUND
      ⎕NC ⊃'⍳ ' '⍴' 'A' 'ZZ'
¯1 ¯1 2 0      ⍝Names '⍳ ' and '⍴' are NOT validly constructed(¯1); Variable A IS Found(2), ZZ is validly constructed but Not Found(0).

⎕NC can be used to determine the presence(=2) or absence(=0) of an optional braced argument e.g. {L arg} FuncName R     argument in a user function call through ⎕NC usage WITHIN the user function itself, e.g. ⎕NC 'ArgName' ! Ref. User Defined Functions/Operators/Hyperators.
See also: Quad Name List ⎕NL

System Variables (A value may be assigned to these except for ⎕DM)
⎕ALX ⎕CT ⎕DM ⎕DT ⎕ELX ⎕FC ⎕FEATURE ⎕FPC ⎕IC ⎕IO
⎕LR ⎕LX ⎕PP ⎕PR ⎕PW ⎕RL ⎕SA ⎕WSID
Niladic System Functions (a value cannot be assigned to these)
⎕A ⎕AV ⎕EM ⎕ET ⎕LC ⎕NNAMES ⎕NNUMS ⎕SI ⎕SYSID ⎕SYSVER
⎕T ⎕TC ⎕TCBEL ⎕TCBS ⎕TCESC ⎕TCFF ⎕TCHT ⎕TCLF ⎕TCNL ⎕TCNUL
⎕TS ⎕WA
Monadic or dyadic system functions (a value cannot be assigned to these)
⎕AT ⎕CR ⎕DC ⎕DFT ⎕DL ⎕DR ⎕EA ⎕EC ⎕ERROR ⎕ES
⎕EX ⎕FMT ⎕FX ⎕MF ⎕NAPPEND ⎕NC ⎕NCREATE ⎕NERASE ⎕NINFO ⎕NL
⎕NLOCK ⎕NREAD ⎕NRENAME ⎕NREPLACE ⎕NRESIZE ⎕NSIZE ⎕NTIE ⎕NUNTIE ⎕STOP ⎕TF
⎕TRACE ⎕UCS ⎕VR
Note that quad functions and variables (except for the ⎕A family of functions) are case insensitive