It could work from the front, but you get extra benefits
from working from the end. The explanation lies in the
way a J array is stored:
header, ravelled atoms, extra space
header is a bunch of stuff such as type, # of atoms
(*/shape for non-sparse arrays), rank, shape,
pointer to ravelled atoms. (The "stuff" is not
necessarily in that order.)
The amount of extra space is relative to the # of atoms,
so that the special code for name=:name,item makes O(1)
the average cost of each operation.
Obviously, if you drop stuff off the front, that too can
be an O(1) operation. However, you can prepend stuff only
to the extent that you'd previously dropped off the front.
Isn't dyadic curtail just k}.y where k is negative?
Perhaps you mean something else?
What exactly is "swap"? Is it name=: (<i,j) C. name ?
----- Original Message -----
From: greg heil <[EMAIL PROTECTED]>
Date: Wednesday, July 12, 2006 11:43 am
Subject: Re: [Jprogramming] special coding for stack operations
> Roger wrote:
>
> > would be used repeatedly.
>
> In a way it is unfortunate that the special coding works at the end
> rather than the beggining of a list... Eg Behead has a dyadic form
> Drop }. but Curtail does not ... are there some better (future) plans
> for a dyadic curtail or any reason that the obvious multiple
> curtailment should not be implemented, also with special coding?
>
> i am using a stack in a simulation system and efficient backtracking
> with the likes of
>
> stack=: stack,x
> ...
> back=: back, {: stack
> stack=: }: stack
>
> would be welcome, multiple item popping even more so. Other Forth like
> stack ops also welcome, eg swap:-)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm