[]NC test

Writing and using Classes in Dyalog APL
Post Reply
User avatar
StefanoLanzavecchia
Posts: 113
Joined: Fri Oct 03, 2008 9:37 am

[]NC test

Post by StefanoLanzavecchia »

Given the following class definition

Code: Select all

:Class a

  :field public shared b

  ∇ test
    :Access public shared
    ⎕←⎕NC'b'
    b
  ∇

:EndClass


guess, before trying it for real, what the execution of

Code: Select all

a.test
will produce. Were you expecting

Code: Select all

0
VALUE ERROR
test[3] b
       ∧

?

Close, but no cigar.

Here's the real thing (notice the "2"):

Code: Select all

a.test
2
VALUE ERROR
test[3] b
       ∧


Why?
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: []NC test

Post by Morten|Dyalog »

A nameclass of 0 means that the name is "free". In this case, "b" is defined as a Field, and is not free for any other use. Therefore, the name has a class of 2 (2.2, to be exact).

For the same reason, a.⎕nl -2 reports that 'b' is in the list of exposed fields and properties, even though it has not yet been assigned a value.
User avatar
StefanoLanzavecchia
Posts: 113
Joined: Fri Oct 03, 2008 9:37 am

Re: []NC test

Post by StefanoLanzavecchia »

Yes... I was afraid you'd reply that... does it mean that it's impossible to use the good ol' 0=[]NC 'varname'? I don't think this is a disaster...
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: []NC test

Post by Morten|Dyalog »

Nope... But then, you really should not have fields with no value in a well-behaved object(!). Set it to ⎕NULL or some other "impossible" value in the class definition and check for that value?
DanB|Dyalog

Re: []NC test

Post by DanB|Dyalog »

Successful []SVO of 'var' will also define 'var' as a variable even tho it has no value.
Post Reply