<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style='font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif;'>Thank you. <br><br>I had the mis-conception of 1 MethodContext representing the code in that Doit.<br><br>From the BlueBook<br><br><br><blockquote style="border: 1px solid rgb(204, 204, 204); padding: 7px; background-color: rgb(245, 245, 245);"><div>A MethodContext ... Represents the execution of a CompiledMethod in<b> response to a message.</b></div></blockquote> <br><br><br><br>Funny how you can read a thing a dozen times and until you try to do something with it, you don't really understand it.<br><br>Thanks again for your help.<br><br><br><div id="1"><br>---- On Wed, 01 Jan 2014 14:15:01 -0800 <b>Ryan Macnak<rmacnak@gmail.com></b> wrote ---- <br></div><br><blockquote style="border-left: 1px solid #0000FF; padding-left: 6px; margin:0 0 0 5px"> <div dir="ltr"><br><div><br><br><div>On Wed, Jan 1, 2014 at 2:55 PM, gettimothy <span dir="ltr"><<a subj="" mailid="gettimothy%40zoho.com" href="mailto:gettimothy@zoho.com" target="_blank">gettimothy@zoho.com</a>></span> wrote:<br> <blockquote 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><u></u><div><div style="font-size:10pt;font-family:verdana,arial,helvetica,sans-serif"> In Eliot's first example on <a href="http://www.mirandabanda.org/cogblog/category/cog/page/14/" target="_blank">fixing the reentrancy problem</a> that uses "factorial copy" for the recursion.<br><br>I modifed his code:<br> <br><font face="serif"></font><br><blockquote style="border:1px solid rgb(204,204,204);padding:7px;background-color:rgb(245,245,245)"><div><font face="serif"> | factorial |<br>          factorial := [:n| n = 1 ifTrue: [1] ifFalse: [(factorial copy value: n - 1) * n]].<br>          (1 to: 10) collect: factorial copy</font></div></blockquote> <br><br>into something I could trace out a bit easier.<br><br><blockquote style="border:1px solid rgb(204,204,204);padding:7px;background-color:rgb(245,245,245)"> <div><br>| factorial fc |<br>Transcript clear.<br>factorial := [:n |<br> n = 1 <br> ifTrue:[ <br> Transcript show: ' n=', (n asString),' ', (thisContext class name), '(', (thisContext identityHash asString),')' .<br> Transcript show: '--sender-->', (thisContext sender) class name, '(', (thisContext sender) identityHash asString,')'. <br> Transcript show: '--home-->', (thisContext home) class name, '(', (thisContext home) identityHash asString,')'; cr. <br> Transcript show: '++++++++++++++++++++++++++++++++++++++++';cr. <br> "thisContext explore. "<br> 1<br> ] <br> ifFalse:[ Transcript show: '-----------------------------------------------';cr. <br> Transcript show: ' n=', (n asString),' ', (thisContext class name), '(', (thisContext identityHash asString),')' .<br> Transcript show: '--sender-->', (thisContext sender) class name, '(', (thisContext sender) identityHash asString,')'. <br> Transcript show: '--home-->', (thisContext home) class name, '(', (thisContext home) identityHash asString,')'; cr. <br> (factorial copy value: n-1) * n<br> ]].<br>Transcript show:' factorial = ' , (factorial class name),'(',factorial identityHash asString,')'. <br>Transcript show: '--sender-->', (factorial sender) class name, '(', (factorial sender) identityHash asString,')'. <br> Transcript show: '--home-->', (factorial home) class name, '(', (factorial home) identityHash asString,')'; cr. <br>Transcript show: '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^';cr. <br> fc := factorial copy .<br><br>Transcript show:' fc = ' , (fc class name),'(',fc identityHash asString,')'. <br>Transcript show: '--sender-->', (fc sender) class name, '(', (fc sender) identityHash asString,')'. <br> Transcript show: '--home-->', (fc home) class name, '(', (fc home) identityHash asString,')'; cr. <br>Transcript show: '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^';cr. <br> <br>thisContext inspect.<br>factorial inspect.<br>fc inspect.<br>(1 to: 3) collect: fc</div></blockquote> <br><br><br>The Transcript output is as follows:<br><br><blockquote style="border:1px solid rgb(204,204,204);padding:7px;background-color:rgb(245,245,245)"> <div><br> factorial = BlockContext(694)--sender-->UndefinedObject(3840)--home-->MethodContext(2677)<br>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br> fc = BlockContext(3934)--sender-->UndefinedObject(3840)--home-->MethodContext(2677)<br> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br> n=1 BlockContext(3934)--sender-->MethodContext(2367)--home-->MethodContext(2677)<br>++++++++++++++++++++++++++++++++++++++++<br>-----------------------------------------------<br> n=2 BlockContext(3934)--sender-->MethodContext(2367)--home-->MethodContext(2677)<br> n=1 BlockContext(1198)--sender-->BlockContext(3934)--home-->MethodContext(2677)<br>++++++++++++++++++++++++++++++++++++++++<br> -----------------------------------------------<br> n=3 BlockContext(3934)--sender-->MethodContext(2367)--home-->MethodContext(2677)<br>-----------------------------------------------<br> n=2 BlockContext(1684)--sender-->BlockContext(3934)--home-->MethodContext(2677)<br> n=1 BlockContext(2780)--sender-->BlockContext(1684)--home-->MethodContext(2677)<br>++++++++++++++++++++++++++++++++++++++++</div></blockquote> <br><br><a href="http://www.mirandabanda.org/cogblog/category/cog/page/14/" target="_blank"></a><br> Look at the 3'rd line, where n=1. <br>Why is the sender-->MethodContext(2367) instead of sender-->MethodContext(2677)<br>What created that new MethodContext?<br></div></div></blockquote><div><br></div><div>That would be the activation of Interval>>collect:, which performs the first call of the copied factorial block for each 1 through 3.</div> <div><br></div><div>collect: aBlock</div><div><span style="white-space:pre">        </span>| nextValue result |</div><div><span style="white-space:pre">        </span>result := self species new: self size.</div><div><span style="white-space:pre">        </span>nextValue := start.</div> <div><span style="white-space:pre">        </span>1 to: result size do:</div><div><span style="white-space:pre">                </span>[:i |</div><div><span style="white-space:pre">                </span>result at: i put: (<b><u>aBlock value: nextValue</u></b>).</div> <div><span style="white-space:pre">                </span>nextValue := nextValue + step].</div><div><span style="white-space:pre">        </span>^ result </div></div><br></div></div> </blockquote><br></div></body></html>