On Fri, Jul 8, 2011 at 2:59 PM, mijj <[email protected]> wrote: > is there a tech reason why i shouldnt be allowed to do this .. > > x ([ =. +) 3
As Brian Schott pointed out, =. is not a verb. However, you can make a verb which performs the same role: serializeNoun=:3 :'5!:5<''y''' localAssign=: ([ ".@, '=.' , ])&serializeNoun Now you can do: 'x' localAssign 3 But the above still does not work, because a variable name is not its value. 'x' ([ localAssign +) 3 |domain error x ([ localAssign +) 3 |domain error The first example fails because you cannot add 'x' and 3. The second example fails because either x's value was a name (which fails for the same reason as before) or x is a number (which cannot be assigned to). You could also have gotten a value error here, if x had never been used before. And =. needs its special parsing rule, so it can get at a variable name before it get replaced by its value. So that is not going to change any time soon. Perhaps you want something like this: modify=:2 :0 (m,'=.',m,' ',5!:5<'v') ".@, serializeNoun@] ) 'x' modify + 3 Note, however, that this does not work for explicit verbs with multi-line definitions in current versions of J. To fix this you would need to replace 5!:5<'v' with something more sophisticated. (Specifically, it would have to look for newlines and do some extra work when they were present.) I've posted code that does this kind of thing, before, but I am not entirely happy with it. I keep thinking there must be better ways of approaching this multi-line explicit definition issue. -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
