home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 31
/
CDASC_31_1996_juillet_aout.iso
/
vrac
/
dflogo12.zip
/
LOGO.DOC
< prev
next >
Wrap
Text File
|
1996-04-19
|
26KB
|
684 lines
DFP LOGO
Version 1.2
Shareware notice:
DFP LOGO version 1.2 may be copied and distributed without charge, except the
cost of materials and handling, under the condition that the program and
accompanying documentation are not modified or changed in any way without the
written consent of the authors.
IF YOU WISH TO USE DFP LOGO YOU ARE REQUIRED BY LAW TO PAY FOR IT
You are free to try DFP Logo for a period of thirty days. Aftwer which you
must either register it, by sending £19.95 to the author, or stop using it.
Comments and suggestions should be addressed to the address at the end of this
document.
2
Getting started:
The LOGO language was invented at the Massachusettes Institute of Technology
(M.I.T.) during the 1960s by a combined group of educationalists and computer
scientists. The purpose was to produce a computer language that would assist
children with learning how to communicate with a computer. Since then various
variations of LOGO have been developed for most popular micro computers, DFP
LOGO is a LOGO language interpreter for IBM personal computers equipped with
a VGA colour monitor. The advances in the technology of the IBM personal
computer have been considered when developing this latest version of LOGO. We
have tried to retain the original M.I.T. flavour as much as possible, and
added to it where appropriate. We suggest anyone interested in LOGO
in general should obtain more detailed literature. A list of known sources of
information is at the end of this document.
Turtle Graphics:
LOGO has achieved fame for its system of moving a pointer around which leaves
a trail behind it. Originally this pointer was a pen carrying robot. Today the
robot has been replaced with a screen icon. Still refereed to as the "turtle".
With turtle graphics a child can instruct (program) the turtle to move, raise
and lower its pen, and to see the result instantly. This allows stimulation to
children of all levels of ability, and encourages thought along the lines of
"what if...". Just with other computer programs, mistakes may be made, and
the turtle will not do what the child intended. Introducing the idea that
computers only do precisely what they are told, and that they are not
intelligent, thinking machines as depicted in many science fiction programs.
When started, DFP LOGO shows a black screen with a blue arrow head in the
centre, and a white question mark at the bottom left corner. The arrow head is
the "turtle" which can be instructed to move. The question mark is called a
"prompt", and shows that DFP LOGO is awaiting a command from the operator,
you. To leave DFP LOGO enter the command QUIT.
Turtle graphics commands are as follows; FORWARD, RIGHT, LEFT, PENDOWN, PENUP,
PENCOLOUR, SETXY, SETHEADING and HOME. To start type FORWARD 50 and press the
return key which is marked <-┘. The turtle moves up the screen. An instant
response to the instruction provided. Now type in RIGHT 90 and press the
return key. The turtle rotates ninety degrees to the right. Another way to
point the turtle in a new direction is with SETHEADING. SETHEADING is similar
to RIGHT and LEFT, except that it turns the turtle to the specified angle. As
well as forward you can use SETXY to move the turtle to a known point.
Coordinates:
DFP LOGO uses a coordinate system which extends from -300 to +300 horizontally
and from -150 to +150 vertically. The origin, or coordinate 0,0 is in the
centre of the screen. The turtle can be moved to any screen coordinate with
SETXY which accepts two values, each enclosed in parenthesis. The first value
is the horizontal (or X) coordinate to move to. The second value is the
vertical (or Y) coordinate to move to. When a SETXY command is issued, the
turtle turns to face the new coordinate and then travels in a straight line to
3
it. If the pen is down a trail will be left.
Text mode:
DFP LOGO can be switched from graphics mode into text mode with the command
TEXTSCREEN. Any drawing on the screen is lost, and the turtle disappears. When
in text mode all DFP LOGO commands are recognised, but turtle graphics
commands have no effect. This is the best mode for writing procedures and
investigating lists. To return to turtle graphics, enter the command
FULLSCREEN.
Variables:
When a procedure starts, it may define local variables. These local
variables are lost when the procedure ends. If a procedure calls another
procedure, any local variables are hidden from the subsequent procedure.
Variables which are defined without the "LOCAL" description are termed global
variables and are available to all procedures. Any parameters specified in a
procedure's definition line are stored as LOCAL variables.
The following program illustrates the idea of local and global variables;
TO TESTVAR
LOCAL "Y
MAKE "X [GLOBAL VARIABLE]
MAKE "Y [LOCAL VARIABLE]
DISPLAY.VARS
END
TO DISPLAY.VARS
PRINT :X
PRINT :Y
END
The program displays the value of X, "GLOBAL VARIABLE". But the variable Y is
unknown to procedure DISPLAY.VARS and an error message is displayed. This
example accepts two parameter variables and uses them to draw a regular
polygon;
TO POLYGON :RADIUS :SIDES
REPEAT :SIDES [FORWARD :RADIUS RIGHT 360 / :SIDES]
END
Recursion:
The term "recursion" refers to a procedure which calls itself. DFP LOGO allows
recursion. When ever a procedure calls another procedure, the computer must
remember where it was before the procedure was called. Remembering uses up
computer memory called the "program stack". With recursion it is easy to
exceed the available memory. When this happens the program will stop running
with the error message "Program stack overflow" displayed.
4
Repeat:
REPEAT is LOGO's looping command. It carries out a list of instructions a
specified number of times. For example; to draw a square we could say;
FORWARD 50
RIGHT 90
FORWARD 50
RIGHT 90
FORWARD 50
RIGHT 90
FORWARD 50
RIGHT 90
Or we could use repeat;
REPEAT 4 [FORWARD 50 RIGHT 90]
This example uses REPEAT to draw a circle;
TO CIRCLE :RADIUS
PENDOWN
REPEAT 360 [FORWARD :RADIUS RIGHT 1]
END
And here is a rather pretty spiral drawing procedure. Try it with parameters
of 10 2 and 117; SPIRAL 10 2 117.
TO SPIRAL :SIDE :INC :ANGLE
PENDOWN
REPEAT 150 [FORWARD :SIDE RIGHT :ANGLE MAKE "SIDE :SIDE + :INC]
PENUP
END
Mathematics:
Traditional LOGO does not cater for mathematicians. DFP LOGO changes all that
by including a new type of command, the function command. A function command
is one which takes a parameter within parenthesis and applies a mathematical
function to it. The result is then returned. Traditional LOGO would calculate
the sine of an angle with the command SIN. DFP LOGO uses SIN(). So for
example, to calculate the sine of ninety degress in DFP LOGO you use; SIN(90).
Addition is represented by the usual plus sign; "+". Subtraction by the
familiar minus sign; "-". Multiplication is represented by the standard
computer symbol "*". Division is represented by the computer symbol for
division; "/". Normal arithmetic rules of precedence apply to mathematics
carried out with DFP LOGO. Parenthesis can be used just like in non-computer
mathematics.
This is an interesting program which draws "star" shapes. However, the values
for the parameters must be carefully chosen or the resulting design may not be
what is expected!
5
TO STAR :NUMBER :MULTIPLIER
REPEAT :NUMBER [FORWARD 100 RIGHT (360 / :NUMBER) * :MULTIPLIER]
END
Lists:
DFP LOGO includes full list handling facilities as found in other LOGOs. A
list is a sequence of words, such as; Matthew Mark Luke John. Logo defines
lists by enclosing the items within square brackets, []. Strings are defined
by a leading single quote, ". So, for example, [THIS IS A VALID LIST] and
"A.STRING. To see lists in action try entering, MAKE "MYLIST [THE FAT CAT SAT
ON THE MAT]. Now enter PRINT :MYLIST. DFP LOGO responds by displaying THE FAT
CAT SAT ON THE MAT.
Logo allows elements of a list to be accessed individually. The command FIRST
returns the first item of a list. If we enter FIRST :MYLIST. DFP LOGO responds
by displaying THE. Another command is LAST which returns the last element in a
list. For example, LAST :MYLIST returns MAT. The command COUNT returns the
number of elements within a list. Here is a simple program to try;
TO TESTLIST
MAKE "MYLIST [THE FAT CAT SAT ON THE MAT]
MAKE "IC COUNT :MYLIST
MAKE "CI 1
REPEAT :IC [PRINT ITEM :CI :MYLIST MAKE "CI :CI+1]
END
This program gives the output;
THE
FAT
CAT
SAT
ON
THE
MAT
The new command ITEM returns the specified element from the list. Lists can be
enclosed within lists. If we change the example program to;
TO TESTLIST
MAKE "MYLIST [[THE FAT CAT] [SAT ON THE MAT]]
MAKE "IC COUNT :MYLIST
MAKE "CI 1
REPEAT :IC [PRINT ITEM :CI :MYLIST MAKE "CI :CI+1]
END
The output from the program changes to;
[THE FAT CAT]
[SAT ON THE MAT]
6
Logo provides the means to test if a word or list is contained within another
list. This is with the command MEMBER? We can test if the word FAT occurs
within our list with;
MEMBER? "FAT :MYLIST
Which will display;
1
Also we can test if the list [THE FAT CAT] occurs within our list using;
MEMBER? [THE FAT CAT] :MYLIST
Lists can be added to, either at the start or at the end, using the commands
FPUT and LPUT. FPUT, which is short for FIRST PUT adds a word or list to the
start of another list. LPUT, which is short for LAST PUT, adds a word or list
to the end of a list. For example;
MAKE "MYLIST [THE QUICK BROWN FOX]
MAKE :MYLIST LPUT [JUMPS OVER THE LAZY DOG] :MYLIST
PRINT :MYLIST
The output from this program may not be quite what you expect. As we have
added a list to the end of our existing list, the output looks like this;
THE QUICK BROWN FOX [JUMPS OVER THE LAZY DOG]
If we want to join lists together we can use the command SENTENCE. SENTENCE
takes two lists, and returns a new list, which is the second list appended to
the end of the first one. So our previous program could be improved by using
SENTENCE in place of LPUT;
MAKE "MYLIST [THE QUICK BROWN FOX]
MAKE :MYLIST SENTENCE :MYLIST [JUMPS OVER THE LAZY DOG]
PRINT :MYLIST
SENTENCE only joins two lists together. To join more than two we have the
command (SENTENCE). This works just like SENTENCE, but accepts any number of
lists. The last list must be followed by a space and a closing parenthesis.
For example;
MAKE "MYLIST [THE QUICK BROWN FOX]
MAKE :MYLIST (SENTENCE :MYLIST [JUMPS OVER] [THE LAZY DOG] )
PRINT :MYLIST
The Editor:
Procedures and programs are written with the DFP LOGO editor. To select the
editor, enter EDIT from the question mark prompt. The screen changes to the
editor screen. The editor will search the current DOS directory for a file
called "logo.def". If the file is found it is automatically loaded into the
7
editor, if not a new file is created. When the editor is in "edit" mode the
current cursor coordinates and the name of the file being edited are displayed
at the bottom of the screen. Procedures can now be typed in. Press the key
marked Esc to exit edit mode. If the file has been changed you will be asked
if you wish to save it. Press the key marked Y to save the file, or the key
marked N if you want to lose the changes. The editor is now in command mode,
shown by a > prompt at the bottom left of the screen.
Command mode commands:
COMMAND FUNCTION
EDIT Edit current file.
LOAD Load new file from disk.
SAVE Save current file to disk.
RUN Leave editor.
Edit mode function keys:
Key Function
Cursor left one character
Cursor right one character
Up arrow Cursor up one line
Down arrow Cursor down one line
Ctrl Cursor left one word
Ctrl Cursor right one word
Home Start of current line
End End of current line
Tab Cursor to next tab stop
Page Down Next page
Page Up Previous page
Ctrl Page Down End of file
Ctrl Page Up Start of file
<-┘ Insert blank line
Ctrl Y Delete current line
Backspace Delete character to left of cursor
Delete Delete character under cursor
Esc Exit edit mode
Procedures:
A procedure is comprised of a heading line, some command lines and an
end line. The heading line starts with the word "TO". This tells DFP LOGO that
this line is the start of a procedure. After the "TO" must be a space and then
the name of the procedure. For example TO SQUARE would tell DFP LOGO that this
is the start of a procedure called "SQUARE". Any parameters which are to be
supplied to the procedure are defined on the heading line. Each parameter is
defined by a colon (:) followed by the parameter's name. For example ":SIDE"
describes a parameter called "SIDE". The end line consists solely of the word
8
"END". A complete procedure to draw a square may be thus written;
TO SQUARE :SIDE
REPEAT 4 [FORWARD :SIDE RIGHT 90]
END
Once written in the editor, procedures can be accessed like built in DFP LOGO
commands from the question mark prompt.
Summary of DFP LOGO commands:
COMMAND ACTION
ABS() Returns the absolute value of the number within the
parenthesis.
Example: PRINT ABS(-56)
ACOS() Returns the arc cosine value of the number within the
parenthesis.
Example: PRINT ACOS(0.5)
ASIN() Returns the arc sine value of the number within the
parenthesis.
Example: PRINT ASIN(0.5)
ASSOC Returns any list in second parameter which is associated with
first parameter.
Example: PRINT ASSOC "HUSBAND [[NAME SALLY] [HUSBAND
FRED]]
ATAN() Returns the arc tangent value of the number within the
parenthesis.
Example: PRINT ATAN(0.5)
ALLOF Used with IF to test multiple conditions, returning TRUE if
all of the conditions are true.
Example: IF ALLOF [XCOR < 20 YCOR < 20] THEN FORWARD 50
ANYOF Used with IF to test multiple conditions, returning TRUE if
any of the conditions are true.
Example: IF ANYOF [XCOR < 20 YCOR < 20] THEN FORWARD 50
BUTFIRST Returns all but the first letter of the supplied input string,
or all but the first item of the supplied input list.
Example: PRINT BUTFIRST [ONE TWO THREE]
Example: PRINT BUTFIRST "ABCDEFGHIJKLM
9
BUTLAST Returns all but the last letter of the supplied input string,
or all but the last item of the supplied input list.
Example: PRINT BUTLAST [ONE TWO THREE]
Example: PRINT BUTLAST "ABCDEFGHIJKLM
CLEARSCREEN Clear the display.
Example: CLEARSCREEN
COS() Returns the cosine of the angle (measured in degrees) within
the parenthesis.
Example: RIGHT COS(:MYVAR)
COSH() Returns the hyperbolic cosine of the angle specified within
the parenthesis.
Example: COSH(90)
COUNT Returns the letters in the string, or items in the list
following.
Example: PRINT COUNT "MATTHEW
Example: PRINT COUNT [THE QUICK BROWN FOX]
EMPTY? Returns 1 if the string/list following is empty
Example: PRINT EMPTY? "
Example: PRINT EMPTY? []
END Defines end of a user procedure.
Example: END
EXP() Returns the exponential e raised to the power of the number in
the parenthesis.
Example: EXP(4)
FIRST Returns the first letter of the supplied input string, or the
first item of the supplied input list.
Example: PRINT FIRST [ONE TWO THREE]
Example: PRINT FIRST "ABCDEFGHIJKLM
FORWARD Move turtle forward.
Example: FORWARD 50
FULLSCREEN Switch to turtle graphics mode.
Example: FULLSCREEN
HIDETURTLE Hide turtle from display. This makes drawing very much faster.
Example: HIDETURTLE
HOME Causes the turtle to return to the centre of the screen in a
straight line, and turn due north.
Example: HOME
IF THEN Tests a condition and if it is true, executes the commands
following the THEN.
Example: IF XCOR > 20 THEN FORWARD 50
10
LAST Returns the last letter of the supplied input string, or the
last item of the supplied input list.
Example: PRINT LAST [ONE TWO THREE]
Example: PRINT LAST "ABCDEFGHIJKLM
LEFT Turn turtle anitclockwise.
Example: LEFT 90
LOCAL Declares a variable known only to the current procedure
Example: LOCAL "MYVAR
(LOCAL ... ) Declares several variables known only to the current
procedure.
Example: (LOCAL "X "Y "Z )
LOG() Returns the natural logarithm of the number within the
parenthesis.
Example: LOG(8)
LOG10() Returns the logarithm of the number within the
parenthesis.
Example: LOG10(800)
MAKE Assigns a value to a variable.
Example: MAKE "MYVAR :OLDVAR
Example: MAKE :MYVAR 10
MEMBER? Returns TRUE if the first input is contained within the
second.
Example: PRINT MEMBER? "QUICK [THE QUICK BROWN FOX]
Example: PRINT MEMBER? "A "MATTHEW
NUMBER? Returns TRUE if the input is a number.
Example: PRINT NUMBER? "NOT_NUMBER
PENCOLOUR Select turtle's pen colour (0 - 14).
Example: PENCOLOUR 12
PENDOWN Lower turtle's pen.
Example: PENDOWN
PENUP Raise turtle's pen.
Example: PENUP
POW10() Returns 10 raised to the power of the number in the
parenthesis.
Example: POW10(5)
PRINT Displays a single input.
Example: PRINT [DFP LOGO RULES OKAY!]
Example: PRINT SIN(90)
(PRINT ... ) Displays input before the closing parenthesis.
11
Example: (PRINT "DFP "LOGO "RULES "OKAY )
QUIT Terminates DFP LOGO.
Example: QUIT
RANDOM() Returns a random number between 0 and one less than the number
within the parenthesis.
Example: PRINT RANDOM(100)
RANDOMIZE Forces initialisation of the random number generator.
Example: RANDOMIZE
READCHAR Waits for a key to be pressed and returns it.
Example: MAKE "KEY READCHAR
REPEAT Do commands in second input field, which must be a list, the
number of times indicated by the first input field.
Example: REPEAT 4 [FORWARD 50 RIGHT 90]
REQUEST Accepts a list from the operator.
Example: MAKE "INPUT REQUEST
RIGHT Turn turtle clockwise.
Example: RIGHT 90
ROUND() Returns the number within the parenthesis rounded to the
nearest whole number.
Example: RIGHT ROUND(COS(:MYVAR))
RUN Do commands recorded in the input field which must be a list.
Example: RUN :MYVAR
SETHEADING Turn turtle to new bearing.
Example: SETHEADING 90
SETXY Move turtle in a straight line to specified coordinates.
Example: SETXY (10) (-50)
SHOWTURTLE Reveal turtle.
Example: SHOWTURTLE
SIN() Returns the sine of the angle within the parenthesis.
Example: RIGHT SIN(:MYVAR)
SINH() Returns the hyperbolic sine of the angle specified within the
parenthesis.
Example: SINH(90)
12
SQRT() Returns the square root of the number within the parenthesis.
Example: PRINT SQRT(25)
TAN() Returns the tangent of the angle within the parenthesis.
Example: RIGHT COS(:MYVAR)
TANH() Returns the hyperbolic tangent of the angle specified within
the parenthesis.
Example: TANH(45)
TEXTSCREEN Switch to text mode.
Example: TEXTSCREEN
THING? Takes a variable name as input and returns TRUE if the
variable has a value assigned to it.
Example: PRINT THING? :MYVAR
TO Defines start of a user procedure.
Example: TO SQUARE
UNTIL Loops whilst a condition is false.
Example: UNTIL :COUNTER = 100 [PRINT :COUNTER MAKE
"COUNTER :COUNTER + 1]
WHILE Loops whilst a condition is true.
Example: WHILE :COUNTER < 100 [PRINT :COUNTER MAKE
"COUNTER :COUNTER + 1]
XCOR Returns the turtle's horizontal coordinate.
Example: MAKE "LASTX XCOR
YCOR Returns the turtle's vertical coordinate.
Example: MAKE "LASTY YCOR
General specification:
DFP LOGO can accomodate nested calls to procedures to a depth of 100 calls.
100 global variables can be defined.
100 Local variables can be defined.
Program files can have up to 2000 lines.
Variables may be up to 500 characters in length.
Variable names are up to twenty characters long.
Further Reading:
Introducing Logo, Boris Allan, Granada Publishing Ltd, 1984,
13
ISBN 0 246 12323 0
Logo For Beginners, J.W.Penfold, Bernard Babani Ltd, 1988, ISBN 0 85934 167 4
Learning Commodore 64 Logo Together, Kenneth P. Goldberg, Microsoft Press,
1984, ISBN 0 914845 24 1
Revision History
Version 0.1 The original.
Version 0.2 Following comments received the procedure for drawing the
turtle has been speeded up.
Text output has been speeded up.
The command interpreter has been speeded up.
Recursion depth has been increased to 100.
Available local variables increased to 100.
Bug fix - The input parser now handles expressions with
multiple arithmetic.
Version 1.0 First production release
Version 1.1 Addition of three new commands: ASSOC, UNTIL and WHILE
COPYRIGHT NOTICE
DFP LOGO is copyright (c)1993 Sservile Software
All rights reserved. We make no claims as to the suitability of this product
for any purpose. DFP LOGO is supplied "as is" and is used solely at the users
risk.
Servile Software
5 Longcroft Close
Basingstoke
Hampshire
RG21 1XG
England
Telephone: 0256 414072