Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!yale!cmcl2!uupsi!mstr!mstr!jcm From: jcm@mstr.hgc.edu (James McKim) Newsgroups: comp.lang.eiffel Subject: Re: Functions without side effects (was Old confusion) Message-ID: <1991Jun10.204452.2717@mstr.hgc.edu> Date: 10 Jun 91 20:44:52 GMT References: <1991May30.141218.3446@mstr.hgc.edu> Sender: Usenet@mstr.hgc.edu (Action News Central) Reply-To: jcm@mstr.hgc.edu (James McKim) Organization: The Hartford Graduate Center, Hartford CT. Lines: 47 Nntp-Posting-Host: sc3.hgc.edu In article <1991Jun10.151959.29568@mstr.hgc.edu> jcm@mstr.hgc.edu (James McKim) writes: (This is me, unfortunately!) >In article <131732@tut.cis.ohio-state.edu> ogden@seal.cis.ohio-state.edu (William F Ogden) writes: >>OK. Let's look at the side effecting function Pop_of vs. the value >>returning Pop_Top procedure on stacks of say integers. If we have >>a stack whose top two entries are say 5 and 3, then, because there's >>an indeterminate order of evaluation problem even in fairly simple >>situations, executing >> >> Dif := Pop_of(S) - Pop_of(S); >> >>might cause Dif to be either 2 or -2. In contrast, with the Pop_Top >>procedure, there can be no uncertainty because a programmer must >>explicitly sequence the operations. >> Pop_Top(S,t1); >> Pop_Top(S,t2); >> Dif := t1 - t2; {or t2 - t1} >> > >OK, so when you say 'procedure with a return value' you mean the >value is returned through arguments of the procedure. Conceptually, >this is still a function with side effects (the return value is just >in a different place). The distinction depends on the language >definition or implementation. > Well, it's now Monday afternoon (I should be banned from posting on Monday morning!) and I now understand (I think) the conceptual difference. Pop_Top as defined above does _not_ return a value for immediate use, rather it changes the state of _two_ objects, the client and the supplier. On the other hand, Pop_of both changes the state of the stack object and returns a value for immediate use, which Bill clearly demonstrates can cause confusion. Now, did I make the same error in another post this morning...? >> >>-- >> >>/Bill > >-- Jim > -- Me again *------------------------------------------------------------------------------* Jim McKim (203)-548-2458 _Give_ people fish and they eat for a day. Internet: jcm@mstr.hgc.edu _Teach_ people to fish and they eat for a lifetime.