You might be interested in
http://rosettacode.org/wiki/Short-circuit_evaluation#J

-- 
Raul


On Tue, Nov 5, 2013 at 10:19 AM, Joe Bogner <[email protected]> wrote:

> Thanks Kip - I thought of using i. but I think the list would need to
> be lazily evaluated to meet the 2nd part of the criteria of what I'm
> looking for.
>
> i. can be used to find the first match
>
> ops=:(1 = #) , (2 = #) , (10 >:~ +/) , 100 >:~ +/
>
>    (c1 ` c2 ` c3 `c4 `c0) @. ((ops (1 2 300)) i. 1) ''
> sum >= than 10
>    (c1 ` c2 ` c3 `c4 `c0) @. ((ops ('')) i. 1) ''
> default
>
> I assume ops is evaluated prior to matching. The concern is if the
> logic checks have any side effects or are slow, then each one is
> evaluated instead of stopping at the first one. Of course there are
> ways to code the logic checks differently. In a traditional case
> statement (for example a SQL case statement generally provides
> deterministic short circuit evaluation), it would stop at the first
> match
>
> On Tue, Nov 5, 2013 at 9:51 AM, km <[email protected]> wrote:
> > See the documentation for Index Of i.
> >
> > http://www.jsoftware.com/docs/help701/dictionary/didot.htm
> >
> >    1 2 3 4 i. 3 _3  NB. 1 2 3 4 index of 3 is 2; _3 not found
> > 2 4
> >
> > --Kip Murray
> >
> > Sent from my iPad
> >
> >> On Nov 5, 2013, at 8:18 AM, Joe Bogner <[email protected]> wrote:
> >>
> >> I'm experimenting with Agenda and building a verb to return the index.
> >>
> >> My case verb generally does what I'd like, but I was stumped on how to
> >> rework it so that it stops on the first match to work more like a
> >> traditional case statement.
> >>
> >> If the conditions were mutually exclusive then I could use a + between
> >> them - each would still process though. Since they aren't, I opted for
> >> the largest of the matching index. Is there a clean way to say the
> >> first non-zero or zero if no others match? What would be the idomatic
> >> way to handle it?
> >>
> >> Also, ideally it wouldn't process the next statement if it finds a
> match.
> >>
> >> c0=:smoutput bind 'default'
> >> c1=:smoutput bind 'only one'
> >> c2=:smoutput bind 'two'
> >> c3=:smoutput bind 'sum >= than 10'
> >> c4=:smoutput bind 'sum >= than 100'
> >> case=:(1*(1 = #)) >. (2*(2 = #)) >. (3*(10 >:~ +/)) >. (4*(100 >:~ +/))
> >> dispatch=:(c0 ` c1 ` c2 ` c3 `c4) @. case
> >>
> >>   dispatch 1
> >> only one
> >>
> >>   dispatch 2
> >> only one
> >>
> >>   dispatch 1 2
> >> two
> >>
> >>   dispatch 2 8
> >> sum >= than 10
> >>
> >>   dispatch 2 3 5
> >> sum >= than 10
> >>
> >>   dispatch 2 3 5 100
> >> sum >= than 100
> >> ----------------------------------------------------------------------
> >> 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