DynamicVariable in a Continuation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

DynamicVariable in a Continuation

Derek Zhou-2
Hi All,
It looks like the sematic of DynamicVariable changed not very long ago; it
was based on Notification, but it now just uses a ProcessVariable. Here is a
simple testcase:

DynamicVariable subclass: Seed [
    ].
Eval [
    |b g1 g2|
    b := [:v | v + Seed value].
    g1 := Generator on: [ :g |
        |v|
        v := 0.
        Seed use: 2 during: [
            [ g yield: v.
              v := b value: v ] repeat ]].
    g2 := Generator on: [ :g |
        |v|
        v := 0.
        Seed use: 3 during: [
            [ g yield: v.
              v := b value: v ] repeat ]].
    Transcript nextPutAll: '%1 %2 %3 %4' % {
        g1 next.
        g2 next.
        g1 next.
        g2 next}; nl.
]

It used to yield "0 0 2 3" but yields "0 0 3 3" now. I'd think "0 0 2 3" is
the correct answer; the documantion specifically mentioned stackframes so
the stackframes hopping from the Continuation should affect the variable,
right?

Derek

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: DynamicVariable in a Continuation

Paolo Bonzini-2
On 05/24/2011 08:20 AM, Derek Zhou wrote:

> Hi All,
> It looks like the sematic of DynamicVariable changed not very long ago; it
> was based on Notification, but it now just uses a ProcessVariable. Here is a
> simple testcase:
>
> DynamicVariable subclass: Seed [
>      ].
> Eval [
>      |b g1 g2|
>      b := [:v | v + Seed value].
>      g1 := Generator on: [ :g |
>          |v|
>          v := 0.
>          Seed use: 2 during: [
>              [ g yield: v.
>                v := b value: v ] repeat ]].
>      g2 := Generator on: [ :g |
>          |v|
>          v := 0.
>          Seed use: 3 during: [
>              [ g yield: v.
>                v := b value: v ] repeat ]].
>      Transcript nextPutAll: '%1 %2 %3 %4' % {
>          g1 next.
>          g2 next.
>          g1 next.
>          g2 next}; nl.
> ]
>
> It used to yield "0 0 2 3" but yields "0 0 3 3" now. I'd think "0 0 2 3" is
> the correct answer; the documantion specifically mentioned stackframes so
> the stackframes hopping from the Continuation should affect the variable,
> right?

You are correct.  The change was made because it was hundreds of time
faster to use ProcessVariable, but I missed this use case.  I have to
think about it.  Do you have any suggestion on how to name the classes
to keep the current one available, and still provide "real"
DynamicVariables?

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: DynamicVariable in a Continuation

Derek Zhou-2
On Wed, May 25, 2011 at 09:35:11AM +0200, Paolo Bonzini wrote:

> On 05/24/2011 08:20 AM, Derek Zhou wrote:
> >Hi All,
> >It looks like the sematic of DynamicVariable changed not very long ago; it
> >was based on Notification, but it now just uses a ProcessVariable. Here is a
> >simple testcase:
> >
> >DynamicVariable subclass: Seed [
> >     ].
> >Eval [
> >     |b g1 g2|
> >     b := [:v | v + Seed value].
> >     g1 := Generator on: [ :g |
> >         |v|
> >         v := 0.
> >         Seed use: 2 during: [
> >             [ g yield: v.
> >               v := b value: v ] repeat ]].
> >     g2 := Generator on: [ :g |
> >         |v|
> >         v := 0.
> >         Seed use: 3 during: [
> >             [ g yield: v.
> >               v := b value: v ] repeat ]].
> >     Transcript nextPutAll: '%1 %2 %3 %4' % {
> >         g1 next.
> >         g2 next.
> >         g1 next.
> >         g2 next}; nl.
> >]
> >
> >It used to yield "0 0 2 3" but yields "0 0 3 3" now. I'd think "0 0 2 3" is
> >the correct answer; the documantion specifically mentioned stackframes so
> >the stackframes hopping from the Continuation should affect the variable,
> >right?
>
> You are correct.  The change was made because it was hundreds of
> time faster to use ProcessVariable, but I missed this use case.  I
> have to think about it.  Do you have any suggestion on how to name
> the classes to keep the current one available, and still provide
> "real" DynamicVariables?

I am not very good at naming, but can we keep DynamicVariable a subclass of
Notification, and provide 2 methods:
use_during_: for the fast way by making use a ProcessVariable
use_inside_: for the slow way of stackframe backtracing.

Derek

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: DynamicVariable in a Continuation

Paolo Bonzini-2
On 05/26/2011 12:29 AM, Derek Zhou wrote:
> I am not very good at naming, but can we keep DynamicVariable a subclass of
> Notification, and provide 2 methods:
> use_during_: for the fast way by making use a ProcessVariable
> use_inside_: for the slow way of stackframe backtracing.

Interesting idea if it can be implemented!  But how would #value know
which one to use?  The slow thing is not _setting_ the variable, it is
_reading_ it, and it seems to me that without doing stack inspection you
cannot know whether you are in a #use:inside: block.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: DynamicVariable in a Continuation

Derek Zhou-2
On Thu, May 26, 2011 at 08:54:41AM +0200, Paolo Bonzini wrote:

> On 05/26/2011 12:29 AM, Derek Zhou wrote:
> >I am not very good at naming, but can we keep DynamicVariable a subclass of
> >Notification, and provide 2 methods:
> >use_during_: for the fast way by making use a ProcessVariable
> >use_inside_: for the slow way of stackframe backtracing.
>
> Interesting idea if it can be implemented!  But how would #value
> know which one to use?  The slow thing is not _setting_ the
> variable, it is _reading_ it, and it seems to me that without doing
> stack inspection you cannot know whether you are in a #use:inside:
> block.
>
Ok we can keep one use_during_: method, but set it both ways. Then we can
provide a value: method for the fast path and a slowValue: method for the
slow path. It is not very elegent but at least the user have a choice.

Derek

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk