Hello,

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

> On Wed, Mar 27, 2013 at 1:42 PM, Noah Lavine <noah.b.lav...@gmail.com>
> wrote:
> > 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?
>
> No that would be hard to reason about. set~ and (~ a) indicate that
> you want to use it as a redo safe variable. set! and normal variable
> reference and you will get normal behavior in user code.
>

I don't understand the difference. If I use ~, I get redo-safe behavior,
and if I use !, I get regular behavior (value shared between dynamic
states). Can I use ~ and ! on the same variable at different places in the
code? If yes, doesn't it have to switch behavior?


> > 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.
>
> Yeah that could be one thing to describe it, but I think that it's
> much nicer to let the code behave as scheme when the user code it as
> scheme as described above.
>

I see what you're saying, but I don't think introducing variables with new
semantics and then hiding them is the right thing to do. After all, this
new class of variables will also be "Scheme". Also, let's say you're
writing a macro that introduces a redo-safe variable. You don't know
whether the macro user will set it with set! or set~, so you have to write
something that works in both cases. If you have two variables that you use
together, it's much worse - what if the user calls set! on one of them but
not the other? I think the only way to reason about programs is for each
variable to have one type of behavior.

Noah

Reply via email to