Hi Folks --

This brings up an interesting pedagogical question about recursion and objects.

Smalltalk (and hence Squeak) has full capabilities for recursion, and etoys could (and maybe should) also.

On the other hand, let's take an example, such as drawing/building a tree shape. A LOGO-like recursive approach would be to make a procedure that draws a V shape, and then write a recursive procedure that invokes this V at different sizes and angles to draw the tree.

Another, more object oriented, approach that is a little more biological is to make a branch object with a non-looping method that creates sprouting further branches (copies of itself) of the tree and gives them "life" to create limbs of their own using the sprouting method. This is much simpler to think about and do, it actually creates a tree of branch objects, and the technique generalizes much better to massively parallel structures that are more complicated than simple nested structures.

The interesting dualism here was noted when objects where invented, that because objects have a full copy of state (whereas procedures don't), there often no good reason for using an invisible stack of contexts where a visible collection of objects would better serve ....

Not that there aren't some nice and neat things that can be done with recursion, but it seems to me, where kids are concerned, there should be big payoffs for each concept that is trying to find a place in the kids' 7+-2 chunks used to think with -- and recursion doesn't make the initial cut in my opinion.

Cheers,

Alan



At 11:15 PM 3/27/2005, 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:

6ab46315.jpg

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 !


_______________________________________________
Squeakland mailing list
Squeakland@squeakland.org
http://squeakland.org/mailman/listinfo/squeakland