Hi Lukas,<div><br></div><div>    can you forward my response to Pharo?  TIA.<br><br><div class="gmail_quote">On Wed, Dec 16, 2009 at 2:54 AM, Lukas Renggli <span dir="ltr">&lt;<a href="mailto:renggli@gmail.com">renggli@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;">Hi Eliot<br>
<br>
While working on a way to use the RB-AST with the standard compiler I<br>
think I found a problem in your code. To reproduce evaluate the<br>
following expression:<br>
<br>
    [ :a | ] value: 1<br>
<br>
According to my understanding that should return nil, not the first argument 1.<br>
<br>
The generated bytecode is:<br>
<br>
    pushTemp: 0<br>
    blockReturn<br>
<br>
I think it should be:<br>
<br>
    pushConstant nil<br>
    blockReturn<br>
<br>
Cheers,<br>
Lukas<br></blockquote><div><br></div><div>:) :)  This is funny.  VisualWorks has exactly the same bug^H^H^Hfeature.  And if you look at the ANSI standard (ok, this is from the draft, but it is essentially the actual document) there is an exception for precisely this case,  See the last sentence in section 3.4.4 Blocks:</div>
<div><br></div><div><p style="margin: 0.0px 0.0px 12.0px 28.8px; font: 10.0px Arial"><span style="letter-spacing: 0.0px"><span class="Apple-style-span" style="font-size: small;">If a block has no &lt;</span></span><span style="font: 10.0px Helvetica; letter-spacing: 0.0px"><span class="Apple-style-span" style="font-size: small;">block body</span></span><span style="letter-spacing: 0.0px"><span class="Apple-style-span" style="font-size: small;">&gt; or no &lt;</span></span><span style="font: 10.0px Helvetica; letter-spacing: 0.0px"><span class="Apple-style-span" style="font-size: small;">statements</span></span><span style="letter-spacing: 0.0px"><span class="Apple-style-span" style="font-size: small;">&gt; in its &lt;</span></span><span style="font: 10.0px Helvetica; letter-spacing: 0.0px"><span class="Apple-style-span" style="font-size: small;">block body</span></span><span style="letter-spacing: 0.0px"><span class="Apple-style-span" style="font-size: small;">&gt; then the value of the block is undefined. </span></span></p>
<div>Which allows [] to be implemented as e.g. [Random new next].  In fact both VisualWorks and Squeak answer the last argument:</div><div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>[:a ] value: 1 1</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>[:a :b|] value: 1 value: 2 2</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>[:a :b :c :d :e :f :g :h| ] valueWithArguments: (1 to: 8) 8</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>[:a | nil] value: 1 nil</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>[:a :b| nil] value: 1 value: 2 nil</div><div><br></div><div>
At least it is consistent whether the block is inlined or not ;)</div><div><br></div><div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>1+2 ifNotNil: [:arg|] 3</div><div><br></div><div>It as ever been so.  This from Smalltalk-80 V2:</div>
<div><i>BlockNode methods for initialize-release</i></div><div><div>arguments: argNodes statements: statementsCollection returns: returnBool from: encoder</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>sourceEnd: sourceEnd </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;compile&quot;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>sourceRange  _ sourceEnd to: sourceEnd.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>arguments _ argNodes.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>statements _ statementsCollection size &gt; 0</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>ifTrue: [statementsCollection]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>ifFalse: [argNodes size &gt; 0</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>ifTrue: [statementsCollection copyWith: arguments last]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span>ifFalse: [Array with: NodeNil]].</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>returns _ returnBool</div><div><br></div><div>
This from VW:</div><div><span class="Apple-style-span" style="font-style: italic; ">BlockNode methods for code generation</span></div><div><div>emitBody: codeStream</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;The codeStream invokes this to compile</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>the body of the block, including the final return.&quot;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>(body isEmpty and: [arguments isEmpty not])</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ifTrue:</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>[codeStream noteSourceStart: body.</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>arguments last variable emitLocalReturn: codeStream from: body]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [body emitLocalReturn: codeStream from: body]</div><div><br></div><div>This from Squeak (my timestamp, but I just changed the _&#39;s to :=&#39;s :) )</div>
<div><br></div><div><span class="Apple-style-span" style="font-style: italic; ">BlockNode methods for initialize-release</span></div><div><div>arguments: argNodes statements: statementsCollection returns: returnBool from: encoder</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Compile.&quot;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>arguments := argNodes.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>statements := statementsCollection size &gt; 0</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>ifTrue: [statementsCollection]</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>ifFalse: [argNodes size &gt; 0</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>ifTrue: [statementsCollection copyWith: arguments last]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span>ifFalse: [Array with: NodeNil]].</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>optimized := false.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>returns := returnBool</div>
<div><br></div><div>So at least it is easy to fix ;)  The question you have to ask yourself is how much code is affected by this wafer thin change. I&#39;m with you, I think this is a bug.  But perhaps it was well thought through.  What say you, Dan &amp; Peter?  Did y&#39;all agonise over this?  What say you Squeak &amp; Pharo communities?  Should we fix this or make it a preference ;)</div>
<div><br></div><div>best</div><div>Eliot</div><div><br></div><div><br></div><div>P.S.  I&#39;m caught between wanting to fix it and wanting to let sleeping dogs lie.  I&#39;d like to know what all the other dialects do.  If a substantial majority have the same curio I think we have to live with this, uh, ornament.  Just to be clear, making it a preference is a sick joke on my part.</div>
<div><br></div></div></div></div></div></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="#888888"><br>
--<br>
Lukas Renggli<br>
<a href="http://www.lukas-renggli.ch" target="_blank">http://www.lukas-renggli.ch</a><br>
</font></blockquote></div><br></div>