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.