[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A Modest Tail-Recursion Proposal



Hello,
	I've just gotten around to digestifying some of the old slug messages
for our local users to peruse, and ran across the discussion some while
back on tail recursion, and I'd like to make a simple, probably non-feasable
suggestion to those who would like it to be available:
	Why don't you build yourself (and us!) a defun-like thing called,
say, defun-tr, that works just like defun in all respects EXCEPT that it
makes use of loop, or do, with let to change its code from recursive calls
into a loop?  This would be, say, a macro like loop (from whence my inspiration
flows) so that you could c-sh-m to see what it would expand to.  Then, you
could run it interpreted and understand its behaviour (with step), and compile
for extra speed.  Of course, it would have to recognize when the code it'd 
been handed wasn't tail-recursivible (sp? :-), but then it could just expand 
into a regular defun and behave correctly.
	I'd do it myself :-) except that I don't understand tail recursion
sufficiently, and I'm going to be away from my beloved lispmachines for
a few months again.  Sigh.
	-- Chris Sterritt
PS: Speaking of loop, is there any hope that the symbolics version (with
all the useful clauses) will become part of common lisp?  It's just
inordinately useful (for those of us who don't know how/when to 
tail-recurse :-).