[Q] recursion

David Faught dave.faught at gmail.com
Sat Nov 25 14:14:28 UTC 2006


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