Pascal,

Not bad, at all. I have seen eval before I think, but did not understand
its use.

Now I am trying to understand its pieces.

eval =: 1 : ' a: 1 :  m'

Am I correct that the `1 : m` part is an explict adverb and that `a:` is
its argument that is not even used until eval is executed. I am pretty sure
that is right, because I tried to redefine eval as follows, as an
experiment, and got the undesirable, but informative result I show below.
Notice that I replaced a: with eval, and the final result of FName_eq is
wrong, but telling.

   eval =: 1 : ' eval 1 :  m'
   evalassign =: 4 : ('(x) =: y eval';'1')
   cols=: 'FName';'LName';'Age';'Company'

       ( (') # ]',~ '(= ' ,]) evalassign~ '_eq' ,~ ]) each cols
┌─┬─┬─┬─┐
│1│1│1│1│
└─┴─┴─┴─┘
   FName_eq
eval(1 : '(= FName) # ]')


On Fri, Apr 25, 2014 at 10:23 PM, 'Pascal Jasmin' via Programming <
programm...@jsoftware.com> wrote:

> remembering eval
>
> eval =: 1 : ' a: 1 :  m'
> evalassign =: 4 : ('(x) =: y eval';'1')
>
> evalassign turns eval into a verb (so we can use rank or each on it), and
> discards the result (would be a domain error to not return a noun from a
> verb), but in the process assign what y evals to (x).
>
> so:
> cols=: 'FName';'LName';'Age';'Company'
>
>     ( (') # ]',~ '(= ' ,]) evalassign~ '_eq' ,~ ]) each cols
> ┌─┬─┬─┬─┐
> │1│1│1│1│
> └─┴─┴─┴─┘
>    FName_eq
> (= FName) # ]
>
>
> it could be prettier with a templating verb (that substitutes into an x
> argument), but still not bad?
>
>
> --
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to