Ian Clark wrote:
> Another thing I'd really like in J (and rookies shouldn't be allowed
> to ask such things) is something like the C++ "const". A way of
> locking down the name of a quantity so that it can't be changed during
> "the run", whatever that is -- at least not without raising an error.
I replied:
> Search for "Single Assignment J" or "SAJ" in the Wiki.
I should've been more helpful than this; the specific link you want is:
http://www.jsoftware.com/jwiki/DanBron/Temp/SingleAssignmentJ
The example it gives is:
name NB. Undefined
|value error: name
name is 'value'
value
name NB. Defined once
value
name =: 'new value' NB. Can't be redefined
|read-only data
| name =:'new value'
Of course, if you want, you can give this another alias, for example
isConstant . Then you could write:
replyYES isConstant 1
and if you tried:
if. replyYES=:y do. ...
you'd get
|read-only data
| replyYES=:y
at run-time.
-Dan
PS: Unfortunately, for your use, the SAJ script takes specific pains to
allow the programmer to shadow a global name with a local name (as usual),
even if that global name is SAJed (constant). So if you tried
if. replyYES=.y do. ... NB. Note =. not =:
J would happily execute it. You could get around this by locally SAJing the
name replyYES wherever you need it (i.e. replyYES isL replyYES). Or, of
course, you could fiddle the SAJ script.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm