From: Kent Dahl Date: 2002-11-29T18:36:18+09:00 Subject: Re: RCR: Stack, Queue alias methods in Array Martin DeMello wrote: > > Kent Dahl wrote: > > Then you really don't want 'top', you want 'peek', as in "get value pop > > would return, but don't pop it off". > > But 'peek' really is too generic - No more than 'top', and it is less confusing, IMHO. > it could also mean 'get value shift > would return', Could, yes, but is that what it traditionally is used for? I've never seen peek in combination with shift and unshift, but often seen it with push and pop. For shift and unshift, the mental image I use, is items horizontally aligned on a table. Shifting it means moving it to give space at the front for a new element, and unshift means pushing it the other way, making the first element fall off the table. I.e. the 'first' or 'front' element is the one unshift would return. As for stacks, the mental image is naturally vertical. Either bend down and take a peek at the one at the bottom (me doing dishes) or stand on toes to peek at the one at the top (cafeterias doing dishes). 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. > '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 > 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. :-) -- (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 5. year ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)