[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> </DIV>
<DIV><FONT face=3DArial size=3D2>I would say Mr. Papert's procedure is =
somewhat=20
curious. But we can use it to answer your question of how the =
program=20
stops.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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> </DIV>
<DIV><FONT face=3DArial size=3D2>There is a missing opening bracket in =
the "ifelse"=20
statement. An "ifelse" must be followed by two lists. One that =
tells it=20
what to do if the condition (:n =3D 0) is true; the other what to =
do if the=20
condition is false. It should read:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> =
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> </DIV>
<DIV><FONT face=3DArial size=3D2>Note also the added spaces in the =
(:n-1)=20
expression. These spaces are required.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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> </DIV>
<DIV><FONT face=3DArial size=3D2> 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> =20
</FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial> =
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> </DIV>
<DIV><FONT size=3D2><FONT face=3DArial> B. Go to the =
Processes=20
Tab, and click the yellow "speed" button. 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> </DIV>
<DIV><FONT face=3DArial size=3D2> C. Issue the =
commands,=20
<STRONG>cg st pd </STRONG><ret>. This clears the graphics =
screen,=20
shows the turtle, and puts the pen down.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Now issue <STRONG>el 500 3 =
</STRONG><ret> and=20
watch the procedure run in slow-motion. Review the outputs in the =
control=20
console.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Basically, the procedure is in the =
"repeat"=20
statement (the "else" of the "ifelse") until :n =3D 0. =
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 "ifelse" is =
satisfied.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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> </DIV>
<DIV><FONT face=3DArial><BR></FONT></DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>----- Original Message ----- </FONT>
<DIV><FONT face=3DArial size=3D2>From: <</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>></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>To: <</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>></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>> <BR>> Thanks Everyone,<BR>> I also just learned that =
Logo=20
programs can call themselves, Seymour Papert just<BR>> gave me this =
program=20
and now I'm trying to understand it.<BR>> to el :x :n<BR>> ifelse =
:n =3D 0=20
[fd :x]<BR>> repeat 4 [ el :x / 3 (:n-1) rt 90]]<BR>> end<BR>> =
It=20
doesn't do what I want it to, but to me this is intriguing because=20
coming<BR>> from C a program can't call itself. I'v been trying to =
figure=20
what's going on.<BR>> The program draws a square and then fills it up =
with=20
four more squares, if you<BR>> input :n as 2. How does the program=20
stop.<BR>> Jim Bonnes<BR>> <BR>> <BR>>=20
_______________________________________________<BR>> MWForum mailing=20
list<BR>> </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>>=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>> Attachments archived at:<BR>> </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>> To unsubscribe or for administrative =
questions contact=20
<BR>> </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>></FONT></BODY></HTML>
------=_NextPart_000_001B_01C52A13.E3D1CD50--