This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Tail recursion and hobbit (was: finite state machines in guile)


> From: Bernard URBAN <Bernard.Urban@meteo.fr>
> >>>>> "Jim" == Jim Blandy <jimb@red-bean.com> writes:
> 
>     Jim> Hobbit does turn some tail calls into jumps, if it is able to
>     Jim> figure out how.  However, tail calls to other top-level
>     Jim> functions, and some tail calls within a single top-level
>     Jim> function, are not optimized, and allocate additional stack
>     Jim> space.
> 
> Exactly. For instance, the following is not tail call optimized:
> 
> (define (fact n)
>   (if (<= n 1)
>       1
>       (* n fact (- n 1))))
> 
> even if equivalent to the original factorial.

I don't see the point of the example.  There is no tail call (to fact)
in this definition, and Scheme does not require this program to run in
constant space.  The fact that it computes the same function as a
program that does run in constant space is irrelevant.  Scheme does
not require that any program be translated into its most efficient
equivalent (that is provably impossible), but only that certain
syntactic forms of procedure call be done in constant space.

-- 
     --Keith

This mail message sent by GNU emacs and Linux.
Food, Shelter, Source code.