On Mon, Apr 27, 2009 at 2:41 PM, I wrote: > trap=: (1 :0) > 'a b c d'=. m > s=. % _1 1 * _2 -/\ m > z=. - 0 3 { m > [: <./ 1 <. 0 >. s * z +/ ] > ) > > 2 6 8 10 trap i. 11 > 0 0 0 0.25 0.5 0.75 1 1 1 0.5 0
That was actually the wrong version. But, I have decided I like my first line there -- it forces an error when its left argument can not be treated as a sequence of four. However, the last line has a minor inefficiency and I should have said: trap=: 1 : 0 'a b c d'=. m s=. % _1 1 * _2 -/\ m z=. - 0 3 { m 1 <. 0 >. [: <./ s * z +/ ] ) However, if that first line annoys you too much, an equivalent form would be: trap=: 1 : 0 s=. % _2 -/\ m * _1 _1 1 1 z=. - 0 3 { m 1 <. 0 >. [: <./ s * z +/ ] ) Finally, note that these implementation of trap support treatment of multiple "trapezoids" at the same time: (2 6 8 10,. 3 5 7 9) trapa i. 11 0 0 0 0.25 0.5 0.75 1 1 1 0.5 0 0 0 0 0 0.5 1 1 1 0.5 0 0 FYI, -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm