For Programmers: Free Programming Magazines  


Home > Archive > APL > March 2005 > [J language] Calling a dyad as you would a monad









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [J language] Calling a dyad as you would a monad
Eighty

2005-03-29, 8:55 pm

I want to define a function/verb f(x) that says if x is one of the
chars a, b or c.

Suppose x is the argument. Then I want:

f =: x e. 'abc'

But I can't name the argument explicitly (can I?), so I don't know how
to do this. The problem is that when I call f, the argument goes on the
right side, but I need to put it on the left side.

Is there a flip function so that the left and right arguments of a dyad
are switched (so x dyad y == y (flip dyad) x)?

Is there a bind function so that I can bind the right argument (so x
dyad y == bind dyad y x)?

Philip A. Viton

2005-03-30, 8:57 am

In article <1111676518.020328.249890@g14g2000cwa.googlegroups.com>,
eightyx@gmail.com says...
> I want to define a function/verb f(x) that says if x is one of the
> chars a, b or c.
>
> Suppose x is the argument. Then I want:
>
> f =: x e. 'abc'
>
> But I can't name the argument explicitly (can I?), so I don't know how
> to do this. The problem is that when I call f, the argument goes on the
> right side, but I need to put it on the left side.
>
> Is there a flip function so that the left and right arguments of a dyad
> are switched (so x dyad y == y (flip dyad) x)?
>
> Is there a bind function so that I can bind the right argument (so x
> dyad y == bind dyad y x)?
>
>


The right argument in an explicit verb definition can be referred to as
y. (and the left is x.) So the following may do what you want (sorta
klunky def)

f =: 3 : 0
+./ y. e. 'abc'
)


Note that we take the "or" of the results of e. then f 'abc' is 1 while
f 'def' is 0

flip function: look at dyad ~ If 1 % 2 is 0.5 1 %~ 2 is 2

No sure I understand the "bind" question , but look at &


--


Phil Viton
Ohio State University
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com