On Tuesday 23 October 2007 07:44 am, Robert Klemme wrote:
> 2007/10/23, Randy Kramer <rhkramer / gmail.com>:
> > On Tuesday 23 October 2007 12:46 am, Konrad Meyer wrote:
> > > Push and pop have been around as instructions since the days of asm. The
> > > common "visualisation" is to imagine a dinner-plate-stack-holder at a
> > buffet.
> > > You push plates down into the spring-loaded stack to add more. When you 
want
> > > to remove a plate, you pop it out of the top of the stack. That's 
probably
> > > not the best description of the idea, but you can always google for
> > push/pop.
> >
> > I always liked that visualization.  The problem for me (and I'm not the 
OP) is
> > that in Ruby you have to lift all the plates off, put the new plate on the
> > bottom, and then put all the plates back.  (Likewise when you want to 
"pop"
> > that plate.)  ;-)  (Because Ruby uses push and pop on the end of the array
> > instead of the beginning.)
> 
> I'm not sure what exactly you mean.  #push and #pop just work as one
> would expect from a LIFO.

Well, it was partly an attempt at humor, and partly the result of some strange 
coding I did recently in a program to convert files in what I call askRhk03 
format to askRhk04 format.  

In doing that, I had the need (or it seemed convenient) to both push and pop 
things on to the array, but then also access all the items in the array in 
order.  (I.e., using something like array.each { } 

But, the first time I attempted it, without noticing that a push occurred on 
the end of the array instead of the beginning, I got the wrong results.  (No 
big deal, I just used array.reverse first.)

Randy Kramer
 
> > It's not a major problem, but it did surprise me the first time I ran into 
it,
> > and I suppose this approach is a little easier to implement.
> >
> > (And, if push and pop were built on a separate "stack" data structure 
(instead
> > of being built on the array structure (with various other paradigms, like
> > being able to access any item in the array via the index), this point 
would
> > not come up.)
> 
> Frankly, I don't understand your point.  You can use an Array as LIFO
> just the same.  There is no additional lifting etc. involved.  And for
> this it's completely irrelevant whether they use lowest or highest
> index for their operation.




> 
> Kind regards
> 
> robert
> 
>