On Sat, Jan 26, 2008 at 12:20:31PM -0800, Wade Curry wrote:

So, now that I understand this a _little_ better, how does scheme
compare to common lisp in regard to optimizing tail recursion?  Is
tail recursion as efficient as iteration in CL?

Pretty much any scheme compiler will compile local tail recursion (a
procedure calling itself) directly into a loop.  Between global procedures
is usually a little iffy.  In fact, some implementations don't even do it
right, and will blow the stack.

A construct known as a named let is the most flexible iteration in scheme.
It's basically named recursion with a shortcut to define the function.

  (let loop ((var init)
             (var2 init2))
       form
       form
       (loop newvar newvar2))

Obviously with more details, and hopefully an exit clause.  Any compiler
should detect this case and make this directly into a loop.

David

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to