[squeak-dev] Accessing temp variables bindings in a BlockClosure

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Sun Apr 19 23:02:37 UTC 2020


Hi Stef,


> because the block basicAt: 1 is actually a list with the value of both x and y - and I do not see how to detect this case.


I may be wrong, but sending #basicAt: to BlockClosures should access its closured objects only, in the way their sender wrote them on it. I suppose this is not a reliable way to access temporaries from it?


The array you found is a remote temp vector, which is basically an implementation detail of how closures work. In a nutshell, a BlockClosure holds a copy of each variable it accesses ("closures") from its outerContext, in order to optimize the execution of blocks. However, if a block must be supposed to reassign some of these variables, we would need to sync these copies with their originals. To avoid this expensive operation, variables that are assigned from within the block are stored in an extra remote temp vector that is common to the block and its outer context(s). You can study the following observations if you're interested:


| a b c d e |
a := 1.
b := 2.
c := 3.
d := 4.
e := 5.
[a. b. c := 6. d := 7]


[cid:cf9d0c42-2b72-49af-af6a-b13d4bdbd0ad]


| x |
x := 2.
[
thisContext sender tempAt: 1 put: 3.
x
] value. "2"


Disclaimer: I played some time around with this amazing stuff and received a number of valuable explanations from the community, but I'm still new to the domain. Nothing I try to explain must be correct or make sense and others can probably tell you better :-)


Here is a really nice explanation by Eliot: http://forum.world.st/BUG-Cannot-compile-cascade-sent-to-block-tp5108942p5109012.html


Best,

Christoph


PS: Just saw your screenshot. If you do not need to access temporaries/args that are local to the blocks, shouldn't you be fine with aBlock outerContext tempsAndValues?



________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Stéphane Rollandin <lecteur at zogotounga.net>
Gesendet: Montag, 20. April 2020 00:24:45
An: squeak-dev at lists.squeakfoundation.org
Betreff: Re: [squeak-dev] Accessing temp variables bindings in a BlockClosure

> At the moment I have something working in many cases, but not all (attached)
>
> It can do
>        | y x |
>        y := 10.
>        x := 8.
>        [:a :b | a + y + x] tempBindings         " {'y'->10 . 'x'->8} "

... well in fact it can't, because just switching x and y in the block
leads to:

        | y x |
        y := 10.
        x := 8.
        [:a :b | a + x + y] tempBindings        "  {'x'->10 . 'y'->8} "

So I'm stuck.

Stef



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200419/e1146e73/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 13504 bytes
Desc: pastedImage.png
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200419/e1146e73/attachment.png>


More information about the Squeak-dev mailing list