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: Stefan Israelsson Tampe
Subject: Re: redo-safe-variables and redo-safe-parameters
Date: Wed, 27 Mar 2013 16:04:05 +0100

Hi Noha,

On Wed, Mar 27, 2013 at 3:29 PM, Noah Lavine <address@hidden> wrote:
> 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?

using set! means that you basically destroys the redo safe property.
There is no sound concept where you mix them. If you want to mix them
use ~ and add correct function guards to describe the semantics.


>>
>> > 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.

You want to allow a user to let one variable behave as with set! and one as with
set~. It is not broken, the useres sees ~ on one of the varibles and !
on the other.

But a large part of the code base will be to use the ~ concept to
achieve a funcitonality
and then combine that into a functiton and macro that will behave as
if there are no
mutation beeing done at all, that is what the users sees. And things
will be easy to reason about code. All effort is done to enable the
macro writer wi actually hide the implementation detail of using set~
behind the scene, If we had a simple framework you would expose a
boxed ~a variable if the user put it into a lambda and there woudl be
suprises appearing.
on the other hand it might be possible to express the semantic without
doing it like I did. i do
like th concept but specification can be buggy and clumsy put
together. The process we are working on rioght now is in perfecting
the idea.

BTW. srfi's shouuld be careful about specifying dynamic state in order
to achieve thread safe concpets, Scheme48 is threadsafe with their
fluid-let, guile would not be.

/Stefan



reply via email to

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