Page 1 of 1

[]NC test

Posted: Wed Mar 03, 2010 2:25 pm
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?

Re: []NC test

Posted: Wed Mar 03, 2010 3:03 pm
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.

Re: []NC test

Posted: Wed Mar 03, 2010 3:11 pm
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...

Re: []NC test

Posted: Wed Mar 03, 2010 3:20 pm
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?

Re: []NC test

Posted: Wed Mar 03, 2010 6:03 pm
by DanB|Dyalog
Successful []SVO of 'var' will also define 'var' as a variable even tho it has no value.