Kent Dahl <kentda / stud.ntnu.no> wrote:
>> And a plausible use of 'peek' paired with 'shift' rather than 'pop'
>> would be looking at the first argument to a function without shifting
>> that argument out.
> 
> Looking at the first you say? Wouldn't that like, ehm, naturally imply
> 'first' rather than 'peek'? 

Not unless you know that the argument array reads from left to right
(seriously - if I were cargo-cult programming I'd catch on to the fact
that 'shift' kept yielding arguments, but that wouldn't tell me how they
were stored in *args)
 
> I see your point, though. I'd like to see highly cohesive subsets of
> methods inside Array for the various uses, such as stack and queue, such
> as I take it you propose, instead of the power-reducing suggestions of
> having specific Stack/Queue classes which also have been mentioned on
> the list. The aliases should then communicate the intended usage of the
> programmer. With array now, 'push' and 'pop' communicate "I'm using it
> like a stack", but when I suddenly use 'last' it is hard to tell wheter
> I'm using it like a stack or doing some magic trick because I know it is
> implemented like an array.

Yes! That's exactly what I'm after - I know that classic OO theory would
say to implement a Stack class containing an internal array and put up
watertight walls to prevent the client programmer from seeing teh array,
but I think it's much more useful to have the option of breaking the
abstraction if you need to.

> I am vary of putting too much emphasis on geometric directions. They
> won't be of much use when we're all of in spacestations, weightless and
> controlling oh-two recyc machines with Ruby. But my propopal of peek
> planted between the pair of push and pop, may have more to do with my
> abnormal affection for alliteration, alas. :-)

But it breaks the Principle of Perfect Predictability :)
 
>> But don't you put in new cups from the top? Which would make it a queue
>> rather than a stack.
> 
> Depends on the type. The last one I refilled frequently didn't have an
> opening at the top, so you had a stack of cups that was inserted from
> the bottom up. I think you could unscrew the transparent part containing
> the cups to avoid rubbing every cup against the insanely simple
> "dispenser", but it still went like a stack with a "push_many" with the
> bottom as the entrypoint :-)

Okay (: I've seen one that was covered from the top, but you could open
the curved face and put in cups. Supermarket shopping cart rails are
an example of a horizontal stack too - you slide in carts and remove the
last slid-in one. So there're even more options than top and bottom :)

martin