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

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Sun Apr 19 21:46:00 UTC 2020


Hi Stef,


good question. You can get the argument names via aBlock decompile arguments, and if you also care about the temp names, you can append aBlock decompile temporaries. But you probably knew that already :)


If you have the possibility to invoke the block, you could also try something like:


| y |
y := 10.
([:x | y + x. thisContext] value: 42) tempsAndValues


If you cannot invoke the block, here would an even more hacky alternative:


| y |
y := 10.
aBlock := [:x | y + x].
(aBlock simulateValueWithArguments: (Array new: aBlock numArgs) caller: aBlock outerContext) tempsAndValues

But I agree that these are no nice solutions at all. I suppose the point is that in contrast to literal bindings, temporary variables are never actually stored as bindings in the block method. For what purpose do you need the bindings?

Best,
Christoph

________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Stéphane Rollandin <lecteur at zogotounga.net>
Gesendet: Sonntag, 19. April 2020 18:18 Uhr
An: liste [Squeak-dev]
Betreff: [squeak-dev] Accessing temp variables bindings in a BlockClosure

Hello,

Is there a way to map the temp variables stored in a BlockClosure with
their names as they appear in the decompileString?

For example we have:

        | y |
        y := 10.
        [:x | y + x] basicAt: 1         "returns 10"

and

        | y |
        y := 10.
        [:x | y + x] decompileString    "returns '[:x | y + x]'"


What I would like is something like

        | y |
        y := 10.
        [:x | y + x] tempBindingAt: 1    "would return #y -> 10"


Stef

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200419/84bfb1a4/attachment.html>


More information about the Squeak-dev mailing list