System Function NC

From NARS2000
Revision as of 19:06, 9 March 2019 by WikiSysop (talk | contribs)
Jump to navigationJump to 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 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.
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