[Q] recursion
Klaus D. Witzel
klaus.witzel at cobss.com
Sat Nov 25 15:40:28 UTC 2006
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.
/Klaus
On Sat, 25 Nov 2006 15:14:28 +0100, David Faught wrote:
> I was thinking that something like this might work:
>
> | 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 value: size + 2 value: angle.
> ].
> ].
> spiral value: 0 value: 91.
>
> but it doesn't. When this code is run, there is an error that says
> something about trying to evaluate a block that is already being
> evaluated. So, I guess that recursion in this manner in this
> environment is not possible. Back to plain old loops ;-)
>
> On 11/24/06, David Faught <dave.faught at gmail.com> wrote:
>> This is really a Smalltalk/Squeak language question, although it may
>> not sound like it at first. There is a limited Squeak programming
>> environment in the MockTurtle turtle graphics package for Croquet,
>> essentially like a WorkSpace where the code is dynamically compiled
>> and executed like a DoIt, and not retained as a method in the turtle
>> class.
>>
>> Since many turtle graphics examples use recursion to do interesting
>> things, I'm wondering if there is a way to do recursion in this kind
>> of environment, maybe using named blocks?
>>
>> Thanks for any input you may have. Simple examples would be much
>> appreciated!
>>
>
>
More information about the Squeak-dev
mailing list
|