guile-devel
[Top][All Lists]
Advanced

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

Re: redo-safe-variables and redo-safe-parameters


From: Noah Lavine
Subject: Re: redo-safe-variables and redo-safe-parameters
Date: Wed, 27 Mar 2013 10:29:00 -0400

Hello,


On Wed, Mar 27, 2013 at 9:22 AM, Stefan Israelsson Tampe <address@hidden> wrote:
On Wed, Mar 27, 2013 at 1:42 PM, Noah Lavine <address@hidden> 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

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