Using a flag on a name or value is an interesting point. Another such area where J has limitation is automatic destruction of Objects (Object-Oriented locales). I believe there is already a mechanism in J nouns to keep track to references and be released from memory when no longer referenced. This not for names, but values.
This could be used with objects: a flag that designates that this locale is a result of "create object". Two uses: * a particular value is known to be an object, not just a boxed string * when the last reference is released, a custom destructor is called automatically, by default release_locnum_'' if exists This would allow to call destructors automatically when an object goes out of scope. It also provides the object identity that needs to be passed around, and automatically maintains references. Note 1: "release" is proposed instead of "destroy" to maintain backward compatibility: old objects without "release" will behave the same and will require "destroy" to be called. Note 2: objects locale reference can be combined into a list to form a collection or other structures. So this need to be watched to maintain the flag and reference count. (So it should probably be the string inside the box and not the box itself.) ----- Original Message ---- > From: Dan Bron <[EMAIL PROTECTED]> > To: General forum <[email protected]> > Sent: Thursday, November 20, 2008 1:41:16 PM > Subject: Re: [Jgeneral] copulas: update vs. declare > > > This implies that this mechanism is limited to the kinds of things that > > can be represented using mapped files. > > The statement is true, but not for the reasons you imply (or that I infer > you imply). > > The read-only mechanism works by setting a flag in the name's header. All > J headers share the same format [1]. Therefore any J name of any class > can theoretically be marked as read-only (i.e. not just mapped nouns, nor > just nouns). > > For an example, here's an excerpt from a J601 session: > > plus=:+ > 15!:6{.;:'plus' > 22098584 > > require 'jmf' > 1 readonly_jmf_ 'plus' > > plus =: - > |read-only data > | plus =:- > > Note that this has nothing to do with mapped files; readonly_jmf_ is just > a utility to set that flag in a name's header. This works by getting a > refernce to the name (using 15!:6 ), reading in the flags field of the > underlying structure, changing the readonly flag, and writing the field > back. > > You'll notice two things: one, I said "theoretically"; two, the excerpt > from is J601. That's because J602 introduced a frustrating change. It is > no longer possible to get a reference to a non-noun name using 15!:6 . > Concretely, the difference is: > > 9!:14 '' NB. J601 > j601/2006-11-17/17:05 > > aNoun =: 'noun' > aVerb =: +/ % # > > 15!:6 <'aNoun' > 22098656 > > 15!:6 <'aVerb' > 22098632 > > versus: > > 9!:14 '' NB. J602 > j602/2008-03-03/16:45 > > aNoun =: 'noun' > aVerb =: +/ % # > > 15!:6 <'aNoun' > 26038640 > > 15!:6 <'aVerb' > |domain error > | 15!:6<'aVerb' > |[-7] > > > Though J602 is fairly new, this change has already thwarted me on several > occasions, and I wish it would be rolled back. What was its rationale? > > -Dan > > [1] http://www.jsoftware.com/jwiki/Essays/Incunabulum > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
