On Fri 04 Jan 2013 00:36, l...@gnu.org (Ludovic Courtès) writes: > Hmm, I can’t see how ‘with-fluids’ or ‘parameterize’ could be > tail-recursive given that it uses ‘dynamic-wind’. Am I missing > something?
It doesn't use dynamic-wind. scheme@(guile-user)> ,x (lambda () (with-fluids ((foo 1)) 2)) 0 (assert-nargs-ee/locals 0) ;; 0 args, 0 locals 2 (toplevel-ref 1) ;; `foo' 4 (make-int8:1) ;; 1 5 (wind-fluids 1) 7 (make-int8 2) ;; 2 9 (unwind-fluids) 10 (return) 11 (unwind-fluids) 12 (return/nvalues) The wind-fluids and unwind-fluids do not use dynamic-wind (though they do use the dynamic stack (dynwind stack)). As you can see the body is inlined. The same for parameterize -- it compiles to with-fluids eventually. Anyway, the trick is to detect with-fluids in a tail position, and to detect recursive tail calls -- and in that case, to update the binding in place, and actually do a tail call instead of pushing a new frame. Andy -- http://wingolog.org/