Hello,

Let me see if I understand the point of set! and set~. I think the goal is
to have a variable that is redo-safe, except that if someone uses set~ on
it, then it is not redo-safe. Is that right?

If so, I think a variable like that is too hard to think about. I really
don't think they should be in the language.

If you want to make a redo-safe variable act like it's not redo-safe, you
can use an explicit box. You do it like this:

(redo-safe-variable ((a 1)) (set~ a (make-variable)) ...)

Inside the ..., you don't set~ or set! a, you use variable-set!. That way,
if you capture the dynamic state and restore it, it just resets to being
the same box as it was before, which means that all of the dynamic states
share the same variable object and the same value. I think this is what
Guile would do for regular variables anyway - you just have to be explicit
about it here.

Note: this is actually a large part of the reason why I think
redo-safe-variables (or fluid-let variables) are a good idea. I saw a quote
from Sussman (one of the creators of Scheme) once that said that he should
have made Scheme with immutable variables and explicit boxes for mutable
locations. I think this is a reasonable extension of that
idea.

Best,
Noah


On Wed, Mar 27, 2013 at 3:13 AM, Stefan Israelsson Tampe <
stefan.ita...@gmail.com> wrote:

> On Tuesday, March 26, 2013 06:36:46 PM Noah Lavine wrote:
> > Okay. I don't see a use for number 1. Could you explain why it's
> > important? It seems easier to me to just let each variable have its
> > own type.
> Actually it has it's uses.
> 1.
>
> Note. This ideom aims at being a sound extension to the case where we
> have non boxed local variables that are never put into a closure and
> where we mutate them with lexical-set directly. Maybe that is easier
> to think of them this way. As you see this ideom will enable pretty
> fast execution of the code in the common case where the variable is
> never put in a closure. It will in the not uncommon case when you put
> a local variable inside a closure and return it and preserve the redo
> safe
> property.
>
> I didn't see that fluid-let could allow this as well through an
> optimization e.g.
>
> (let ((a 1)) code ...)
>
> redo safe and can be well optimized =>
> (let (a)
>   (fluid-let ((a 1)) code ...))
>
> And it's actually better in many ways in that fluid-let guards the
> outer context of the variable to be changed. On the other hand,
> fluid-let does not mix well with delayed computations, my suggestion
> does so indeed. So Different notions, different benefit. But as you
> say thay are close to my number 2 suggestion
>
>
> > As for 2, I believe that's how MIT Scheme's (fluid-let ...) works. I
> > suspect that if you give up property 1, then fluid-let would do the
> > job you want.
>
> No, parameter values are stored in different dynamic state and because
> you have one dynamic state per thread usually (it's possible to let
> threads share dynamic-state) the concpet is safe with respect to
> multithreading. It does not look like fluid-let have that property.
>
>
> a)
> > Also, in the example you gave earlier (in your third email in this
> > thread, beginning with "you need to combine fluids and dynamic wind
> > ..."), I don't see the difference between set! and set~ semantics.
>
> b)
> >It
> > seems like the variables there have exactly the same semantics as
> > fluids, except that you don't have to use (fluid-ref ...) to get
> > their value.
>
> a)
> set! means that you will box a value. The coders intention is that it
> should
> behave as such. With set~ you will many times be able to unbox the
> value. But as you say, with the example it may look like they are the
> same. But note that putting a set! in the code means that the
> variables becomes unguarded and the with-undo-variables becomes a
> no-op. Really The whole setup is done in order to keep ~ semantic
> enclosed in a macro and the user of the macro should can work as if
> the macro only uses local variables with no set!.
>
> b)
> As I said, you are right that they are close in notion and many times
> the semantic will overlap but as described above they are different.
>
> /Stefan
>
>

Reply via email to