On 16 Jul 1998 at 11:42:44 +0200, sperber(a)informatik.uni-tuebingen.de
(Michael Sperber [Mr. Preprocessor]) wrote:
>>>>> "RP" == Reggie Perry
<Reggie.Perry(a)digital.com> writes:
RP> I think that tail recursion could be done in common lisp.
How?
Common Lisp is not inherently incompatible with tail recursion
elimination. For example:
- CLtL2 mentions the possibility on page 686:
<
URL:http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node227.html>
- Harlequin's mostly-ANSI-compliant Liquid Common Lisp (formerly Lucid
CL) does such elimination, as documented in their user manual:
<
URL:http://www.harlequin.com/education/books/lispworks/lcl/aug/aug-51.htm...
- I'm also pretty certain (although not entirely positive) that the
CLtL2-compliant-with-some-ANSI-extensions Macintosh Common Lisp
(<
URL:http://www.digitool.com/>) does tail recursion elimination on
functions declared (speed 1) or better. At least I seem to remember
that from my now somewhat distant MCL programming days although,
admittedly, the system may have changed drastically in the 6 years
since I last used it. :-)
I have Allegro CL from Franz (<
URL:http://www.franz.com/>) on my home
machine, so I'll try compiling a tail-recursive procedure tonight and
see if it applies this optimization.
(BTW, those of you with Linux systems can try out Allegro CL for free.
See the web page. Those with Windows systems might want to try out
Harlequin's FreeLisp, <
URL:http://www.harlequin.com/>. Note that both
come with an Emacs-like editor.)
I once read something about why some Common Lisp implementations do not
provide tail recursion elimination. I've been racking my brains to
recall where I read it, but no luck so far. It was something to do with
supporting catch and throw as I recall, but for the life of me, I can't
imagine why that would be much of an obstacle. Surely you could just
refuse to do TRE on a function containing a catch if you don't want to
deal with analyzing how the stack might unwind.
On the subject of call/cc, I also would like to thank Chipsy for the
nice tutorial. I would like one more piece of information, though. How
does call/cc relate to a lexical closure?
--
Jerry James
Email: jerry(a)cs.ucsb.edu
WWW:
http://www.cs.ucsb.edu/~jerry/