Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!news.mathworks.com!fu-berlin.de!zrz.TU-Berlin.DE!isst.fhg.de!berlin.fhg.de!news.fhg.de!blackbush.xlink.net!ins.net!heeg.de!hmm
From: hmm@heeg.de (Hans-Martin Mosner)
Subject: Re: Tail recursion ???
Message-ID: <DwJA31.8q8@heeg.de>
Sender: uucp@heeg.de
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
X-Newsreader: TIN [version 1.2 PL2]
References: <4uvjlg$i0b@goanna.cs.rmit.edu.au> <DwDquu.JFJ@heeg.de> <ww7rap3nzbh.fsf@garden.WPI.EDU> <4vdpa5$dob@tandem.CAM.ORG>
Date: Thu, 22 Aug 1996 09:52:13 GMT
Lines: 33

Vassili Bykov (vbykov@cam.org) wrote:
... a very good explanation of context substitution ...

: Context substitution *can* be introduced in Smalltalk.  All that is
: needed is "tail send" VM instruction in addition to the regular "send".
: The compiler should emit "tail send" whenever it sees an explicit return
: of a message send's result, like "^foo blorple: bar".  "Tail send" *need
: not* perform any runtime checks.  The VM unconditionally discards the
: sender's context and creates the new one in its place, so that its
: sender is the sender's sender.

: --Vassili

Yes I see your point. I must admit that my example was rather narrow-minded,
and that tail recursion (or rather, context sustitution, as you explained)
would be not only feasible, but probably advantageous (sp?) in Smalltalk
implementations. From my debugging experiences I know that Smalltalk
call stacks can grow quite big even without recursion, and often the
result of the last message send will be simply returned by the caller.

However, one thing that occurs to me in this context is that for debugging,
you would not want to eliminate intermediate contexts, because without them
you don't see how you got to a specific point. This would imply that either
the VM should have a 'debug' mode in which tail sends are treated like
other sends, or the compiler should emit the tail send instructions
only when production code is generated.

Hans-Martin
--
+--- Hans-Martin Mosner -------- Senior Smalltalk Guru ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm@heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
