Hi, Phil,
In this example, the approachBlue script is not *ticking* -- it is just run once per star, and the result -- until termination -- is the birth of a new star a bit to the right of the star, which is then told to run -- again *once* -- its approachBlue script.
This continues until one of the newborn stars finally hits blue, in which case it does *not* follow the NO branch and hence does not make a fresh copy -- so that's how things terminate.
(This is actually not true recursion, which, I think, would be when a script in an object calls the same script in that *same* object. But it's something close.)
In Squeak, we would normally do this example using a ticking script, as you suggest, without the recursion. If at each step the star used "stamp", the trail would end up with the same appearance as Kevin wanted, but all done using a single star rather than a whole series of them.
But I think Kevin wanted to try it the way he did just to explore the possibilities of recursion in Squeak.
Cheers,
-- Scott
At 8:22 AM -0500 3/28/05, Phil Firsenbaum wrote:
Interesting, Scott, however, I don't see what would stop apporachBlue script if nothing is in the Yes "fork."
Also, my experience with recursion was basically from my work with Logo, where I had to call a procedure (within itself) for that procedure to be recursive. Since a ticking Squeak script keeps calling itself why was it even necessary for you to add the "do approachBlue" (recursive call) to your version of the script?
Phil
On Mar 28, 2005, at 2:15 AM, Scott Wallace wrote:
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:
<image.tiff> 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 !
<P5E04C520>_______________________________________________ Squeakland mailing list Squeakland@squeakland.org http://squeakland.org/mailman/listinfo/squeakland