that uses "factorial copy" for the recursion.
into something I could trace out a bit easier.
| factorial fc |
Transcript clear.
factorial := [:n |
n = 1
ifTrue:[
Transcript show: ' n=', (n asString),' ', (thisContext class name), '(', (thisContext identityHash asString),')' .
Transcript show: '--sender-->', (thisContext sender) class name, '(', (thisContext sender) identityHash asString,')'.
Transcript show: '--home-->', (thisContext home) class name, '(', (thisContext home) identityHash asString,')'; cr.
Transcript show: '++++++++++++++++++++++++++++++++++++++++';cr.
"thisContext explore. "
1
]
ifFalse:[ Transcript show: '-----------------------------------------------';cr.
Transcript show: ' n=', (n asString),' ', (thisContext class name), '(', (thisContext identityHash asString),')' .
Transcript show: '--sender-->', (thisContext sender) class name, '(', (thisContext sender) identityHash asString,')'.
Transcript show: '--home-->', (thisContext home) class name, '(', (thisContext home) identityHash asString,')'; cr.
(factorial copy value: n-1) * n
]].
Transcript show:' factorial = ' , (factorial class name),'(',factorial identityHash asString,')'.
Transcript show: '--sender-->', (factorial sender) class name, '(', (factorial sender) identityHash asString,')'.
Transcript show: '--home-->', (factorial home) class name, '(', (factorial home) identityHash asString,')'; cr.
Transcript show: '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^';cr.
fc := factorial copy .
Transcript show:' fc = ' , (fc class name),'(',fc identityHash asString,')'.
Transcript show: '--sender-->', (fc sender) class name, '(', (fc sender) identityHash asString,')'.
Transcript show: '--home-->', (fc home) class name, '(', (fc home) identityHash asString,')'; cr.
Transcript show: '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^';cr.
thisContext inspect.
factorial inspect.
fc inspect.
(1 to: 3) collect: fc
Look at the 3'rd line, where n=1.
A screenshot of my Squeak 4.0 session is attached if the above gets mangled in posting this.
Thank you for your time.