Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!ukc!pyrltd!tetrauk!rick From: rick@tetrauk.UUCP (Rick Jones) Newsgroups: comp.lang.eiffel Subject: Re: Functions without side effects (was Old confusion) Message-ID: <1187@tetrauk.UUCP> Date: 12 Jun 91 13:01:26 GMT References: <1991May30.141218.3446@mstr.hgc.edu> <130803@tut.cis.ohio-state.edu> <1991Jun7.135613.1515@mstr.hgc.edu> Reply-To: rick@tetrauk.UUCP (Rick Jones) Organization: Tetra Ltd., Maidenhead, UK Lines: 36 In article kers@hplb.hpl.hp.com (Chris Dollin) writes: > >My vision of Stack is one in which ``every time you need to make a decision >based on the current top'' is a non-issue; you stuff things on the stack, later >you get them back. Why would you want to ``make a decision'' based on the ``top >element''? (All the code I've done with stacks just pops the element when it >wants it. Repeated access to that element - while it's still on the stack - >just doesn't seem to be one of the desired properties. No, this isn't an >artifact of using imperative pop!) > >Perhaps we're talking about two different data-types both called ``Stack''? While your vision of Stack corresponds to one particular implementation, common in hardware, it's in fact quite a specific type of stack. There are many other widely used types of stack where you do get at the top element without popping it. Think of an RPN calculator, for example (something HP are quite fond of, if I recall :-) - the result is a view of the top value of the stack. You don't take it off to look at it - it's still there. Also the memory stack used in most modern CPU's for parameter passing is accessed non-destructively. In practice that's actually a hybrid stack, since any element can be accessed directly. In the most general terms, a stack is just a LIFO buffer. In many applications, your view of a Stack is what you want, but if that is the only way you think of stacks, you'll only use them where that sort of stack is required. Having a more generalised notion of a stack may enable you to use a stack structure effectively in other situations. This is what's difficult but ultimately satisfying about OO - tearing yourself away from implementation and seeing the wider abstraction. And in the end, you get better software. -- Rick Jones, Tetra Ltd. Maidenhead, Berks, UK rick@tetrauk.uucp Chairman, NICE (Non-profit International Consortium for Eiffel) Any fool can provide a solution - the problem is to understand the problem