Raul, thank you for the detailed explanation and alternate code. I was using this as an opportunity to learn gerunds. As a bonus, from your reply I was able to learn more about custom adverbs and conjunctions.
I agree that the adverb approach makes more sense then a verb for every column and operator. I can envision wanting to do > and < and other operations, which would make sense as adverb just eq. I was also glad to find out that I could mimic what Martin had in his videos too with FName_eq This works well: (<'John') FName eq (<'Acme') Company eq data(<'John') FName eq (<'Acme') Company eq data In terms of sel, I had to modify yours slightly to make it work: I'm including it here for completeness NB. Raul's first version sel2=:2 :0 (v u) # ] ) ('`',;:inv cols,L:0 '_eq2')=: 3 :'{. = sel2 (y`:6)`'''''"0 cols (<'John') FName_eq2 data |length error: FName | (<'John') FName_eq2 data NB. Pascal's version sel3=:2 : '(u v ]) # ]' ('`',;:inv cols,L:0 '_eq3')=: 3 :'{. = sel3 (y`:6)`'''''"0 cols (<'John') FName_eq3 data |length error: FName_eq3 | (<'John') FName_eq3 data NB. Raul's second version sel=:2 :0 v@u # ] ) ('`',;:inv cols,L:0 '_eq')=: 3 :'{. = sel (y`:6)`'''''"0 cols (<'John') FName_eq data |length error: FName_eq | (<'John') FName_eq data NB. Joe's final version sel4=:2 :0 (u v) # ] ) ('`',;:inv cols,L:0 '_eq4')=: 3 :'{. = sel4 (y`:6)`'''''"0 cols (<'John') FName_eq4 data +----+-----+--+----+ |John|Smith|31|Acme| +----+-----+--+----+ It's easy to see the differences: FName_eq NB. v@u # ] FName@= # ] FName_eq2 NB. (v u) # ] (FName =) # ] FName_eq3 NB. (u v ]) # ] (= FName ]) # ] FName_eq4 NB. (u v) # ] --> correct (= FName) # ] Where FName_eq4 is the only one I could get to work. Pascal -- regarding the eval and evalassign. Neat tricks. I will keep that at hand too I feel much more comfortable with gerunds, adverbs and conjunctions... Thanks! On Fri, Apr 25, 2014 at 11:57 PM, Raul Miller <rauldmil...@gmail.com> wrote: > That won't work. > > Actually, my code had a bug in it also, for what I think is the intended > use pattern. It's also the case (u v ]) # ] is not equivalent to (v u) # ] > but since (v u) # ] does not do the right job, let's skip on to what I > think I should have defined: > > sel=:2 :0 > v@u # ] > ) > > Here's a test case: > > prime=: = ]&.(p:inv) > > prime 2 3 4 > > 1 1 0 > > penultimate=: _2&{"1 > > prime sel penultimate i. 5 5 > > 0 1 2 3 4 > > 10 11 12 13 14 > > 20 21 22 23 24 > > > (This example gets the rows of i.5 5 where the value in the second to last > column is prime.) > > > Thanks, > > > -- > > Raul > > > > > > On Fri, Apr 25, 2014 at 11:43 PM, 'Pascal Jasmin' via Programming < > programm...@jsoftware.com> wrote: > > > good post, Raul thank you. > > > > I just want to rant on a pet peave about hooks. > > > > sel=:2 :0 > > (v u) # ] > > ) > > > > is better defined as: > > > > sel=:2 : '(u v ]) # ]' > > > > for one, its needed to allow u to be a noun. > > > > The point relating to my pet peave about hooks, is that it also allows u > > to be dyadic. Not that I have a great use case for it, in this example. > > > > 1 2: sel < i.5 > > 3 4 > > > > > > ----- Original Message ----- > > From: Raul Miller <rauldmil...@gmail.com> > > To: Programming forum <programm...@jsoftware.com> > > Cc: > > Sent: Friday, April 25, 2014 9:35:02 PM > > Subject: Re: [Jprogramming] J in 5 minutes > > > > Ah, I see... > > > > I'd like to draw your attention to something in my code here: > > > > colN=:3 : 0 > > {.y&{"1`'' > > ) > > '`FName LName Age Company'=: colN"0 i.4 > > > > Notice that the expression on the far right is: colN"0 i. 4 > > > > That ("0) means that colN is running independently for each value in i.4 > > > > Also, I already knew what my column names were, so I did not bother > > abstracting them. > > > > Now it looks like you want to have the name list as an argument and build > > up operations based on those names. Personally, I tend to shy away from > > abstractions unless I feel they will help (J gives a lot of abstraction > > already). Still, let's look at some alternatives for the way you > currently > > have things expressed: > > > > cols=: 'FName';'LName';'Age';'Company' > > vars=:('`',(, > (],&'_eq ') each cols)) > > verbs=:". }. ,> ('`',[) each ('((= ' , ') # ])' ,~ ]) each cols > > > > Here's how I might express those two first two lines: > > cols=: ;:'FName LName Age Company' > > vars=: '`',;:inv cols,L:0 '_eq' > > > > But verbs is a bit different. I'd be tempted to not bother with names of > > the form FName_eq and instead use an adverb: > > eq=:1 :0 > > (= u) # ] > > ) > > > > Then, instead of FName_eq, I would use FName eq > > > > Or, (contradicting my earlier statement about avoiding abstraction - but > > what I really meant was that I like simple, direct abstractions, but > mostly > > it's hard for me to describe "how I think" in a meaningful fashion): > > > > sel=:2 :0 > > (v u) # ] > > ) > > > > Now, instead of FName_eq or FName eq, I would use = sel FName > > > > But let's say that I wanted to define those verbs. First, notice > something: > > > > cols-:FName`LName`Age`Company > > 1 > > > > A boxed list of names of verbs is equivalent to a gerund listing those > > verbs by name. And that relates back to what colN was doing (forming a > > gerund length one and taking the first and only box from that list). I > can > > perform a similar trick here: > > > > ('`',;:inv cols,L:0 '_eq')=: 3 :'{. = sel (y`:6)`'''''"0 cols > > > > Does this make sense? > > > > Thanks, > > > > -- > > Raul > > > > > > > > On Fri, Apr 25, 2014 at 9:02 PM, Joe Bogner <joebog...@gmail.com> wrote: > > > > > On Fri, Apr 25, 2014 at 7:44 PM, Raul Miller <rauldmil...@gmail.com> > > > wrote: > > > > > > > On Fri, Apr 25, 2014 at 5:31 PM, Joe Bogner <joebog...@gmail.com> > > 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 > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm