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)


Bernard URBAN <Bernard.Urban@meteo.fr> writes:

 > >>>>> "Jim" == Jim Blandy <jimb@red-bean.com> writes:
 > 
 >     Jim> Bernard, tell me if I've got this right:
 > 
 >     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))))

1. I assume you meant:

   (define (fact n)
     (if (<= n 1)
	 1
         (* n (fact (- n 1)))))

2. This *isn't* tail recursion.  *Nothing* requires it to run in
   finite space.

-- 
Harvey J. Stein
BFM Financial Research
hjstein@bfr.co.il