[MWForum]curious language

Jeff Knope mwforum@lists.mathcats.com
Wed, 16 Mar 2005 10:35:36 -0800


This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C52A13.E3D1CD50
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 =3D 0) is true; the other what to do if the condition =
is false.  It should read:

        ifelse :n =3D 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:
       =20
        ifelse :n =3D 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 =3D 0.  The procedure stops when :n =3D 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 -----=20
From: <jbonnes@libertyschool.us>
To: <mwforum@lists.mathcats.com>
Sent: Wednesday, March 16, 2005 8:18 AM
Subject: [MWForum]curious language


>=20
> 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 =3D 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
>=20
>=20
> _______________________________________________
> MWForum mailing list
> MWForum@lists.mathcats.com
> http://lists.mathcats.com/mailman/listinfo/mwforum
> Attachments archived at:
> http://www.mathcats.com/mwforum/attachments.html
> To unsubscribe or for administrative questions contact=20
> mailto:mwforum-admin@lists.mathcats.com
>
------=_NextPart_000_001B_01C52A13.E3D1CD50
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2604" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi Jim,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I would say Mr. Papert's procedure is =
somewhat=20
curious.&nbsp; But we can use it to answer your question of how the =
program=20
stops.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>First, there are some sytax errors that =
have to be=20
fixed:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>There is a missing opening bracket in =
the "ifelse"=20
statement. An "ifelse" must be followed&nbsp;by two lists. One that =
tells it=20
what to do if the condition (:n =3D 0)&nbsp;is true; the other what to =
do if the=20
condition is false.&nbsp; It should read:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
ifelse :n =3D 0=20
[fd :x]<STRONG><FONT color=3D#ff0000>[</FONT></STRONG>repeat 4 [ el :x / =
3 (:n -=20
1) rt 90]]</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Note also the added spaces in the =
(:n-1)=20
expression.&nbsp; These spaces are required.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Now, to help make visible what is =
happening, I=20
suggest the following:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; A. Add to this line =
instructions=20
to print the values of :x and :n in the control console at each =
iteration, as=20
follows:</FONT></DIV>
<DIV><FONT size=3D2><FONT =
face=3DArial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; ifelse=20
:n =3D 0 [fd :x][repeat 4 [ el :x / 3 (:n - 1) <FONT =
color=3D#ff0000><STRONG>show :x=20
show :n</STRONG></FONT> rt 90]]</FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT face=3DArial>&nbsp;&nbsp;&nbsp; B. Go to the =
Processes=20
Tab, and click the&nbsp;yellow "speed" button.&nbsp; This will slow down =
the=20
running so you can watch the turtle's behavior.</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; C. Issue the =
commands,=20
<STRONG>cg st pd </STRONG>&lt;ret&gt;.&nbsp; This clears the graphics =
screen,=20
shows the turtle, and puts the pen down.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Now issue <STRONG>el 500 3 =
</STRONG>&lt;ret&gt; and=20
watch the procedure run in slow-motion.&nbsp; Review the outputs in the =
control=20
console.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Basically, the procedure is in the =
"repeat"=20
statement (the "else" of the&nbsp;"ifelse")&nbsp;until :n =3D 0.&nbsp; =
The=20
procedure stops when :n =3D 0 because at that point the instruction is =
to simply=20
<STRONG>fd :x</STRONG> and the entire&nbsp;"ifelse" is =
satisfied.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I hope this helps.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Jeff</FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><BR></FONT></DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>----- Original Message ----- </FONT>
<DIV><FONT face=3DArial size=3D2>From: &lt;</FONT><A=20
href=3D"mailto:jbonnes@libertyschool.us"><FONT face=3DArial=20
size=3D2>jbonnes@libertyschool.us</FONT></A><FONT face=3DArial=20
size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>To: &lt;</FONT><A=20
href=3D"mailto:mwforum@lists.mathcats.com"><FONT face=3DArial=20
size=3D2>mwforum@lists.mathcats.com</FONT></A><FONT face=3DArial=20
size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Sent: Wednesday, March 16, 2005 8:18=20
AM</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Subject: [MWForum]curious=20
language</FONT></DIV></DIV>
<DIV><FONT face=3DArial><BR><FONT size=3D2></FONT></FONT></DIV><FONT =
face=3DArial=20
size=3D2>&gt; <BR>&gt; Thanks Everyone,<BR>&gt; I also just learned that =
Logo=20
programs can call themselves, Seymour Papert just<BR>&gt; gave me this =
program=20
and now I'm trying to understand it.<BR>&gt; to el :x :n<BR>&gt; ifelse =
:n =3D 0=20
[fd :x]<BR>&gt; repeat 4 [ el :x / 3 (:n-1) rt 90]]<BR>&gt; end<BR>&gt; =
It=20
doesn't do what I want it to, but to me this is intriguing because=20
coming<BR>&gt; from C a program can't call itself. I'v been trying to =
figure=20
what's going on.<BR>&gt; The program draws a square and then fills it up =
with=20
four more squares, if you<BR>&gt; input :n as 2. How does the program=20
stop.<BR>&gt; Jim Bonnes<BR>&gt; <BR>&gt; <BR>&gt;=20
_______________________________________________<BR>&gt; MWForum mailing=20
list<BR>&gt; </FONT><A href=3D"mailto:MWForum@lists.mathcats.com"><FONT =
face=3DArial=20
size=3D2>MWForum@lists.mathcats.com</FONT></A><BR><FONT face=3DArial =
size=3D2>&gt;=20
</FONT><A =
href=3D"http://lists.mathcats.com/mailman/listinfo/mwforum"><FONT=20
face=3DArial=20
size=3D2>http://lists.mathcats.com/mailman/listinfo/mwforum</FONT></A><BR=
><FONT=20
face=3DArial size=3D2>&gt; Attachments archived at:<BR>&gt; </FONT><A=20
href=3D"http://www.mathcats.com/mwforum/attachments.html"><FONT =
face=3DArial=20
size=3D2>http://www.mathcats.com/mwforum/attachments.html</FONT></A><BR><=
FONT=20
face=3DArial size=3D2>&gt; To unsubscribe or for administrative =
questions contact=20
<BR>&gt; </FONT><A =
href=3D"mailto:mwforum-admin@lists.mathcats.com"><FONT=20
face=3DArial =
size=3D2>mailto:mwforum-admin@lists.mathcats.com</FONT></A><BR><FONT=20
face=3DArial size=3D2>&gt;</FONT></BODY></HTML>

------=_NextPart_000_001B_01C52A13.E3D1CD50--