<br><br><div class="gmail_quote">On Wed, Apr 21, 2010 at 4:34 PM, Hernán Morales Durand <span dir="ltr">&lt;<a href="mailto:hernan.morales@gmail.com">hernan.morales@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
2010/4/21 Lukas Renggli &lt;<a href="mailto:renggli@gmail.com">renggli@gmail.com</a>&gt;:<br>
&gt;&gt; thisContext is a special object for representing an activation in a<br>
&gt;&gt; stack frame in a stack-based VM.<br>
&gt;<br>
&gt; Actually &quot;thisContext&quot; represents *the current* activation/stack-frame.<br>
&gt;<br>
&gt;    foo: anObject<br>
&gt;         ^ thisContext at: 1<br>
&gt;<br>
&gt; is the same as<br>
&gt;<br>
&gt;    foo: anObject<br>
&gt;         ^ anObject<br>
&gt;<br>
<br>
Of course, &quot;this&quot; refers to &quot;the current&quot; in common language usage.<br>
<br>
&gt;&gt; There are two kinds of contexts:<br>
&gt;&gt; Method Contexts and Block Contexts.<br>
&gt;<br>
&gt; Actually in Pharo images there are only instances of MethodContext.<br>
&gt; Though you can ask the context if it comes from a block by sending the<br>
&gt; message #isExecutingBlock.<br>
&gt;<br>
<br>
Actually in Pharo there is a BlockContext class, which is not<br>
instantiated anymore after the introduction of the closure compiler?<br></blockquote><div><br></div><div>Right.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

In other Smalltalks aBlockContext is the resulting context of a block<br>
activation during its evaluation and is activated by sending<br>
#value,.this fills thisContext with the execution information inside<br>
the block.<br></blockquote><div><br></div><div>and it is now with the closure compiler.  Or rather a new context is created when a BlockClosure is sent the value message.  The context is an instance of methodContext though.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">In Squeak (or the old compiler) block contexts were created using<br>
#blockCopy:, now I see #closureNumCopied:numArgs:. Does this means<br>
BlockContext could be completely removed and replaced with<br>
MethodContext semantics? I&#39;ve removed the BlockContext class and used<br>
Pharo a little bit with no problems, maybe some Decompiler issues in<br>
the Debugger...<br></blockquote><div><br></div><div>Yes.  But MethodContext behaves differently depending on whether its closureOrNil inst var is nil (a normal method) or a BlockClosure (an activation of a block).  If nil, ^-returns return to the context&#39;s sender.  If not nil ^-returns return from the home context, found by following the outerContext chain through the closureOrNil inst var.  So we no longer need BlockContext.</div>
<div><br></div><div>This also means we only need one context class, and some time I&#39;d like to merge the two ContextPart and MethodContext classes into a single Context class.  Possibly the name should be ExecutionContext or MethodOrBlockContext or?  Suggestions?</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Now, test yourself before evaluating :) what should be the result of<br>
this expression?<br>
<br>
[: arg | arg perform: #isExecutingBlock ] value: thisContext<br></blockquote><div><br></div><div>It depends on whether the expression is executed at method level or at block level.  As a test this should be:</div><div><br>
</div><div>testIsExecutingBlock</div><div>    self assert: ([: arg | arg perform: #isExecutingBlock ] value: thisContext) == false.</div><div>    [self assert: ([: arg | arg perform: #isExecutingBlock ] value: thisContext) == true] value</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Can somebody justify the result?<br></blockquote><div><br></div><div>isExecutingBlock answers if the receiver is executing a block or not. It does not answer whether the context in which isExecutingBlock is sent is executing a block or not.  Remember that</div>
<div><br></div><div>    [:arg| arg == thisContext] value: thisContext</div><div><br></div><div>is false.  thisContext is rebound within every actual method or block scope.</div><div><br></div><div>HTH</div><div><br></div>
<div>Eliot</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
&gt;&gt; Context creation is optimized in the VM in most Smalltalks, so it&#39;s<br>
&gt;&gt; only really created as an object in the environment (reified) when<br>
&gt;&gt; it&#39;s specifically needed through &quot;thisContext&quot;.<br>
&gt;<br>
&gt; In Pharo contexts are not reified like that. Stack-frames are actual<br>
&gt; objects at all times. However, for speed reasons, their creation and<br>
&gt; garbage-collection is optimized by the VM. Stack frames get<br>
&gt; automatically recycled if nobody refers to them.<br>
&gt;<br>
<br>
I think is what I said :)<br></blockquote><div><br></div><div>But its not a property of Pharo.  It is a property of the VM.  In Cog contexts are not actual objects all the time, only when needed.  And Cog runs Pharo images just as it runs Squeak images.  So it would be incorrect to say &quot;in Pharo&quot; and better to say &quot;in the standard Squeak VM&quot;.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
&gt;&gt; There are several applications related with computational reflection<br>
&gt;&gt; (Reflective Programming, Meta-Programming, MOP, etc) which makes use<br>
&gt;&gt; of the current context.<br>
&gt;<br>
&gt; Also: exception handling, generators, continuations, co-routines, ...<br>
&gt;<br>
&gt; For another fun use of &quot;thisContext&quot; check this Stack-Overflow question:<br>
&gt;<br>
&gt; <a href="http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without-r" target="_blank">http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without-r</a><br>

&gt;<br>
&gt; Lukas<br>
&gt;<br>
&gt; --<br>
&gt; Lukas Renggli<br>
&gt; <a href="http://www.lukas-renggli.ch" target="_blank">www.lukas-renggli.ch</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Pharo-project mailing list<br>
&gt; <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
&gt; <a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br>
&gt;<br>
<br>
_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
<a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a></blockquote></div><br>