Re: [Pharo-project] Reference temporary variable of method ( or other solution )
On Jul 28, 2011, at 5:11 PM, Dario Trussardi wrote:
and methodB:
methodB
| a b c |
a := 'a'.
......... i can now at this step reference the var1 defined in methodA ?
I think it's in the stack or i wrong ?
Yes, it is on the stack: thisContext sender tempNamed: 'var1'. but tempNamed: has to look at the sources... so faster is: thisContext sender tempAt: 1.
It's no elegant do it ?
I would not do it... it's hard to understand, easy to break (adding a temp will break it, refactoring breaks it easily, calling the method from somewhere else will lead to funny effects, and so on). And it's slow (on the jit it means that the context needs to be created) and far too much magic. Marcus -- Marcus Denker -- http://marcusdenker.de
On 28 July 2011 17:54, Marcus Denker <marcus.denker@inria.fr> wrote:
On Jul 28, 2011, at 5:11 PM, Dario Trussardi wrote:
and methodB:
   methodB
       | a b c |
       a := 'a'.
       .........  i can now at this step  reference the          var1    defined in methodA ?
I think it's in the stack or i wrong ?
Yes, it is on the stack:
    thisContext sender tempNamed: 'var1'.
but tempNamed: has to look at the sources... so faster is:
    thisContext sender tempAt: 1.
It's no elegant do it ?
I would not do it... it's hard to understand, easy to break (adding a temp will break it, refactoring breaks it easily, calling the method from somewhere else will lead to funny effects, and so on).
yes, but you can check who calling you, like: (thisContext sender method == (SomeClass>> #methodA )) ifTrue: [ ... ] but of course it doesn't makes this hack less evil. Less brittle , yes :)
And it's slow (on the jit it means that the context needs to be created) and far too much magic.
    Marcus
-- Marcus Denker -- http://marcusdenker.de
-- Best regards, Igor Stasenko AKA sig.
participants (2)
-
Igor Stasenko -
Marcus Denker