<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Sorry, yes, "dict" should be "collection".</div><div><br></div><br><div><div>On 02.08.2013, at 15:16, Clément Béra &lt;<a href="mailto:bera.clement@gmail.com">bera.clement@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">This is not a bug.<div><br><div style="">Here your variable methodScope is defined outside the block, therefore all the blocks and the method refers to the same variable when calling methodScope.</div></div></div></blockquote><div><br></div><div>Yes, I understand that. I just wanted to make sure that's the intended functionality. The reason I ask is that the error isn't easy to spot and there's no cue that one might be doing something wrong (It's not my code by the way :P). Especially for newcomers this can be a tricky one.</div><div><br></div><div>I totally agree with you that the variables belong to the block and should be declared there.</div><br><blockquote type="cite"><div dir="ltr"><div><div style="">
<br></div><div style="">Your code is the same as if you wrote :</div><div style="">| methodScope |</div><div style="">methodScope := 1.&nbsp;</div><div style="">methodScope := 2.</div><div style="">At the end, methodScope is of course 2.</div>
<div style=""><br></div><div style="">If you want the result :</div><div style="">1</div><div style="">2</div><div style="">you have to declare the variable in the block (then there are different variable named methodScope, actually 1 per activation of the block.</div>
<div style=""><br></div><div style="">collection := OrderedCollection new.<br>1 to: 2 do: [ :index |</div><div style="">&nbsp; &nbsp; &nbsp; &nbsp; | methodScope |<br>&nbsp; &nbsp; &nbsp; &nbsp; methodScope := index.<br>&nbsp; &nbsp; &nbsp; &nbsp; dict add: [ methodScope ] ].<br>collection do: [ :block | Transcript show: block value; cr ]<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/8/2 Max Leske <span dir="ltr">&lt;<a href="mailto:maxleske@gmail.com" target="_blank">maxleske@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I just came across this (possible) bug and I'm able to reproduce it in Pharo 2.0 and 3.0 with the latest PharoVM (found in a 1.3 with NBCog):<br>
<br>
expected (by my feeble mind):<br>
1<br>
2<br>
<br>
actual:<br>
2<br>
2<br>
<br>
| methodScope |<br>
collection := OrderedCollection new.<br>
1 to: 2 do: [ :index |<br>
&nbsp; &nbsp; &nbsp; &nbsp; methodScope := index.<br>
&nbsp; &nbsp; &nbsp; &nbsp; dict add: [ methodScope ] ].<br>
<br>
collection do: [ :block | Transcript show: block value; cr ]<br>
<br>
I'm aware that using method temps in this way is not good programming style (usually) but I still think this behavior is curious if not at least very likely to cause a lot of weird errors.<br>
<br>
Should I open a bug report?<br>
<br>
Cheers,<br>
Max</blockquote></div><br></div></div></div>
</blockquote></div><br></body></html>