guile-devel
[Top][All Lists]
Advanced

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

Re: A proper tail version of with-fluids


From: Noah Lavine
Subject: Re: A proper tail version of with-fluids
Date: Thu, 3 Jan 2013 18:44:56 -0500

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 <address@hidden> wrote:
Hi Stefan,

Stefan Israelsson Tampe <address@hidden> 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

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