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

Re: LOGO-L> Non-alterable file



Leen Vuyge wrote:
> 
> Hello,
> 
> I have this .txt file in which there is a LOGO program with not all
> procedures defined yet. The thing I have to do now is to define these
> procedures so that when someone loads the .txt file with my program, one
> can see the output of it all. No alterations may be made on the .txt file,
> though! Trouble is this doesn't work (yet)!
> In the .txt file, there is a line which says:
> while not westward turn_right
> When I have made the procedures westward and turn_right, the turtle must turn
> so that it is oriented to the west at the end. I have tried doing this by
> defining a variable "direction which is initialised at 0 since the turtle
> is always oriented to the north in the beginning. Other values for
> :direction are 1 (east), 2 (south) and 3 (west).
> My procedures are as follows:
> to turn_right
>   rt 90
>   make "direction :direction + 1
>   test 3 < :direction
>   iftrue make "direction :direction - 4
> end
> to westward
>   ifelse :direction = 3 [ op "true] [ op "false]
> end
> I keep getting this error message that "turn_right didn't output to while".
> Why doesn't this work and what can I change about it?
> 

You should specify which logo you use so that the most
familiar with your flavor can best help you. However, many
folks know many logo's.

to turn_right
  rt 90
  make "direction :direction + 1
  test 3 < :direction
  iftrue [make "direction :direction - 4]
end

You were missing []'s in iftrue expression above.
The code above would do 0,1,2,3,0,1,2,3
You did not say "0" was a legal direction.

to westward
  ifelse :direction = 3 [op "true] [op "false]
end

to xxx
  make "direction 1
  while [not westward] [turn_right]
end

You were missing []'s in the while expression above.
You need to tell logo what code you want to execute.
Some logo's may not require the []'s on the conditional
part.

Here is a slightly easier to read version of your
code that still does the same thing.

=============

to turn_right
  rt 90
  make "direction :direction + 1
  if :direction > 3 [make "direction 0]
end

If your going to immediately act on what you TEST
you might as well do it all at once with IF. TEST is
there to let you TEST in one place and act on that
TEST one or more times later on. However TESTing in one
place and acting on that test in another place is very
hard to follow your code (i.e which TEST did what).
If you want to save the result of a condition for later
testing you can save that in a variable.

make "test1 :a < :b
.
.
.
if :test1 [do something]

Now you can have several TEST's going without one
getting confused with another. The above, is all
TEST does but only allows a single TEST to be
outstanding at any given time.

to westward
  op :direction = 3
end

The result of a conditional expression can be output
directly just like any other data type.

to xxx
  make "direction 1
  while [not westward] [turn_right]
end

-- 
===============================================================
George Mills
email: mills@softronix.com
http://www.softronix.com
The www page contains some very powerful educational software.
Our single most important investment is our kids.

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