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?
----- Original Message -----
From: Joe Bogner <[email protected]>
To: [email protected]
Cc:
Sent: Friday, April 25, 2014 9:02:46 PM
Subject: Re: [Jprogramming] J in 5 minutes
On Fri, Apr 25, 2014 at 7:44 PM, Raul Miller <[email protected]> wrote:
> On Fri, Apr 25, 2014 at 5:31 PM, Joe Bogner <[email protected]> wrote:
>
> > So I can generate a string and evaluate it, but is there a better way
> than
> > evaluating the string?
> >
>
> Here are some options:
>
> ". (or do - the advantage of do being that it's a name so you can specify
> which locale to use).
>
>
My goal is to define a list of helper verbs for each column in the table.
I used ". in my last version. It was somewhat cryptic, so here it is again
with more details:
cols=: 'FName';'LName';'Age';'Company'
] vars=:('`',(, > (],&'_eq ') each cols))
`FName_eq LName_eq Age_eq Company_eq
] verbs=:". }. ,> ('`',[) each ('((= ' , ') # ])' ,~ ]) each cols
┌───────────────────────┬───────────────────────┬─────────────────────┬─────────────────────────┐
│┌─┬───────────────────┐│┌─┬───────────────────┐│┌─┬─────────────────┐│┌─┬─────────────────────┐│
││3│┌─────────────┬─┬─┐│││3│┌─────────────┬─┬─┐│││3│┌───────────┬─┬─┐│││3│┌───────────────┬─┬─┐││
││ ││┌─┬─────────┐│#│]││││ ││┌─┬─────────┐│#│]││││ ││┌─┬───────┐│#│]││││
││┌─┬───────────┐│#│]│││
││ │││2│┌─┬─────┐││ │ ││││ │││2│┌─┬─────┐││ │ ││││ │││2│┌─┬───┐││ │ ││││
│││2│┌─┬───────┐││ │ │││
││ │││ ││=│FName│││ │ ││││ │││ ││=│LName│││ │ ││││ │││ ││=│Age│││ │ ││││
│││ ││=│Company│││ │ │││
││ │││ │└─┴─────┘││ │ ││││ │││ │└─┴─────┘││ │ ││││ │││ │└─┴───┘││ │ ││││
│││ │└─┴───────┘││ │ │││
││ ││└─┴─────────┘│ │ ││││ ││└─┴─────────┘│ │ ││││ ││└─┴───────┘│ │ ││││
││└─┴───────────┘│ │ │││
││ │└─────────────┴─┴─┘│││ │└─────────────┴─┴─┘│││ │└───────────┴─┴─┘│││
│└───────────────┴─┴─┘││
│└─┴───────────────────┘│└─┴───────────────────┘│└─┴─────────────────┘│└─┴─────────────────────┘│
└───────────────────────┴───────────────────────┴─────────────────────┴─────────────────────────┘
(I don't know how to paste this better)
(vars)=:verbs
FName_eq
(= FName) # ]
I can now execute statements like this: (<'John') FName_eq (<'Acme')
Company_eq data
This works fine, but I wanted to get input on it vs other other approaches.
More specifically, you used this:
colN=:3 : 0
{.y&{"1`''
)
'`FName LName Age Company'=: colN"0 i.4
I don't quite understand how it works and I was wondering if it's better
than using Do. I don't know how to have a verb return a train of verbs for
a gerund. I may be using the wrong terminology.
[colN"0 i.1
┌─────────────────────────┐
│┌─┬─────────────────────┐│
││"│┌─────────────┬─────┐││
││ ││┌─┬─────────┐│┌─┬─┐│││
││ │││&│┌─────┬─┐│││0│1││││
││ │││ ││┌─┬─┐│{│││└─┴─┘│││
││ │││ │││0│0││ │││ │││
││ │││ ││└─┴─┘│ │││ │││
││ │││ │└─────┴─┘││ │││
││ ││└─┴─────────┘│ │││
││ │└─────────────┴─────┘││
│└─┴─────────────────────┘│
└─────────────────────────┘
I can come reasonable close, but not the final mile. No big deal if Do. is
good enough, since it works
'`FName_eq LName_eq' =: (3 : '=&y` '''' ' ) each 'FName';'LName'
FName_eq
=&'FName'
I would ideally like something like this (I think), assuming this better
than do:
'`FName_eq LName_eq' =:(3 :'(= y) #]` '''' ')each'FName';'LName'
|length error
| (=y) #]`''
But again, I don't really understand what it's doing with the verb
returning a strange form that somewhat appears to be a gerund
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm