On Sat, Nov 30, 2002 at 05:37:42AM +0900, Martin DeMello wrote: > 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 :) Ummm, I have also seen this implemented as a queue :-) Access to its elements was unprotected, though (no coin); I believe this kind of access control can only be done straightforwardly with stacks. I hereby propose a pointless competition (like all the good ones! ;) on reports of use of stacks and associated structures IRL. BTW, I believe nobody thought about the following, even though it is one we are all exposed daily to: my desk is a stack, too. Papers and stuff get stacked, and I can easily peek at the topmost element. My desk-stack is able to hold objects of different types, as there's no static type checking. There's however a set of constraints on which types can be stacked over. To reach a deeper understanding of these typing issues, I performed the following experiment on the table to my left (just as I typed these words) 1) push CD 2) push CD -> structure is stable 3) push cardboard box -> type of this object == CardboardBox 4) push set of 50 CDs inside plastic box ==> SURPRISE!!! the type of object (3) has changed to FlattenedCardboardBox 5) push apple 6) push Blue Book (Smalltalk 80, The Language and Its Implementation) ==> an UnstableStack Exception is thrown. Sorry, haven't had any caffeine in two days and I'm too hungry to _think_ right now :-P -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com ...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and the Ugly). -- Matt Welsh