[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LOGO-L> Word Sculpturing



RAY CATZEL wrote:

> to main
> newtext "text1 [-300 200] [400 400]    ;establishes text box. You can draw this manually instead, if you wish.
> top ct
> question [Give me a word ==> ]
> sculpture answer
> end
> 
> to sculpture :wrd
> if 1 = count :wrd[pr :wrd stopme]
> pr :wrd
> sculpture bl :wrd
> pr :wrd
> end
> 
> My result looked as follows:
> 
> yahuda
> yahud
> yahu
> yah
> ya
> y
> 
> To repeat the procedure you will have to remove the text box manually or use the command REMOVE "text1.

Add: carefully [remove "text1 ] [] , before the "newtext". Then if the
textbox exists it will be removed.  If it doesn't exist no error message
will be printed. Either way the newtext can then create the textbox. See
the microworlds vocabulary help pages for CAREFULLY.

> When I used STOP instead of STOPME, the following was produced:
> yahuda
> yahud
> yahu
> yah
> ya
> y
> ya
> yah
> yahu
> yahud
> yahuda
> 
> I don't understand why.  Can someone please explain this.
> 
> Ray Catzel
> 

Before we can understand  why STOP and STOPME behave differenrly here we
need to think about recursion and the sculpture routine.  

In sculpture you have three places where the procedure can print. In the
conditional, before the recursive call to sculpture and after the
recursive call. So what's happening? Let's say sculpture is called with
the word "cat".  The "cat" will print via the PRINT before the recursive
call. Now sculpture is called with "ca". The "ca" will print, again via
the PRINT before the recursive call. Now sculpture is called with a "c".
The condition is satisfied and the "c" is printed via the PRINT in the
conditional.

Now if the next instruction is STOPME the PROCESS is stopped.
Microworlds returns to the top level no other code in your program is
executed.  (You can see this by placing a: PRINT "DONE after the call to
sculpture in main. When STOPME is used this PRINT  never prints showing
that you never returned to main.)

If the next instruction is STOP only the PROCEDURE running is stopped.
The running procedure is the recursively called sculpture. It returns to
the sculpture which called it.  The PRINT after the call is executed,
then it returns and so on. Finally we'll return to main. (Again if you
have placed a PRINT "DONE after the call to sculptue in main now you
will see DONE printed in text1.)

If you remove the third PRINT you can replace the STOPME with a STOP. I
beleive this is "more correct" for what you are trying to do. 

Hope this helps.  I've always found explaining recursion to be a real
pain in the neck. Its best to play around with recursive routines using
simple arguments and printing out the results at each level.

regards
-- 
Frank Caggiano
caggiano@atlantic.net
http://www.atlantic.net/~caggiano
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home