<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 21, 2013 at 10:29 AM, Yoshiki Ohshima <span dir="ltr">&lt;<a href="mailto:Yoshiki.Ohshima@acm.org" target="_blank">Yoshiki.Ohshima@acm.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I have a potential application of valueWithReceiver for BlockClosures<br>

(not CompiledMethod) in my little project.  It&#39;d start with something<br>
like:<br>
<br>
k1 := Dictionary new.<br>
k1 at: #foo put: 3.<br>
k1 at: #bar put: 4.<br>
<br>
k2 := Dictionary new.<br>
k2 at: #foo put: 6.<br>
k2 at: #bar put: 8.<br>
<br>
and then a closure is created in the context of k1 (thus &quot;self&quot; in the<br>
following is k1):<br>
<br>
self at: #block put: [(self at: #foo) + (self at: #bar)]<br>
<br>
Then later, I&#39;d like to &quot;steal&quot; the block from k1 and evaluate it in<br>
the context of k2:<br>
<br>
(k1 at: #block) valueWithReceiver: k2.<br>
<br>
to get 14 instead of 7.  (Otherwise, in my application, the &quot;equal&quot;<br>
closure that only differ in their &quot;self&quot; would be created many, many<br>
times.  So, I want to share them.)<br>
<br>
....<br>
<br>
And Bert told me that I can just store &quot;k2&quot; into the outerContext&#39;s<br>
receiver and it works. </blockquote><div><br></div><div>Phhh... yes, sort-of.  But the outerContext could be shared by other blocks.  So safest is to copy the outerContext and change the receiver in the copy.  But since you&#39;re doing this to save space and you really, really know what you&#39;re doing, do it Bert&#39;s way.</div>
<div><br></div><div>But IMO it&#39;s far from safe for a base image facility, because</div><div><br></div><div>a) one should really change the receiver along the static chain as the block may be nested within other blocks.</div>
<div><br></div><div>b) one can&#39;t tell, without resort to slow allOwners-style code, if the outerContext is shared by other blocks.</div><div><br></div><div>So this is a really hairy hack that isn&#39;t safe in general, but is really neat in the right context.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
 As long as there is no concurrent invocation,<br>
it&#39;d just work.  Do people see other potential problems?<br></blockquote><div><br></div><div>Apart form the above no.  But why not simply rewrite as</div><div><br></div><div>    self at: #block put: [:scope| (scope at: #foo) + (scope at: #bar)]</div>
<div><br></div><div>and later do</div><div><br></div><div>    (k1 at: #block) value: k1</div><div><br></div><div>?</div><div><br></div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<br>
--<br>
-- Yoshiki<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>