Home
Project Folders
Teacher Resources
Student Resources
How Do I?
Literacy
MWForum
Site Map
Search
Our Team

MWForum Message [Date Index] [Threads] [Authors] [Attachments] [Subscribe]

[Thread Prev] [Thread Next]

Subject: curious language
From: mwforum@xxxxxxxxxxxxxxxxxx (Jeff Knope)
Date: Wed, 16 Mar 2005 10:35:36 -0800

Hi Jim,

I would say Mr. Papert's procedure is somewhat curious.  But we can use it to
answer your question of how the program stops.

First, there are some sytax errors that have to be fixed:

There is a missing opening bracket in the "ifelse" statement. An "ifelse" must
be followed by two lists. One that tells it what to do if the condition (:n
= 0) is true; the other what to do if the condition is false.  It should
read:

        ifelse :n = 0 [fd :x][repeat 4 [ el :x / 3 (:n - 1) rt 90]]

Note also the added spaces in the (:n-1) expression.  These spaces are
required.

Now, to help make visible what is happening, I suggest the following:

    A. Add to this line instructions to print the values of :x and :n in the
control console at each iteration, as follows:
        
        ifelse :n = 0 [fd :x][repeat 4 [ el :x / 3 (:n - 1) show :x show :n
rt 90]]

    B. Go to the Processes Tab, and click the yellow "speed" button.  This
will slow down the running so you can watch the turtle's behavior.

    C. Issue the commands, cg st pd <ret>.  This clears the graphics screen,
shows the turtle, and puts the pen down.

Now issue el 500 3 <ret> and watch the procedure run in slow-motion.  Review
the outputs in the control console.

Basically, the procedure is in the "repeat" statement (the "else" of the
"ifelse") until :n = 0.  The procedure stops when :n = 0 because at that
point the instruction is to simply fd :x and the entire "ifelse" is satisfied.

I hope this helps.
Jeff




----- Original Message ----- 
From: <jbonnes@xxxxxxxxxxxxxxxx>
To: <mwforum@xxxxxxxxxxxxxxxxxx>
Sent: Wednesday, March 16, 2005 8:18 AM
Subject: [MWForum]curious language


> 
> Thanks Everyone,
> I also just learned that Logo programs can call themselves, Seymour Papert
just
> gave me this program and now I'm trying to understand it.
> to el :x :n
> ifelse :n = 0 [fd :x]
> repeat 4 [ el :x / 3 (:n-1) rt 90]]
> end
> It doesn't do what I want it to, but to me this is intriguing because coming
> from C a program can't call itself. I'v been trying to figure what's going
on.
> The program draws a square and then fills it up with four more squares, if
you
> input :n as 2. How does the program stop.
> Jim Bonnes
> 
> 
> _______________________________________________
> MWForum mailing list
> MWForum@xxxxxxxxxxxxxxxxxx
> http://mia.openworldlearning.org/mwforum/
> Attachments archived at:
> http://www.mathcats.com/mwforum/attachments.html
> To unsubscribe or for administrative questions contact 
> mailto:mwforum-admin@xxxxxxxxxxxxxxxxxx
>
Hi Jim,
 
I would say Mr. Papert's procedure is somewhat curious.  But we can use it to answer your question of how the program stops.
 
First, there are some sytax errors that have to be fixed:
 
There is a missing opening bracket in the "ifelse" statement. An "ifelse" must be followed by two lists. One that tells it what to do if the condition (:n = 0) is true; the other what to do if the condition is false.  It should read:
 
        ifelse :n = 0 [fd :x][repeat 4 [ el :x / 3 (:n - 1) rt 90]]
 
Note also the added spaces in the (:n-1) _expression_.  These spaces are required.
 
Now, to help make visible what is happening, I suggest the following:
 
    A. Add to this line instructions to print the values of :x and :n in the control console at each iteration, as follows:
       
        ifelse :n = 0 [fd :x][repeat 4 [ el :x / 3 (:n - 1) show :x show :n rt 90]]
 
    B. Go to the Processes Tab, and click the yellow "speed" button.  This will slow down the running so you can watch the turtle's behavior.
 
    C. Issue the commands, cg st pd <ret>.  This clears the graphics screen, shows the turtle, and puts the pen down.
 
Now issue el 500 3 <ret> and watch the procedure run in slow-motion.  Review the outputs in the control console.
 
Basically, the procedure is in the "repeat" statement (the "else" of the "ifelse") until :n = 0.  The procedure stops when :n = 0 because at that point the instruction is to simply fd :x and the entire "ifelse" is satisfied.
 
I hope this helps.
Jeff
 

 
----- Original Message -----
Sent: Wednesday, March 16, 2005 8:18 AM
Subject: [MWForum]curious language

>
> Thanks Everyone,
> I also just learned that Logo programs can call themselves, Seymour Papert just
> gave me this program and now I'm trying to understand it.
> to el :x :n
> ifelse :n = 0 [fd :x]
> repeat 4 [ el :x / 3 (:n-1) rt 90]]
> end
> It doesn't do what I want it to, but to me this is intriguing because coming
> from C a program can't call itself. I'v been trying to figure what's going on.
> The program draws a square and then fills it up with four more squares, if you
> input :n as 2. How does the program stop.
> Jim Bonnes
>
>
> _______________________________________________
> MWForum mailing list
>
MWForum@xxxxxxxxxxxxxxxxxx
> http://mia.openworldlearning.org/mwforum/
> Attachments archived at:
>
http://www.mathcats.com/mwforum/attachments.html
> To unsubscribe or for administrative questions contact
>
mailto:mwforum-admin@xxxxxxxxxxxxxxxxxx
>
  • Previous by thread: curious language
  • Next by thread: curious language

  • To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.


    © copyright 2001 - 2008