LOGO-L> Word Sculpturing 
Author Message
 LOGO-L> Word Sculpturing

Hello Jim,

I don't know if you have the following program in your arsenal:

=============================
to main
ct ts
type "|Give me a word ==> |
sculpture rw
end

to sculpture :wrd
if 1=count :wrd[pr :wrd stop]
pr :wrd
sculpture bl :wrd
pr :wrd
end
=============================

Enjoy. D you need other sculptures of similar nature?

Regards...

[[Yehuda]]

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





Sat, 04 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Hi Yehuda,
Thanks for your fun word manipulation exersize.  I have translated it for MicroWorlds2 (Win95) as follows:

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.
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

Quote:
-----Original Message-----

Sent:   Tuesday, June 17, 1997 3:41 PM
To:     Jim Muller

Cc:     Logo-L
Subject:        LOGO-L> Word Sculpturing

Hello Jim,

I don't know if you have the following program in your arsenal:

=============================
to main
ct ts
type "|Give me a word ==> |
sculpture rw
end

to sculpture :wrd
if 1=count :wrd[pr :wrd stop]
pr :wrd
sculpture bl :wrd
pr :wrd
end
=============================

Enjoy. D you need other sculptures of similar nature?

Regards...

[[Yehuda]]

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



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






Sun, 05 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Quote:

> 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.

- Show quoted text -

Quote:
> 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

http://www.atlantic.net/~caggiano
---------------------------------------------------------------





Sun, 05 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Hi Frank,
Thanks for your explanation.  I'm getting there - but not quite.  I will list the procedure, then the output, then my question:

