System Function NC

From NARS2000
Jump to: navigation, search

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 character string Matrix   - to enumerate name classes for.
Z (returned) is a scalar or vector of name class results - e.g. a scalar or vector of integers.


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:
Z will contain:
1 = line label (if ⎕NC called from WITHIN a user function)
2 = variable (global variable name class, or if ⎕NC used IN a user function then local variable names class)
3 = function (for function name(s))
4 = operator
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.
See also: Quad Name List ⎕NL

System Variables (A value may be assigned to these except for ⎕DM)
ALX CT DM DQ DT ELX FC FEATURE FPC IC
IO 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 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 are case insensitive