Thanks for the pointer,
>From my search, looks like Oleg came up with
and=: ^:
2&>) and (0&<) 1
1
(2&>) and (0&<) 2
0
These do in fact shortcircuit, which he proved.
There's a few things that and function doesnt do:
1. As Oleg pointed out, you can't parenthesize it (or
compose with it)
2. Single parameter for whole chain
3. Not limited to 0 or 1 result. In a way, more true
to lisp, but for J, limiting seems more applicable.
4. as seen below, the behaviour of ^:0 is to return y.
which although theoretically desirable, will be very
difficult to work with results of different shapes
depending on results.
(+/) and (0&<) 0 1
0 1
1 0
(+/) and (0&<) 2 1
3 3
(+/) and (0&<) 1 0 1
2 0 0
1 0 1
2 0 0
(+/) and (0=#) 1 0 2
1 0 2
(+/) and (3=#) 1 0 2
3
AND seems very flexible to me, but it is just one of
many variations on the SIDE verb, which is the really
innovative J idiom I presented. I can anticipate more
uses of SIDE than the built in gerund evoke modes.
Perhaps presenting it with more of the domain-related
functionality stripped out of the main pattern will
make its usefulness/flexibility more apparent to
others.
Pan2=: ('123456789'"_ -: /:~)@":"0 NB. True if arg
pandigital.
(>:`fib9G & SIDE)[EMAIL PROTECTED](Pan2@ (]`fibfirst9) AND
(({:@>@{:);(>@{.)))(^:1000) 2; 1 1x
Things to notice above,
1. SIDE is bonded with its Gerund argument so as to
form a single monad. The Gerund can represent an
arbitrarily complex series of verbs. The generic use
of SIDE that is clumsy to do any other way in J, is
maintaining side effects.
2. Composing on the gerund. Pan2 verb is applied to
all elements of the gerund. very clean. It
transforms the gerund before it is applied to
arguments in the and test.
3. the right side of the AND verb lets you reorder and
transform arguments before applying logical tests.
Its easier to write than read, but its easy to write.
--- John Randall <[EMAIL PROTECTED]>
wrote:
> John Randall wrote:
>
> > For your AND verb, you probably want to use
> prefixes and the power
> > operator.
> >
> > Best wishes,
> >
> > John
> >
>
> Scrub this. Search the J Forum for "shortcutted".
>
> Best,
>
> John
>
>
----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm