<br><br><div class="gmail_quote">On Tue, Jul 9, 2013 at 11:29 PM, Frank Shearar <span dir="ltr">&lt;<a href="mailto:frank.shearar@gmail.com" target="_blank">frank.shearar@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">
<div class="HOEnZb"><div class="h5"><br>
On 9 July 2013 23:03, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Jul 9, 2013 at 1:27 AM, Igor Stasenko &lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On 9 July 2013 10:15, Clément Bera &lt;<a href="mailto:bera.clement@gmail.com">bera.clement@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Hello pharoers,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Recently I have been looking at the Pharo thisContext capabilities, in order<br>
&gt;&gt; &gt; to perhaps one day in the far future edit its implementation with the Pharo<br>
&gt;&gt; &gt; dev team. Nothing is planned or confirmed, it is just to discuss.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; A context has instances variables (method closureOrNil receiver stackp<br>
&gt;&gt; &gt; sender pc) and holds the arguments and temporaries.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Now I&#39;d like to know what context&#39;s state do we modify, and what states are<br>
&gt;&gt; &gt; just internal representations ?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; For example, it seems that you can do &#39;thisContext receiver: #foo&#39;, but you<br>
&gt;&gt; &gt; cannot with Cog.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; SomeClass&gt;&gt;foo<br>
&gt;&gt; &gt; thisContext receiver: #foo.<br>
&gt;&gt; &gt; ^ self<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; In workspace, evaluating:<br>
&gt;&gt; &gt; 1 to: 5 do: [:i | Transcript show: SomeClass new foo ]<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Transcript result (with Cog):<br>
&gt;&gt; &gt; foo<br>
&gt;&gt; &gt; foo<br>
&gt;&gt; &gt; a SomeClass<br>
&gt;&gt; &gt; a SomeClass<br>
&gt;&gt; &gt; a SomeClass<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Transcript result (with Stack or Vanilla):<br>
&gt;&gt; &gt; foo<br>
&gt;&gt; &gt; foo<br>
&gt;&gt; &gt; foo<br>
&gt;&gt; &gt; foo<br>
&gt;&gt; &gt; foo<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Now as no one has ever complained, I guess this feature is not used.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; As far as I know, the real use cases of the context seems to be:<br>
&gt;&gt; &gt; - setting and gettings temporaries<br>
&gt;&gt; &gt; - setting and getting the sender of a context<br>
&gt;&gt; &gt; - setting and getting the pc<br>
&gt;&gt; &gt; - getting method, closureOrNil, receiver, stackp, arguments but NOT setting<br>
&gt;&gt; &gt; them<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Now setting the sender of a context seems to be used only in two cases:<br>
&gt;&gt; &gt; - continuations (as seaside continuations)<br>
&gt;&gt; &gt; - exception implementation<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; So imagine that in the future you would have a context that can be accessed<br>
&gt;&gt; &gt; in read-only, where you could only:<br>
&gt;&gt; &gt; - set the temporaries (but not arguments)<br>
&gt;&gt; &gt; - set the pc (or something equivalent, as set the currently executed ast<br>
&gt;&gt; &gt; node)<br>
&gt;&gt; &gt; - use continuations (exceptions can be implemented on top of continuations)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I would like to know if there are things that you do now and that you would<br>
&gt;&gt; &gt; not be able to do with a context like that. For non meta developer (like<br>
&gt;&gt; &gt; enterprise app developer) I guess it will not change anything, but I want to<br>
&gt;&gt; &gt; know if you implemented a framework as seaside, does it requires other<br>
&gt;&gt; &gt; things from the context and why ?<br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; To my thinking playing with pc is awfully evil, it should be<br>
&gt;&gt; read-only, only to allow debugger<br>
&gt;&gt; to map it to source code. Same goes for stack pointer.<br>
&gt;<br>
&gt;<br>
&gt; There are good uses for this  I just used it to implement basic-block coverage for methods.  One can use it for exception handling (mustBeBoolean etc).  I&#39;m always wary of introducing restrictions when the system has worked fine without them for years.  One exception recently was in adding bounds checking to CompiledMethod&gt;&gt;at:put: so one could not change arbitrary bytes in the literals via at:put:.  But this was adding safety, not adding a restriction.  I see no harm in allowing one to assign the pc.  It is unsafe, and the system will likely crash if you get it wrong.  But it is also potentially useful (e.g. I&#39;ve used it to do a prototype of tail-recursion elimination).<br>

<br>
</div></div>Do you mean just eliminating tail calls in some easy places, or proper<br>
tail calls? (I keep saying &quot;proper tail call&quot; and not &quot;tail call<br>
optimisation/elimination&quot; because implementing proper tail calls is<br>
_language design_, not optimising. Or, having proper tail calls lets<br>
you do things that are impossible without a global program<br>
transformation. Handily, we can often implement language design in our<br>
own language!)<br></blockquote><div><br></div><div>I mean a hack that allows a context to restart itself with any of different receiver/arguments/method.  e.g. thisContext tailSend: selector to: receiver with: arg with: arg.  More a test of contexts than a useful facility.  But a fun experiment all the same.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
frank<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
&gt;  So let&#39;s be laissez faire, unless the freedoms in question really do only do harm.<br>
&gt;<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Setting receiver is less evil and it may work, if receiver belongs to<br>
&gt;&gt; same inheritance chain<br>
&gt;&gt; as compiled method&#39;s class. But it should not be set without checking this.<br>
&gt;&gt;<br>
&gt;&gt; And for method&#39;s temps, it is fine.<br>
&gt;&gt;<br>
&gt;&gt; &gt; Thanks for answering,<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Best regards,<br>
&gt;&gt; Igor Stasenko.<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; best,<br>
&gt; Eliot<br>
&gt;<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>