[Q] recursion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Q] recursion

David Faught
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.

Reply | Threaded
Open this post in threaded view
|

Re: [Q] recursion

David Faught
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 <[hidden email]> 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 (60K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Q] recursion

Joshua Gargus-2
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 <[hidden email]> 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>
>