<div dir="ltr">I didn't read your post clearly enough. Yep, that would seem odd. You may have a bug there. I'm not sure why that happens. It looks like the outer context isn't taking the assignment, but hanging onto the initial value it receives from #value:. <div>
<div><br></div><div style>I'm not totally sure we should expect to be able to do what you're trying to do in modern Squeak. I haven't assigned to a block arg in a long time (I keep allow block assignments off unless I'm loading old code.) I don't know what the status is there. I run a relatively recent Cog VM on a 10.7.5 Mac and I'm seeing the same behavior in Squeak 4.4.</div>
<div style><br></div><div style>When I switch to an old VM (3.8.18Beta3U) and run Squeak 3.0, your snippet works as expected. I'm not sure if this is in the image or the VM yet, or whether it's expected behavior or not with allowBlockArgumentAssignment (Again, I usually turn it off.)</div>
<div><br></div><div style>The main take away here is, don't do that:) as it's a back-compat feature and it really ought to have a big sign on it that says DEPRECATED. If you're trying to load some older code and running into this, it might be better to actually rewrite it not to assign to block arguments in my opinion (and maybe I'm nuts.)</div>
<div style><br></div><div style>Can you tell me what VM you're using?</div><div style><br></div><div style>Smalltalk vmVersion "this will tell us"</div><div style><br></div><div style>And also which version of Squeak?</div>
<div style><br></div><div style>SmalltalkImage current systemInformationString "ditto"<br></div><div style><br></div></div><div style>Also, what's the OS of the host system?</div><div style><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Aug 5, 2013 at 1:44 AM, psea <span dir="ltr"><<a href="mailto:denis.lukichev@gmail.com" target="_blank">denis.lukichev@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Smalltalkers!<br>
<br>
Here is a question I can't find answer with google.<br>
In short: Does block parameters and block local variables are the same thing<br>
(semantically) inside closure? It looks like it's not. Below the<br>
explanation.<br>
<br>
===================<br>
Here is the accumulator function (first attempt):<br>
<br>
makeAcc := [ :acc |<br>
[:n | acc:=acc+n. acc]]<br>
<br>
It turns out it doesn't work as intended:<br>
<br>
a1 := makeAcc value: 10<br>
a1 value: 1 => 11<br>
a1 value: 1 => 11<br>
a1 value: 2 => 12<br>
<br>
====================<br>
Here is the second attempt:<br>
<br>
makeAcc := [ :acc |<br>
| total |<br>
total:=acc.<br>
[:n | total:=total+n. total]]<br>
<br>
And it does work as intended:<br>
<br>
a1 := makeAcc value: 10<br>
a1 value: 1 => 11<br>
a1 value: 1 => 12<br>
a1 value: 2 => 14<br>
<br>
So if we use the local variable to store accumulator it works as it should<br>
and remembers the value between function (block) calls. But if we use block<br>
parameter to store the value of accumulator it does not remembers the value<br>
between calls.<br>
Why is it so?<br>
<br>
P.S. Sorry for my English. I do all my best.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://forum.world.st/Modify-block-closure-parameters-tp4702118.html" target="_blank">http://forum.world.st/Modify-block-closure-parameters-tp4702118.html</a><br>
Sent from the Squeak - Beginners mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Casey Ransberger
</div>