An improvement to evalassign, is to return the assigned name instead of 1

evalassign =: 4 : ('(x) =: y eval';'x')

   ( (') # ]',~ '(= ' ,]) evalassign~ '_eq' ,~ ]) each cols 
┌────────┬────────┬──────┬──────────┐ 
│FName_eq│LName_eq│Age_eq│Company_eq│ 
└────────┴────────┴──────┴──────────┘ 

Its an improvement because some other verb on the same line could use those 
results.

This also made be realize an interesting strategy for verbs that create non 
nouns, and would prefer to return these somehow:  assign the results in some 
locale, likely with the help of an autoincrementing counter to ensure unique 
names, and then return the names... Call it semi-anonymous.


----- Original Message -----
From: Brian Schott <schott.br...@gmail.com>
To: Programming forum <programm...@jsoftware.com>
Cc: 
Sent: Saturday, April 26, 2014 10:53:33 AM
Subject: Re: [Jprogramming] J in 5 minutes

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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to