From: Martin DeMello Date: 2002-11-29T21:16:35+09:00 Subject: Re: RCR: Stack, Queue alias methods in Array Kent Dahl wrote: > Martin DeMello wrote: > > If you're still not convinced, there's a little something that stuck to > my mind all day: > > Push, pop and peek, > on their own were rather meek. > But their combined whack, > made quite a stack, > with an interface that sounds quite sleek. There is really no reason to stop With defining a 'push' and a 'pop' But a function called 'peek' Isn't all that unique I would much rather see it called 'top' 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. >> 'expose the internal data structure' >> and probably a >> couple of other things (remember BASIC's 'peek'?) > > Yes, I remember. But how many come to Ruby from a Basic that uses peek > these days? :-P Can you even *get* a Basic that uses peek these days? I think C is the last bastion of pointer arithmetic :) >> Cafeterias, for example, use push-down stacks of plates. The plates sit >> in a vertical cage, with a spring at the bottom, so that the top plate >> is always at the same height. You literally push in a plate - the others >> get pushed downwards and teh spring compresses, and likewise you can >> only remove the top plate. > > Can't argue with that. Or can I? A more frequented stack-like structure > encountered IRL by programmers, I would assume to be the coffee machine > and (somewhat) the water cooler. Usually, in my experience, they have a > stack of cups where you remove at the bottom, from a cylindrical plastic > encasing, to avoid the cup being full of dust. :-) But don't you put in new cups from the top? Which would make it a queue rather than a stack. martin