I wrote:
>  zUr3=: (2$:1 0,~1+]) : ([EMAIL PROTECTED](>:@[$:],1,0$~1={)@.(<:{.))

Arie Groeneveld responded:
>  I want to avoid the `  

A knotty problem.  Let's see if I can untie it:

           NB.  Look ma, no  `  !
           zUr4=: (2$:1 0,~1+]) : ([EMAIL PROTECTED] :. (>:@[$:],1,0$~1={)^:(_1 
^(<:{.)))
        
           zUr4 7
           1 0 1 1 0 1 0 1 1 0 1 1 0
           
           (zUr -: zUr4) 100
        1
           
I know.  Cheap shot.  But you did say:

>  I just want to come up with a wide variation on the subject 

Onward then.  Studying further, I better understand what your verb is doing. 
Another way to avoid the  `  is by keeping ALL your control data in the LHA. 
That is, you can "include the behead" by obviating the need for it:

           zUr5 =: (1 0 $:~ 1 , >:) : (((1 0 + [) $: ] , 1 , 0 #~ 1= ({~
{.)~)^:(</@[))

           zUr5 7
        1 0 1 1 0 1 0 1 1 0 1 1 0
        
           (zUr -: zUr4) 100
        1

But that's still not what you _really_ want:
>  is there a way to do this  iteration by not dragging 
>  along the iterator.

The previous verbs are recursive; if you want an interative formulation, you
need to drop the  $:  .  That is, the "purely iterative" format would use
only  ^:  .

If we could somehow calculate the current index from the argument, it would
permit the form:

           (, 1 , 0 #~ 1 = ({~ calcIdx))^:n   

which is much cleaner.

At first glance the verb  calcIdx   is unobtainable, as the stepwise index
is lost; the argument grows as a function of its previous states (i.e. it is
a recurrence relation), so we cannot use the length of the argument.  But
then, it occured to me that one and only one  1  , is added at every step. 
So the definition of  calcIdx  is simply  +/  .  Therefore we obtain:

           zUr6 =: $:&1 0 : ((, 1 , 0 #~ 1 = ({~ +/))@:]^:[)
        
           zur6 7
        1 0 1 1 0 1 0 1 1 0 1 1 0
           
           (zUr -: zUr6) 100
        1

Now, I personally find forms like  u@:]^:[  unappealing.  Usually I try to
convert them into the equivalent  x u&n y   form.  This is especially true
when I also see a bound argument.  In this case, the argument isn't bound,
but it is defaulted.  And losing the monad would also clean up the
parenthesis mess a bit.  But I leave the reforumlation as an exercise for
the reader.

I hope this helped.

G-Dan
-- 
View this message in context: 
http://www.nabble.com/How-to-behead-included--tf4778131s24193.html#a13672072
Sent from the J Programming mailing list archive at Nabble.com.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to