Martin Pelletier <[EMAIL PROTECTED]> wrote:
> I'm trying to use agenda dyadically to apply monadic verbs. I will admit
> this may not be the best solution to my problem. The concept behind this
> would be equivalent in C to looping through each value of "val" and to
> apply whichever "operator" at the same index with a select.
>
> Suppose I have the following verbs, which would be to be used monadically:
>
> v1 =: +:
> v2 =: *:
>
> NB. x is a string which identifies which operation to pick, either
> double or square
> operator =: 'dddssds'
>
> val =: i. #operator
>
> operator v1`v2 @. ('ds'& i. @:["0) val
>
> This is the clumsy and erroneous "thing" I can come up with. I can't
> progress further...
>
> If there is something simpler, better, and/or susceptible to be faster,
> I will gladly take suggestions.
Pretty much what you wrote, except monad f is turned into [EMAIL PROTECTED]
which makes it
dyad-safe (i.e. an ambivalent verb that ignores the optional left parameter)
'dddssds' ((+:@])`(*:@])@.('ds'i.[)"0) i.7
0 2 4 9 16 10 36
or, totally tacit:
((+:@])`(*:@])@.('ds'i.[)"0 [EMAIL PROTECTED]) 'dddssds'
0 2 4 9 16 10 36
In J 5 you used to be able to say +:`*:@] (applying @ to each item in the
gerund)
but this undocumented feature has been removed in the latest version.
-- Mark D. Niemiec <[EMAIL PROTECTED]>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm