[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A proper tail version of with-fluids

From: Andy Wingo
Subject: Re: A proper tail version of with-fluids
Date: Mon, 21 Jan 2013 22:05:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

On Fri 04 Jan 2013 00:36, address@hidden (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

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]