<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 04.10.2011, at 17:58, Erlis Vidal wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi all, <br><br>I was looking at the implementation of some of the flow control methods and I have a question with the method <b>whileTrue</b>. <br><br>First of all, I can see two identical implementation in the classes <b>BlockClosure</b> and <b>BlockContext</b> the implementation is this <br>

<br><font size="2"><b style="font-family: courier new,monospace;">whileTrue</b><span style="font-family: courier new,monospace;">: </span><span style="color: rgb(0, 0, 153); font-family: courier new,monospace;">aBlock </span><br style="font-family: courier new,monospace;">

<span style="color: rgb(0, 102, 0); font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; "Ordinarily compiled in-line, and therefore not overridable.</span><br style="color: rgb(0, 102, 0); font-family: courier new,monospace;">
<span style="color: rgb(0, 102, 0); font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; This is in case the message is sent to other than a literal block.</span><br style="color: rgb(0, 102, 0); font-family: courier new,monospace;">

<span style="color: rgb(0, 102, 0); font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; Evaluate the argument, aBlock, as long as the value of the receiver is true."</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; ^ [</span><span style="color: rgb(51, 153, 153); font-family: courier new,monospace;">self </span><span style="font-family: courier new,monospace;">value] whileTrue: [</span><span style="color: rgb(0, 0, 153); font-family: courier new,monospace;">aBlock </span><span style="font-family: courier new,monospace;">value]</span></font><br>

<br>I'm assuming here that there's another class <b>Block</b> I'm missing (something like the literal block mentioned in the comment) which is the one that contains the logic I was looking for. But I'm not able to find any other whileTrue method in my image.</blockquote><div><br></div><div>"Block" is just short for either&nbsp;BlockClosure or&nbsp;BlockContext. "Literal" blocks are those written directly with square brackets. If you store a block in a variable and pass that variable, the block would not be literal.</div><br><blockquote type="cite"> What's the difference between BlockClosure and BlockContext? <br></blockquote></div><div><br></div><div>BlockClosures are&nbsp;BlockContexts Done Right.</div><div><br></div><div>If you wrote square brackets in older Squeak versions (3.x) you would get a&nbsp;BlockContext. In a current Squeak you get a&nbsp;BlockClosure.</div><div><br></div><div>So since now we only have closures, the difference is only of historic interest. You can do some things with closures that you couldn't do with block contexts, e.g. recursive blocks:</div><div><br></div><div><div>| fac |</div><div>fac := nil.</div><div>fac := [:n | n &gt; 1 ifTrue: [n * (fac value: n - 1)] ifFalse: [1]].</div><div>fac value: 10</div></div><div><br></div><div>This would not have worked with contexts.</div><div><br></div><div>
<div style="font-family: Helvetica; font-size: 12px; "><span class="Apple-style-span" style="font-family: Helvetica; ">- Bert -</span></div><span class="Apple-style-span" style="font-size: 12px; "><br class="Apple-interchange-newline"></span>
</div>
<br></body></html>