I think with-fluids could at least be semi-tail-recursive. If you imagine a
normal non-tail-recursive implementation, you might get to a point where
your continuation is going to set a fluid back to a value, and then the
*next* continuation is going to set that fluid back to *another* value.
Since these are only set!s and have no side-effects, you could somehow
notice that and not do the first set!. So your continuation only needs to
have one set! for each fluid, no matter how many times that fluid is
changed by with-fluids.

But that seems tricky to implement. I haven't looked at how Stefan did it,
but I'm impressed.

Noah


On Thu, Jan 3, 2013 at 6:36 PM, Ludovic Courtès <l...@gnu.org> wrote:

> Hi Stefan,
>
> Stefan Israelsson Tampe <stefan.ita...@gmail.com> skribis:
>
> > (define f (lambda (n) (if (= n 0) (fluid-ref a) (with-fluids ((a n)) (f
> (-
> > n 1))))))
> >
> > with the modified VM:
> > scheme@(guile-user)> (f 10000000)
> > $2 = 1
> >
> > with the old VM, it craches. It works!
>
> Hmm, I can’t see how ‘with-fluids’ or ‘parameterize’ could be
> tail-recursive given that it uses ‘dynamic-wind’.  Am I missing
> something?
>
> Ludo’.
>
>
>

Reply via email to