f2=: (?@(+/) (1 + <i.1:) +/\)@{
----- Original Message -----
From: Kairit Sirts <[EMAIL PROTECTED]>
Date: Friday, January 18, 2008 11:07
Subject: RE: [Jprogramming] loopless code
To: 'Programming forum' <[email protected]>
> >
> > In fact, I think it would be a fruitful discussion to compare
> and contrast
> > the cases where we use:
> >
> > * "
> > * /
> > * ^:iteration_calculator
> > * ^:condition^:_
> > * $:
> > * for. and while.
> >
> > I say that because I struggled with the third sentence of this
> message. I
> > couldn't quite articulate the type of problem which would
> cause one to use
> > $: instead of ^: .
> >
> > -Dan
>
> I myself am far too incompetent to start this fruitful
> discussion, but
> actually I do have several peaces of code which are implemented
> with for or
> while loops. I don't like them and I'm quite sure there are
> nicer ways to
> write them, but it has been to complicated to me so far.
>
> For example the following peace:
>
> y is a matrix of shape n * n
> x is a number between 0..n-1
>
> roll =. ?+/ row =. x { y
> index =. 0
> while. roll > 0 do.
> roll. =. roll. - index { row
> index =: >: index
> end.
> if. index = 0 do.
> index =. 1
> end.
>
> For the last if-clause I figured out something like this:
>
> check =: =&0^:(=&0)
>
> And 'check index' seems to work as expected, but I'm not quite
> sure if it
> really is working correctly
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm