Hi Klaus and Stéphane,
Thank you both for your help. It looks like #clone is indeed faster and will work okay for copying a block like this, as there is no reason to worry about instance variables.
My recursive turtle thanks you too! Dave
Stéphane Rollandin wrote:
there is also #clone, which seems faster on my computer:
fact _ [:n | n isZero ifTrue: [1] ifFalse: [n * (fact copy value: (n - 1))]].
[fact copy value: 6] bench ==> '157928.2143571286 per second.'
fact _ [:n | n isZero ifTrue: [1] ifFalse: [n * (fact clone value: (n - 1))]].
[fact clone value: 6] bench ==> '208975.4049190162 per second.'
Klaus D. Witzel wrote:
Hi David, try this:
| spiral | self vi:1. self r: 0.0 g: 0.8 b: 0.0. self lw: 1. spiral := [ :size :angle | (size < 100) ifTrue: [ self fo: size. self tr: angle. spiral copy value: size + 2 value: angle. ]. ]. spiral copy value: 0 value: 91.
Indeed, if you don't make a copy of a recursing block, it is (as the error message says) already being evaluated. But not so the copy. Note that every #value:value: needs its own copy.
Here is a small screenshot of a slight variation of this spiral. I hope nobody minds on the list. I tried to keep it small but I don't know if the list manager will forward the attachment.
On 11/26/06, David Faught dave.faught@gmail.com wrote:
Hi Klaus and Stéphane,
Thank you both for your help. It looks like #clone is indeed faster and will work okay for copying a block like this, as there is no reason to worry about instance variables.
My recursive turtle thanks you too!
Very cute screenshot, David!
It reminds me of AquaMOOSE 3D, a research project at Georgia Tech.
http://www-static.cc.gatech.edu/elc/aquamoose/
Josh
On Nov 26, 2006, at 11:33 AM, David Faught wrote:
Here is a small screenshot of a slight variation of this spiral. I hope nobody minds on the list. I tried to keep it small but I don't know if the list manager will forward the attachment.
On 11/26/06, David Faught dave.faught@gmail.com wrote:
Hi Klaus and Stéphane,
Thank you both for your help. It looks like #clone is indeed faster and will work okay for copying a block like this, as there is no reason to worry about instance variables.
My recursive turtle thanks you too! <ScreenShot008s.PNG>
squeak-dev@lists.squeakfoundation.org