[Squeakland] Recursion supported in etoys script ?

Scott Wallace scott.wallace at squeakland.org
Sun Mar 27 23:15:46 PST 2005


Hi, all.  A question arose recently on the Squeak-dev mailing list (a 
list mostly inhabited by software engineers) concerning "recursion in 
etoys."  I wrote a reply, which I'm herewith forwarding to the 
Squeakland list, on the chance that this information might be useful 
to some readers.  BTW my reply was suppressed by the moderators of 
the Squeak-dev list, who said it was too large, so it never did 
actually appear on that list  ;-)

   -- Scott

------------------------------------------------------------------------------------

Hi, Kevin,

Yes, etoys do support recursion.  But they don't have a good way of 
detecting and recovering from *runaway* recursion, which is what was 
befalling your script.

Here's a recursive etoy script which does what you want, and which 
*does* converge, provided that there is a patch of the appropriate 
blue somewhere ahead of the Star:



Two points to note here:

(1)  The critical difference between this and what you did is that 
after the *copy* is made, this script "includes" that copy in the 
container.  Without the "include," the copy isn't present in the 
"world", so neither it nor any future generation of "copy" will be 
"over blue" and hence terminate the recursion.  That's why your 
recursion ran away.

(2)  In the last line, it's *okay* simply to have "Star's nextGuy 
approachBlue".  The value of the "do" inserted here is that this 
defers the recursive #approachBlue script call until the next cycle 
of the simulation.  The result will be there will be a sense of 
"movement" since each generation will be born on a different tick, 
whereas without the "do" all the generations will be born within the 
same "tick" so all will appear instantaneously -- a much less nice 
effect.

Cheers,

Scott


PS:  Please check out Squeakland.org, and you may well want to 
subscribe to the Squeakland mailing list:
	http://www.squeakland.org/mailman/listinfo/squeakland



At 10:08 AM -0800 3/25/05, Kevin Lawrence wrote:
>Is it appropriate to post questions about etoys to this list ?
>
>[I'll risk it this time - let me know if there is somewhere else I 
>should be asking, thanks.]
>
>
>I tried making a simple etoys script with recursion and it hangs as 
>soon as I click the run icon.
>
>the script was essentially (excuse my Java-ish pseudocode) ...
>
>
>spawn script
>  test self.sees blue
>
>  yes
>
>  no
>   self.newCopy = self.copy
>   self.newCopy.forwardBy self.length
>   self.newCopy.spawn
>
>
>Assuming I haven't made a really silly *mistake, should this work ?
>
>Is recursion supported ?
>
>(I searched the bug database but couldn't find anything)
>
>
>Thanks !
>
>Kevin
>
>* Please tell me if there is a silly mistake !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://squeakland.org/pipermail/squeakland/attachments/20050327/26280c8f/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: P5E04C520
Type: image/png
Size: 75570 bytes
Desc: not available
Url : http://squeakland.org/pipermail/squeakland/attachments/20050327/26280c8f/P5E04C520-0001.png


More information about the Squeakland mailing list