to main
carefully [remove "text1 ] [] newtext "text1 [-300 200] [400 400]  
top ct
question [Give me a word ==> ]
sculpture answer
end

to sculpture :wrd
if 1 = count :wrd[pr :wrd stop]
pr :wrd
sculpture bl :wrd
pr :wrd
end

Now the result:

caggiano
caggian
caggia
caggi
cagg
cag
ca
c
ca
cag
cagg
caggi
caggia
caggian
caggiano

Now my question: I understand how the word gradually gets truncated by one letter at a time.  I do not understand how it "grows" again.  Which instructions are causing it to add one letter at a time after "caggiano" is reduced to "c".

Ray Catzel
President  ComputerPals

Internet:  http://www.computerpals.on.ca/~pals

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





Sun, 05 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Frank Caggiano wrote (good stuff skipped):

Quote:

> Before we can understand why STOP and STOPME behave differenrly here...

I understand that STOPME in MW is the same as THROW "TOPLEVEL in
UCBLogo.
As a rule of thumb I would refrain from using that command in other than
emergency, as it results in a drastic intervention in the flow of the
program. Its use might be a sign of poor programming style.

Quote:
> If the next instruction is STOP only the PROCEDURE running is stopped.

True. Understanding STOP in Logo is not so trivial (mainly for those who
have experienced BASIC).

Regards...

[[Yehuda]]

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





Sun, 05 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Quote:

> Hi Frank,
> Thanks for your explanation.  I'm getting there - but not quite.  I will list the procedure, then the output, then my question:

> to main
> carefully [remove "text1 ] [] newtext "text1 [-300 200] [400 400]
> top ct
> question [Give me a word ==> ]
> sculpture answer
> end

> to sculpture :wrd
> if 1 = count :wrd[pr :wrd stop]
> pr :wrd
> sculpture bl :wrd
> pr :wrd
> end

> Now the result:

> caggiano
> caggian
> caggia
> caggi
> cagg
> cag
> ca
> c
> ca
> cag
> cagg
> caggi
> caggia
> caggian
> caggiano

> Now my question: I understand how the word gradually gets truncated by one letter at a time.  I do not > understand how it "grows" again.  Which instructions are causing it to add one letter at a time after
> "caggiano" >is reduced to "c".

Ahh, where's a white board when you need one :-)

A good question and with your question we see the root of the problem.
The word "caggiano" passed to the first call of sculpture never shrinks
or grows. Sculpture is called repeatedly. Each time the line "sculpture
bl :wrd" is executed a new instance of the sculpture routine is started.
The argument it receives IS truncated (via the BL) but this operation in
no way affects the contents of :wrd in the calling procedure.

Are you familiar with the gizmo used in cafeterias to dispense trays? As
you take one off the top the one under pops up to take its place. And
when you put trays back in they push down the trays already there. This
is a stack. Things added to the stack "push" down the things already on
the stack so that the first thing in is at the bottom.  As you remove
things you "pop" them off the top of the stack until you reach that
first item. (Push and pop are the two basic actions performed on a
stack. Push adds the thing to the top of the stack; pop removes the
thing at the top of the stack).

So why all this talk of cafeteria trays and stacks.  Recursion behaves
in the same way. Think of sculpture as a tray. When main calls sculpture
a "tray" is pushed onto the stack and its instructions begin executing.
Lets say we call it with "cat" as the argument. (Like I said I find it
easier to trace these things through with small arguments, makes
tracking it easier).  The conditional doesn't fire. We print "cat". We
call sculpture with "ca".  Ahh,  we need a new sculpture tray.  We get
one, give it "ca" as it argument and push it on the stack. Again the
conditional doesn't fire. We print "ca". We call sculpture "c".  Ahh,
again we need a new sculpture tray. It's pushed onto the stack with "c"
as the argument.

Ok, were are we?  We have three sculpture trays on the stack. We just
called the last one (The one at the top of the stack) with "c". Now the
conditional fires.  We print the "c" and STOP. The stop causes this
procedure to immediately return so we pop it off the stack and give it
the heave-ho.  Now what's on the top of the stack?  The sculpture "tray"
with the argument "ca". When we return to this "tray" we just continue
executing at the next instruction after the call. What is it? It's the
third print. So we print "ca" (again). We then fall off the end of the
procedure. We pop this one off the stack.  Again we have a sculpture
"tray" waiting. So we resume executing its instructions. We print "cat"
(again with the print AFTER the call to sculpture). We fall of the end
of this one, pop it and loose it.  Now where are we?  (At the end of the
line, "I'll have the Jell-O and mashed potatoes, thanks).  Now we have a
main "tray" (It was pushed on the stack when we began execution). We
continue execution after the call to sculpture and when we fall off the
end of main we're back at the top level.

Now you can also see why if we replace the STOP with the STOPME we only
get the word decreasing.  Once the STOPME in the third instance of
sculpture is executed no other instructions in this program execute.

It will help a lot if you take a pencil and paper and write down the
calls and arguments as you work through this. Recursion is wonderful,
great, powerful, elegant and a real show stopper. Plus you can dazzle
your friends and co-workers. (I keep hearing the genie from Aladdin
speaking these lines). But it ain't easy (at least at first). It's a
very different way to think about problems and their solutions.  You may
want to check out one of the many books mentioned here for a more
detailed explanation and for some examples and problems to work out.

I hope this helps and didn't make the waters muddier, regards.
--
Frank Caggiano

http://www.atlantic.net/~caggiano
---------------------------------------------------------------





Mon, 06 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Quote:


> > to main
> > carefully [remove "text1 ] [] newtext "text1 [-300 200] [400 400]
> > top ct
> > question [Give me a word ==> ]
> > sculpture answer
> > end

> > to sculpture :wrd
> > if 1 = count :wrd[pr :wrd stop]
> > pr :wrd
> > sculpture bl :wrd
> > pr :wrd
> > end
> Ahh, where's a white board when you need one :-)

> A good question and with your question we see the root of the problem.
> The word "caggiano" passed to the first call of sculpture never shrinks
> or grows. Sculpture is called repeatedly. Each time the line "sculpture
> bl :wrd" is executed a new instance of the sculpture routine is started.
> The argument it receives IS truncated (via the BL) but this operation in
> no way affects the contents of :wrd in the calling procedure.

> Are you familiar with the gizmo used in cafeterias to dispense trays? As
> you take one off the top the one under pops up to take its place. And
> when you put trays back in they push down the trays already there. This
> is a stack. Things added to the stack "push" down the things already on
> the stack so that the first thing in is at the bottom.  As you remove
> things you "pop" them off the top of the stack until you reach that
> first item. (Push and pop are the two basic actions performed on a
> stack. Push adds the thing to the top of the stack; pop removes the
> thing at the top of the stack).

> So why all this talk of cafeteria trays and stacks.  Recursion behaves
> in the same way. Think of sculpture as a tray. When main calls sculpture
> a "tray" is pushed onto the stack and its instructions begin executing.
> Lets say we call it with "cat" as the argument. (Like I said I find it
> easier to trace these things through with small arguments, makes
> tracking it easier).  The conditional doesn't fire. We print "cat". We
> call sculpture with "ca".  Ahh,  we need a new sculpture tray.  We get
> one, give it "ca" as it argument and push it on the stack. Again the
> conditional doesn't fire. We print "ca". We call sculpture "c".  Ahh,
> again we need a new sculpture tray. It's pushed onto the stack with "c"
> as the argument.

> Ok, were are we?  We have three sculpture trays on the stack. We just
> called the last one (The one at the top of the stack) with "c". Now the
> conditional fires.  We print the "c" and STOP. The stop causes this
> procedure to immediately return so we pop it off the stack and give it
> the heave-ho.  Now what's on the top of the stack?  The sculpture "tray"
> with the argument "ca". When we return to this "tray" we just continue
> executing at the next instruction after the call. What is it? It's the
> third print. So we print "ca" (again). We then fall off the end of the
> procedure. We pop this one off the stack.  Again we have a sculpture
> "tray" waiting. So we resume executing its instructions. We print "cat"
> (again with the print AFTER the call to sculpture). We fall of the end
> of this one, pop it and loose it.  Now where are we?  (At the end of the
> line, "I'll have the Jell-O and mashed potatoes, thanks).  Now we have a
> main "tray" (It was pushed on the stack when we began execution). We
> continue execution after the call to sculpture and when we fall off the
> end of main we're back at the top level.

> Now you can also see why if we replace the STOP with the STOPME we only
> get the word decreasing.  Once the STOPME in the third instance of
> sculpture is executed no other instructions in this program execute.

> It will help a lot if you take a pencil and paper and write down the
> calls and arguments as you work through this. Recursion is wonderful,
> great, powerful, elegant and a real show stopper. Plus you can dazzle
> your friends and co-workers. (I keep hearing the genie from Aladdin
> speaking these lines). But it ain't easy (at least at first). It's a
> very different way to think about problems and their solutions.  You may
> want to check out one of the many books mentioned here for a more
> detailed explanation and for some examples and problems to work out.

> I hope this helps and didn't make the waters muddier, regards.

Hello Ray,

You might want to test yourself with the following: Change in SCULPTURE
the last PR :WRD by PR "RAY. Now, if you run MAIN with "jerusalem" as
ANSWER (don't run it yet), how many times will you have RAY printed on
screen?
Now run it and check if you answered correctly.

I think that Frank made a good and clear job in his above answer.

The (not easy) idea of recursion takes considerable place in the first
volume of Harvey's "Computer Sceince Logo Style". I warmly recommend it.

Regards...

[[Yehuda]]

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





Mon, 06 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing


Quote:
>I understand that STOPME in MW is the same as THROW "TOPLEVEL in
>UCBLogo.
>As a rule of thumb I would refrain from using that command in other than
>emergency, as it results in a drastic intervention in the flow of the
>program. Its use might be a sign of poor programming style.

In MicroWorlds one can have several processes executed in parallel. To halt
a process you use STOPME. In the particular example of the "sculpture"
procedure, since you have only one process running (the one where the
sculpture procedure gets executed) "STOPME" is equivalent to:
        THROW "TOPLEVEL

In MicroWorlds there are many situations, like a process monitoring the
behaviour of other processes, where STOPME is indeed usefull and needed.

/// Dr. Augusto Chioccariello                  tel: +39 10 6475319
/// Istituto Tecnologie Didattiche - CNR       fax: +39 10 6475300

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





Mon, 06 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

 Recursion is wonderful,
great, powerful, elegant and a real show stopper. Plus you can dazzle
your friends and co-workers. (I keep hearing the genie from Aladdin
speaking these lines). But it ain't easy (at least at first). It's a
very different way to think about problems and their solutions.  You may
want to check out one of the many books mentioned here for a more
detailed explanation and for some examples and problems to work out.

I hope this helps and didn't make the waters muddier, regards.
--
Frank Caggiano

http://www.atlantic.net/~caggiano

[RAY CATZEL]  Thanks Frank, you are a great teacher. Your enthusiasm for the subject forced me to work through the complex logic. I think I do understand it. It is certainly not intuitive - it requires a clear understanding of how recursion uses stacks.
One thing I have decided: it is not for younger kids. I try to push my students (all < 14 years old) as far as possible, but I think I might find it difficult to engage them in stack operation. Mind you, I have a couple of really smart kids who this might appeal to. So maybe I'll play it by ear.........
Thank you once again for a great explanation of recursion and stack operation.
---------------------------------------------------------------





Mon, 06 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Quote:

>I think I do understand it. It is certainly not intuitive - it requires a
>clear understanding of how recursion uses stacks.  One thing I have decided:
>it is not for younger kids. I try to push my students (all < 14 years old)
>as far as possible, but I think I might find it difficult to engage them in
>stack operation. Mind you, I have a couple of really smart kids who this
>might appeal to. So maybe I'll play it by ear.........  Thank you once again
>for a great explanation of recursion and stack operation.

I don't think I'd talk about stacks in explaining recursion, especially
to kids.  Back in the old days at the MIT Logo Lab everyone assumed you
could get eight-year-olds to understand recursion, using the following
model:

Inside the computer are a bunch of little people, each of whom is a specialist
in some particular procedure.  So, for example, there are FIRST specialists
and PRINT specialists.  When you want to invoke a procedure, you hire one of
these little people, and give him/her a piece of paper for each input, on
which you've written the value for that input in this invocation.  Each
little person has as many pockets as that procedure requires inputs, so
for example the FIRST people have one pocket each, but the SENTENCE ones
have two pockets each.

Procedures that you write are also carried out by little people.  So if we
have a procedure like this:

        to foo :word
        ...
        foo butlast :word
        ...
        end

and we want to compute FOO "HELLO we hire Fred, a foo specialist, and we
give him the word HELLO to put in his pocket.  Fred goes through the
instructions in FOO, one by one, hiring other little people as needed.
When he gets to the FOO BUTLAST :WORD he first hires Bob, a butlast
specialist, with HELLO as his input.  Bob gives him back the word HELL
as his output.  Fred now hires Francine, *another* foo specialist, and
gives her HELL as her input.  And so on.

At all times, Fred's input has the value HELLO.  At all times, Francine's
input has the value HELL.  Nothing ever *changes* in value.

It's helpful to actually act this out with kids as the little people.



Mon, 06 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Ray ==>

Here's a couple of word sculpturing procedures that demonstrate tail-end
and embedded recursion.

Tail-end
========

TO WORDTRIANGLE :WORDS
IF :WORDS = " [STOP]
PR :WORDS
WORDTRIANGLE BUTFIRST :WORDS
END

EMBEDDED
========

TO WORDTRIANGLE :WORDS
IF :WORDS = " [STOP]
WORDTRIANGLE BUTFIRST :WORDS
PR :WORDS
END

There's just one problem. The second procedure starts printing the last
letter and then adds letters until :WORDS is printed.

A challenge for you...
======================

Write a procedure that makes the same shape of triangle but starts with the
first letter, then the first and second, first three, etc.

Something else to think about.

Regards...Jim

PS:  How about a rectangle?  Of variable size?

Quote:
>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>

Jim Muller

The Great Logo Adventure at
http://www.{*filter*}ramp.net/~jmul
Quote:
>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>

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





Mon, 06 Dec 1999 03:00:00 GMT  
 LOGO-L> Word Sculpturing

Quote:

> In MicroWorlds one can have several processes executed in parallel. To halt
> a process you use STOPME. In the particular example of the "sculpture"
> procedure, since you have only one process running (the one where the
> sculpture procedure gets executed) "STOPME" is equivalent to:
>         THROW "TOPLEVEL

> In MicroWorlds there are many situations, like a process monitoring the
> behaviour of other processes, where STOPME is indeed usefull and needed.

Hello Augusto,

I know absolutely nothing about MicroWorlds, so sorry for asking what
might be trivial for you:

I don't understand what you mean by "process". Do you mean "procedure"?

You say that MW runs paralelly several "processes". How is it that done
on a single-processor computer?

Do you think that in MW, STOPME is an essential command and normally one
can't do without it?

Thank you in advance,

[[Yehuda]]

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





Mon, 06 Dec 1999 03:00:00 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. LOGO-L> Number Sculpturing

2. LOGO-L> Logo 15-Word Challenge Update

3. LOGO-L> Logo 15-Word Challange Update

4. LOGO-L> Re: Logo 15-Word Challenge

5. LOGO-L> Logo 15-Word Challenge

6. LOGO-L> Logo 15-word challenge update

7. LOGO-L> Logo 15-Word Challenge Update

8. LOGO-L> Logo 15-Word Challenge Update

9. LOGO-L> More word-shuffling

10. LOGO-L> Another Word scuplturing

11. LOGO-L> Shuffling words and privacy

12. LOGO-L> Shuffling words

 

 
Powered by phpBB® Forum Software