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

Reply via email to