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

Reply via email to