home *** CD-ROM | disk | FTP | other *** search
- .ll 7.5i
- .lt 7.5i
- .po .2i
- .pn 1
- .de TL
- .sp 2
- .ft 3
- .ce
- \\$1
- .sp 1
- .ft 1
- ..
- .de PP
- .sp 1
- .ti 5
- .fi
- .ft 1
- ..
- .de NB
- .de NP
- 'sp 1
- .tl ''%''
- 'bp +1
- 'sp 2
- \\..
- .ch NP -1i
- ..
- .de NP
- 'bp +1
- 'sp 2
- ..
- .wh -1.0i NP
- .TL "LSRHS Logo Manual"
- .NB
- .de EX
- .ft 3
- .in +5
- .sp 1
- .nf
- ..
- .de EE
- .ft 1
- .in -5
- .fi
- .PP
- ..
- .de EC
- .ft 1
- .in -5
- .sp 1
- .fi
- ..
- .de IN
- .br
- .in +5
- ..
- .de OU
- .sp 1
- .in -5
- ..
- .de UB
- .uf 3
- .cu 1
- \\$1
- .ft 1
- .uf 2
- ..
- .PP
- .UB "Introduction."
- Logo is a computer programming language which was
- designed to be both simple to use and extremely powerful. It was
- designed by a group of computer scientists at MIT and at Bolt, Beranek, and
- Newman. Its structure is based largely on the LISP language, which is
- widely used in Artificial Intelligence research, but the notation has been
- changed to make Logo far easier for a beginner than LISP. This manual
- describes a version of Logo for the PDP-11, originally written in C at the
- Boston Children's Museum and extensively modified at the Lincoln-Sudbury
- Regional High School.
- .PP
- The power of Logo comes primarily from the idea of the \f2procedure\f1. A
- procedure is simply something the computer "knows" how to do; some
- procedures are built into Logo itself (these are called \f2primitive\f1
- procedures), while others are \f2defined\f1 by the programmer in terms of
- these simple procedures. Defined procedures can be used as part of the
- definition of other procedures, so that a complicated program can be built
- in "layers" of complexity. This layered structure is analogous to the
- description of a complex machine in terms of building blocks: an automobile
- is made of a chassis, a drive train, an electrical system, and so on. The
- drive train contains an engine, a transmission, a clutch, an axle, and so
- on. The transmission contains a housing, gears, and levers. A lever may
- include connecting joints at the ends and at a pivot point. Eventually the
- description of the automobile reaches the level of bolts and washers; these
- correspond to the primitive procedures in Logo.
- .PP
- .UB "Starting Logo."
- Use the shell command \f3logo\f1 to start the Logo
- interpreter. When Logo is running it will print a question mark (?) at the
- beginning of a line to indicate that it is ready for you to type in a Logo
- instruction. The instruction may print something on the terminal, or draw a
- line on a graphics display screen, or move a turtle around the floor. Then
- another question mark is typed and you may give another instruction. (If Logo
- prints a "greater than" sign (>) instead of a question mark, it is
- in \f2procedure definition mode\f1,
- which will be described later. Type your system quit character
- (control-G at Lincoln-Sudbury) to return to normal mode.)
- .PP
- If an argument is used with the shell command \f3logo\f1, the argument is
- taken as the name of a procedure, which Logo runs before doing anything
- else. You can therefore create a shell script which will start Logo, run
- a procedure automatically, and (if you say "goodbye" at the end of the
- procedure) exit.
- .PP
- .UB "Syntax."
- Unlike most computer languages, Logo has an almost
- entirely uniform
- syntax. That is, all of the different commands Logo understands are
- represented using the same notation: the name of a procedure is followed by
- its \f2inputs\f1, which may be \f2constants\f1 (like numbers) or else may
- be the results of using other procedures. Here is a simple example:
- .EX
- print "hello
- .EC
- In this Logo instruction, the primitive procedure \f3print\f1 is used with
- a constant input, the word \f3hello\f1. The quotation mark indicates that
- \f3hello\f1 is being used to represent the word itself; without the
- quotation mark it would have been interpreted as the name of a procedure,
- just as \f3print\f1 is the name of a procedure. In Logo, the \f3print\f1
- procedure always requires exactly one input, which is the thing to print. The
- input can be a \f2word\f1, as in this example, or a \f2list\f1, which will
- be explained later. (A \f2number\f1 is a special case of a word, and a
- \f2sentence\f1 is a special case of a list.) Here is another example:
- .EX
- print first "hello
- .EC
- In this instruction, the primitive procedure \f3first\f1 is used. This
- procedure takes one input, a word, and has an \f2output\f1 which is the
- first letter of the word. The output from \f3first\f1 is used as the input
- to \f3print\f1, so what is printed is the letter \f3h\f1 rather than the
- word \f3hello\f1 as in the earlier example.
- .PP
- Don't confuse the \f2output\f1 from a procedure with what is \f2printed\f1
- by the \f3print\f1 command. In Logo, the word "output" is not used to
- refer to what is printed by a program, just as the word "input" does not
- mean something you type into the program. Instead, these words refer to
- objects (words or lists) which are given to a procedure (inputs) or
- produced by a procedure (outputs). A particular procedure has a fixed
- number of inputs and outputs. The number of inputs may be anything,
- including zero, whereas the number of outputs is either zero or one. A
- procedure with an output (like \f3first\f1) is called an \f2operation\f1; one
- without an output (like \f3print\f1) is called a \f2command\f1.
- .PP
- Some operations only have two possible outputs: the word \f3true\f1 and
- the word \f3false\f1. Such a procedure is called a \f2predicate\f1. Predicates
- are used to allow a program to carry out some instruction only if a
- particular condition is met. By convention, predicates generally have
- names ending with the letter "p".
- .PP
- .UB "Multiple inputs to operations."
- Several Logo primitive procedures are
- operations with two inputs. The arithmetic operations, like \f3sum\f1, are
- examples of this. A special extension to Logo syntax allows such an operation
- to have more than two inputs by enclosing the operation and its inputs in
- parentheses or braces:
- .EX
- (sum 2 5 13 8.5)
- .EC
- Association is right to left. At least two inputs must be given, except for
- the \f3list\f1 operation, which can take one input if parenthesized.
- .PP
- .UB "Multi-instruction lines."
- It is possible to put more than one instruction on the same line when you
- are typing to Logo. If you do this, it is recommended that you type a
- semicolon (;) between the instructions for improved readability:
- .EX
- print "hello; print "goodbye
- .EC
- For compatibility with other versions of Logo, it is permitted to leave out
- the semicolon. Later in this manual, the phrase "instruction line" will
- mean one or more instructions on a line.
- .PP
- .UB "Multi-line instructions."
- It is possible to continue an instruction on
- a second line. To do this, end the first line with a backslash (\\),
- immediately followed by the RETURN key. If you are typing a quoted word,
- you must end the word (with a space, for example) before using the
- backslash-RETURN combination. Inside a quoted word, backslash-RETURN
- means to put an actual RETURN as part of the word.
- .PP
- .UB "Comments."
- It is possible to include in an instruction line comments
- which are meant for human readers of your program (including yourself, next
- week), and which are not Logo instructions. To do this, begin the comment
- with an exclamation point (!). Everything after the exclamation point on the
- line will be ignored by Logo. For example:
- .EX
- print [Hi, there.] ! A friendly greeting.
- .EC
- However, the exclamation point does not begin a comment if it is part of a
- word or list (see below). You should type a space before the exclamation
- point, as in the example above, to make sure it will be interpreted as the
- beginning of a comment.
- .PP
- .UB "Words."
- Every computer language deals with particular kinds
- of objects. Most languages, like FORTRAN or BASIC or Pascal, are best at
- dealing with numbers. Logo is a \f2list processing\f1 language, which is
- at its best with more complicated data structures. The two main categories
- of object are the \f2word\f1 and the \f2list\f1.
- .PP
- A \f2word\f1 is a string of characters. (A \f2character\f1 is a letter,
- digit, space, or punctuation mark. Things like TAB and RETURN on the
- terminal keyboard are also characters, although they are not usually used
- as part of Logo words.) A word can be any length, including zero. The way
- to indicate a word as part of a Logo program is to use the quotation mark
- (") before the word. The word begins with the character after the
- quotation mark and continues until a space, a tab, the end of the
- line, or one of these characters:
- .EX
- ( ) [ ] { } " ;
- .EC
- A quotation mark immediately followed by a space or one of the other
- word-terminating characters indicates the \f2empty word\f1, which is a word
- of length zero.
- .PP
- Please notice that, unlike most programming languages, Logo does not use
- quotation marks in pairs to delimit strings of characters. The following
- instruction is an error:
- .EX
- print "aardvark"
- .EC
- This is an error because the \f3print\f1 command is followed by \f2two\f1
- words, the word \f3aardvark\f1 and an empty word which is indicated by the
- second quotation mark. Since \f3print\f1 only uses one input, the second
- word has no purpose, and Logo gives the error message
- .EX
- You don't say what to do with "
- .EE
- In order to include one of the word-terminating characters in a word, you
- must precede it with a backslash (\\). Do not confuse backslash with the
- regular slash (/) character. For example, this instruction:
- .EX
- print "\\(boo\\)
- .EC
- will print the five characters \f3(boo)\f1 as its result. The space
- character may be included in a word by using a percent (%) instead of the
- space. Therefore, the following are equivalent:
- .EX
- print "Hello%there.
- print "Hello\\ there.
- .EC
- To include a percent character or a backslash character in a word, you must
- precede it with a backslash.
- .PP
- .UB "Numbers."
- A number is a special case of a word, in which the
- characters are all digits. (That definition isn't quite complete, and will
- be expanded in the next paragraph.) A number need not be preceded with a
- quotation mark. (This rule is possible because normally Logo interprets
- words without quotation marks as the names of procedures, but there are no
- procedures whose names begin with digits.) If a quotation mark is not
- used, then any nondigit terminates the word.
- .PP
- Actually, numbers may be written in scientific notation. That is, they can
- include signs, decimal points, and a power of 10 by which the number is
- multiplied. This \f2exponent\f1 is indicated by the letter \f3e\f1
- followed by the integer power of 10. The following numbers have the
- same value:
- .EX
- 1000
- "1000
- 1000.00
- 1e3
- 10.0e+2
- "+1.0e3
- 10000e-1
- .EC
- Notice that if the number begins with a sign it must be quoted. A quoted
- number still must begin with a digit or a sign, not with a
- decimal point or a letter \f3e\f1. (The
- letter may be a capital \f3E\f1, by the way.) If a number is quoted, it
- must end with one of the normal word-terminating characters. A number
- which contains only digits (no decimal point or exponent) is called
- an \f2integer\f1. Note that a number with a decimal point is not
- considered an integer even if the digits after the decimal point are
- all zero.
- .PP
- Since a number is a word, the usual character-manipulating procedures may
- be applied to it. For example,
- .EX
- print first 1024
- .EC
- prints the digit \f31\f1 which is the first character of the number. In
- addition, there are arithmetic procedures which apply specifically to numbers:
- .EX
- print sum 3 2
- .EC
- prints the number 5. These procedures will be listed later.
- .PP
- .UB "Lists."
- A word can be thought of as a list of characters; for
- example, the word \f3hello\f1 is a list of five letters. In Logo it is
- possible to manipulate not only lists of characters but also lists of
- words, lists of lists of words, and so on. This is a very powerful capability
- which allows very complicated data structures to be manipulated easily. To
- indicate a list in a program, you put square brackets ([ and ]) around the
- list, and separate the list elements with spaces. For example:
- .EX
- print [This is a list of seven words.]
- .EC
- A list all of whose elements are words is called a \f2sentence\f1. Here
- is an example of a list which is not a sentence:
- .EX
- print [[This is a list][of two sentences.]]
- .EE
- Within a bracketed list, square brackets delimit sub-lists (lists which are
- elements of the main list). The quotation mark, parentheses, and braces
- are not considered special within a bracketed list, unlike the rules for
- quoted words. A list may extend over more than one line; that is, if you
- have typed an open square bracket ([) and have not yet typed the matching
- close square bracket, the Logo instruction is not ended by typing the RETURN
- key.
- .PP
- .UB "Variables."
- A variable is an entity which has a \f2name\f1, which
- is a word, and a \f2thing\f1 (also called a \f2value\f1), which
- can be any Logo object. Variables
- are used to "remember" a computed object for repeated or delayed use
- in a program. In Logo, the most common way that a variable acquires
- a value is that it is associated with an input to a user-written
- procedure. In the following example, don't worry about the details
- of the format of the procedure, which will be explained later:
- .EX
- to pff :sentence
- print first first :sentence
- end
- .EC
- This is the definition of a command with one input. The name of the
- command is \f3pff\f1. It has one input because in the "title line" (the
- one starting \f3to pff\f1) there is one variable name after the command
- name. The variable whose name is \f3sentence\f1 is associated with the
- first (and only, in this case) input to \f3pff\f1. In the line starting
- with the word \f3print\f1, the notation \f3:sentence\f1 means "the \f2thing\f1
- of the variable whose \f2name\f1 is \f3sentence\f1". (To refer to the
- name itself, quote it as you would any word.) If this procedure is used
- in a Logo instruction like this:
- .EX
- pff [This is the poop.]
- .EC
- then the variable \f3sentence\f1 has the value \f3[This is the poop.]\f1.
- .PP
- It is also possible to assign a value to a variable by an explicit
- Logo instruction. There is a primitive procedure to do this:
- .sp 1
- \f3make\f1 \(em Command, two inputs.
- .IN
- The first input is the name of a variable (that is, it must be a word); the
- second is any Logo object. The effect of the command is to assign the
- second input as the value of the variable named by the first input.
- .OU
- If you are accustomed to programming in a non-procedural language like
- BASIC, you should strenuously avoid the temptation to overuse \f3make\f1;
- explicit assignment is almost always the wrong thing to do in Logo. Total
- abstention is the best policy for a Logo beginner.
- .PP
- In Logo, variables are \f2dynamically scoped\f1. That means that a
- variable can "belong to" a particular procedure; such a variable can
- be used by that procedure and by any procedure which is used by an
- instruction within the procedure, but is not available to the procedure
- which invoked the owning procedure. In other words, such a \f2local\f1
- variable comes into being when the owning procedure starts running, and
- disappears when that procedure is finished. It is possible for a
- procedure with a local variable to use another procedure with a local
- variable of the same name. In that case, the variable belonging to the
- "inner" procedure is the one which is associated with the name as long
- as it exists; when the inner procedure is finished, the "hidden"
- variable belonging to the outer procedure is again available.
- .PP
- A variable which is associated with the input to a procedure is
- automatically local to that procedure. Other variables are normally
- \f2global\f1: they are "permanent" and do not disappear when the
- procedure in which they get their values finish. It is both possible
- and desirable to make such variables local, by an explicit instruction
- to that effect:
- .sp 1
- \f3local\f1 \(em Command, one input.
- .IN
- The input must be a word. A variable with that word as its name
- is created, local to the currently running procedure (that is,
- local to the procedure in which the \f3local\f1 command is used).
- .OU
- The virtue of local variables is that they make procedures more
- independent of one another than they would be if global variables
- were used. In other words, if you use local variables consistently,
- then nothing that happens in one procedure will change the values
- of variables used in another procedure. This makes it very much
- easier to find program errors.
- .PP
- .UB "Case insensitivity."
- Names of procedures (primitive or user-defined) and names of variables
- may be typed in upper or lower case. They are converted internally to
- lower case. That is, the variables \f3foo\f1 and \f3FOO\f1 are the
- same variable. Letters in other contexts are not converted to lower
- case. For example, \f3equalp\f1 will report that the words \f3foo\f1
- and \f3FOO\f1 are not equal.
- .PP
- Names of procedures and names of variables may include only letters,
- digits, and the special characters period (.) and underscore (_). Also,
- names of procedures are limited to 11 characters in some versions of Unix.
- .PP
- .UB "Primitive procedures to define user procedures."
- There are
- two ways to define your own procedure. The first way, using the \f3to\f1
- command, is simple to learn but limited in flexibility. The second way,
- using the \f3edit\f1 command, is more complicated to learn, but makes it
- easy to make changes in your procedures. The \f3edit\f1 command uses the
- text editing program \f3edt\f1, just as you might use it outside of Logo
- to edit a document you want to print. Once you've learned the special
- editing commands in \f3edt\f1, it's easy to use. The \f3to\f1 command makes
- it possible to begin programming in Logo without having learned how to use
- \f3edt\f1. It just lets you type in your procedure definition, without any
- provision for correcting errors or changing the definition of the procedure.
- It is fast and convenient for short procedures, but limited.
- .sp 1
- The \f3to\f1 command is unique, in Logo, in that its inputs are interpreted
- in a special way. The inputs aren't \f2evaluated\f1: Logo doesn't run any
- procedures you name, or look up the values of any variables, before carrying
- out the \f3to\f1 command. The example below should make this clearer.
- .sp 1
- \f3to\f1 \(em Command, special form, see below.
- .IN
- This command takes a variable number of inputs. The first is the name
- of a procedure to be defined. The rest, if any, must be preceded by
- colons, and are the names of variables to be used as inputs to the
- procedure. Logo responds to the \f3to\f1 command by printing a
- "greater than" sign (>) prompt, to show you that you are defining a procedure
- rather than entering commands to be executed immediately. You type
- the instruction lines which make up the definition. When
- you are done with the definition, type the special word \f3end\f1 on
- a line by itself. For example:
- .sp 1
- .nf
- \f3\z_?to twoprint :thing
- \z_>print :thing
- \z_>print :thing
- \z_>end
- \z_?\f1
- .fi
- .sp 1
- This example shows the definition of a procedure named \f3twoprint\f1,
- which has one input, named \f3thing\f1. The procedure you are defining
- with the \f3to\f1 command must not already be defined.
- .OU
- \f3edit\f1 \(em Command, zero or one input. Abbreviation: \f3ed\f1
- .IN
- The input to this command must be a word, which is the name of a procedure,
- or a list of words, each of which is the name of a procedure.
- (Unlike the \f3to\f1 command, but like all other Logo procedures, the
- \f3edit\f1 command evaluates its input, so you must use a quotation mark
- before the procedure name, if only one is given, to indicate
- that it is the name itself which is
- the input to \f3edit\f1; otherwise Logo would actually run the procedure
- to calculate the input to \f3edit\f1.) The procedure you name may or may
- not already be defined. Logo responds to the \f3edit\f1 command by running
- the text editor \f3edt\f1, editing the definition of the procedure(s) named in
- its input. (If a procedure was not previously defined, Logo creates an
- initial definition for it which contains only a title line and the end line.)
- You then edit the definition(s) with \f3edt\f1. When you write the file and
- leave \f3edt\f1, Logo will use the edited file as the definition(s) of the
- procedure(s). You must not put anything in the file except procedure
- definitions; in other words, every nonempty line in the file must be between
- a "to" line and an "end" line.
- .sp 1
- If the \f3edit\f1 command is given with no input, \f3edt\f1 is given the same
- file as from the last time you used the \f3edit\f1 command. This is a
- convenience for editing the same procedure(s) repeatedly.
- .sp 1
- If, while editing, you change your mind and want to leave \f3edt\f1
- without redefining anything, use the command \f3ESC ^Z\f1 instead of
- the normal \f3^Z\f1. This special way of leaving \f3edt\f1 tells Logo
- not to redefine your procedures. You have the choice, before exiting
- \f3edt\f1, of writing or not writing the temporary file which contains
- the definitions. If you don't write the file, another \f3edit\f1 command
- with no input will re-read the previous contents of the temporary file;
- if you do, another \f3edit\f1 will re-read the new version.
- .sp 1
- If your Unix environment contains a variable named EDITOR, the contents of
- that variable is used as the name of the text editor program instead of
- the standard \f3edt\f1. The variable can contain a full pathname, or just
- a program name if the program can be found in /bin or /usr/bin. Your favorite
- editor may not have a facility like \f3edt\f1's ESC ^Z to abort redefinition.
- .OU
- \f3show\f1 \(em Command, one input. Abbreviation: \f3po\f1
- .IN
- The input to this command is a word or a list of words. Each word must be
- the name of a procedure. The command prints out the definition(s) of the
- procedure(s) on your terminal. (The abbreviation \f3po\f1 stands for
- \f3printout\f1, which is the name used for this command in some other versions
- of Logo.)
- .OU
- \f3pots\f1 \(em Command, no inputs.
- .IN
- This command types at your terminal the title lines of all procedures
- you've defined. The name is an abbreviation for "print out titles".
- .OU
- \f3erase\f1 \(em Command, one input. Abbreviation: \f3er\f1
- .IN
- As for the \f3show\f1 command, the input is either a word, naming one
- procedure, or a list of words, naming more than one. The named procedures
- are erased, so that they are no longer defined.
- .OU
- .ti 5
- .UB "Primitive procedures to manipulate words and lists."
- There are
- primitive procedures to print text objects on the terminal, to read
- them from the terminal, to combine them into larger objects, to split
- them into smaller objects, and to determine their size and nature:
- .sp 1
- \f3print\f1 \(em Command, one input. Abbreviation: \f3pr\f1
- .IN
- The input, which may be a word or a list, is printed on the terminal,
- followed by a new line character. (That is, the terminal is positioned
- at the beginning of a new line after printing the object.) If the
- object is a list, any sub-lists are delimited by square brackets, but
- the entire object is not delimited by brackets.
- .OU
- \f3type\f1 \(em Command, one input.
- .IN
- The input, which may be a word or a list, is printed on the terminal,
- \f2without\f1 a new line character. (That is, the terminal remains
- positioned at the end of the object after printing it.) Brackets
- are used as with the \f3print\f1 command.
- .OU
- \f3fprint\f1 \(em Command, one input. Abbreviation: \f3fp\f1
- .IN
- The input is printed as by the \f3print\f1 command, except that if it
- is a list (as opposed to a word) it is enclosed in square brackets. The
- name of the command is short for "full print".
- .OU
- \f3ftype\f1 \(em Command, one input. Abbreviation: \f3fty\f1
- .IN
- The input is printed as by the \f3type\f1 command, except that if it
- is a list, it is enclosed in square brackets.
- .OU
- \f3readlist\f1 \(em Operation, no inputs. Abbreviation: \f3rl\f1
- .IN
- Logo waits
- for a line to be typed by the user. The contents of the line are made
- into a list, as though typed within square brackets as part of a Logo
- instruction. (The user should not actually type brackets around the
- line, unless s/he desires a list of one element, which is a list
- itself.) That list is the output from the operation.
- .OU
- \f3request\f1 \(em Operation, no inputs.
- .IN
- A question mark is printed on the terminal as a prompt. Then Logo waits
- for a line to be typed by the user, as for \f3readlist\f1.
- .OU
- \f3word\f1 \(em Operation, two inputs.
- .IN
- The two inputs must be words. The output is a word which is the
- concatenation of the two inputs. There is no space or other
- separation of the two inputs in the output.
- .OU
- \f3sentence\f1 \(em Operation, two inputs. Abbreviation: \f3se\f1
- .IN
- The two inputs may be words or lists. The output is a list formed
- from the two inputs in this way: if either input is a word, that
- word becomes a member of the output list; if either input is a
- list, the \f2members\f1 of that input become members of the
- output. Here are some examples:
- .EX
- .ta 2i 4i
- first input second input output
- "hello "test [hello test]
- "goodbye [cruel world] [goodbye cruel world]
- [a b] [c d] [a b c d]
- [] "garply [garply]
- .EC
- If an input is the empty list, as in the last example above, it
- contributes nothing to the output.
- .OU
- \f3list\f1 \(em Operation, two inputs.
- .IN
- The output is a list of two elements, namely, the two inputs. The
- inputs may be words or lists.
- .OU
- \f3fput\f1 \(em Operation, two inputs.
- .IN
- The first input may be any Logo object; the second must be a list. The
- output is a list which is identical with the second input except that
- it has an extra first member, namely, the first input.
- .OU
- \f3lput\f1 \(em Operation, two inputs.
- .IN
- The first input may be any Logo object; the second must be a list. The
- output is a list which is identical with the second input except that
- it has an extra last member, namely, the first input.
- .OU
- \f3first\f1 \(em Operation, one input.
- .IN
- The input may be any non-empty Logo object. If the input is a list,
- the output is its first member. If the input is a word, the output is
- a single-letter word, namely the first letter of the input. If the
- input is empty (a word or list of length zero) an error results.
- .OU
- \f3last\f1 \(em Operation, one input.
- .IN
- The input may be any non-empty Logo object. If the input is a list,
- the output is its last member. If the input is a word, the output is
- a single-letter word, namely the last letter of the input. If the
- input is empty (a word or list of length zero) an error results.
- .OU
- \f3butfirst\f1 \(em Operation, one input. Abbreviation: \f3bf\f1
- .IN
- The input may be any non-empty Logo object. If the input is a list,
- the output is a list equal to the input list with the first member
- removed. (If the input list has only one member, the output is
- the \f2empty list\f1, a list of zero members.) If the input is
- a word, the output is a word equal to the input word with the
- first letter removed. (If the input is a single-letter word, the
- output is the \f2empty word\f1.) If the input is empty, an
- error results.
- .OU
- \f3butlast\f1 \(em Operation, one input. Abbreviation: \f3bl\f1
- .IN
- The input may be any non-empty Logo object. If the input is a list,
- the output is a list equal to the input list with the last member
- removed. (If the input list has only one member, the output is
- the \f2empty list\f1, a list of zero members.) If the input is
- a word, the output is a word equal to the input word with the
- last letter removed. (If the input is a single-letter word, the
- output is the \f2empty word\f1.) If the input is empty, an
- error results.
- .OU
- \f3count\f1 \(em Operation, one input.
- .IN
- The input may be any Logo object. If the input is a list, the
- output is a number indicating the number of members in the list. (Note:
- only top-level members are counted, not members of members. The count
- of the list
- .EX
- [[This is] [a list]]
- .EC
- is 2, not 4.) If the input is a word, the output is the number of
- letters (or other characters) in the word. Remember that in Logo a
- number is just a particular kind of word, so the output from \f3count\f1 can
- be manipulated like any other Logo word.
- .OU
- \f3emptyp\f1 \(em Operation (predicate), one input.
- .IN
- The input can be any Logo object. The output is the word \f3true\f1 if
- the input is of length zero (i.e., it is the empty word or the empty
- list). The output is the word \f3false\f1 otherwise.
- .OU
- \f3wordp\f1 \(em Operation (predicate), one input.
- .IN
- The input can be any Logo object. The output is the word \f3true\f1 if
- the input is a word. The output is the word \f3false\f1 if the input
- is a list.
- .OU
- \f3sentencep\f1 \(em Operation (predicate), one input.
- .IN
- The input can be any Logo object. The output is the word \f3true\f1 if
- the input is a sentence, i.e., a list of words. The output is the word
- \f3false\f1 if the input is a word, or if any member of the input is a
- list.
- .OU
- \f3is\f1 \(em Operation (predicate), two inputs.
- .IN
- The inputs can be any Logo objects. The output is the word \f3true\f1 if
- the two inputs are identical. That is, they must be of the same type
- (both words or both lists), they must have the same count, and their
- members (if lists) or their characters (if words) must be identical. The
- output is the word \f3false\f1 otherwise. (Note: this is an exception
- to the convention that names of predicates end with the letter "p".)
- .OU
- \f3memberp\f1 \(em Operation (predicate), two inputs.
- .IN
- If the second input is a word, the first input must be a word of
- length one (a single character), and the output is \f3true\f1 if and
- only if the first input is contained in the second as a character. If
- the second input is a list, the first input can be any Logo object,
- and the output is \f3true\f1 if and only if the first input is a member
- of the second input. (Note that this is member, not subset.)
- .OU
- \f3item\f1 \(em Operation, two inputs. Abbreviation: \f3nth\f1
- .IN
- The first input must be a positive integer less than or equal to
- the \f3count\f1 of the second input. If the second input is a word,
- the output is a word of length one containing the selected character
- from the word. (Items are numbered from 1, not 0.) If the second input
- is a list, the output is the selected member of the list.
- .OU
- .ti 5
- .UB "Primitive procedures for turtles and graphics."
- An important
- part of the Logo environment is a rich set of applications to which the
- computer can be directed. The most important of these is \f2turtle
- geometry\f1, a way of describing paths of motion in a plane which is
- well-suited to computer programming. There are two ways to use the
- turtle procedures. First, you can control a \f2floor turtle\f1, a small
- robot which can move one the floor or on a table under computer
- control. Second, you can use a \f2display turtle\f1 to draw pictures
- on the TV screen of a graphics terminal.
- .PP
- Each computer center has a different variety of graphics hardware
- available. Floor turtles are very different from display turtles, but also
- each kind of display terminal has different characteristics. For example,
- some terminals can draw in several colors; others can't. The following
- descriptions of graphics primitives explain the "best" case for each one
- and mention restrictions on some graphics devices.
- .PP
- The floor turtle can draw pictures on paper, because it has a pen
- attached to its "belly": the underside of the turtle. Since it is
- a mechanical device, however, it is not very precise; the pictures
- you get may not be exactly like what your program specifies. A more
- interesting way to use the floor turtle is to take advantage of its
- \f2touch sensors\f1. Switches under the turtle's dome allow the computer
- to know when the turtle bumps into an obstacle. You can use this
- information to write programs to get around obstacles or to follow
- a maze.
- .PP
- The display turtle lives on the surface of a TV screen. It can draw
- pictures more precisely than the floor turtle, since it does not
- measure distances and angles mechanically. It is also faster than
- the floor turtle. When using the display turtle, remember that
- it interprets commands relative to its own position and direction,
- just as the floor turtle does. The command \f3left\f1, for example,
- turns the turtle to its own left, which may or may not be toward
- the left side of the TV screen.
- .sp 1
- \f3turtle\f1 \(em Command, one input. Abbreviation: \f3tur\f1
- .IN
- The input is the name of a turtle. You can only control one turtle
- at a time, so using this command a second time releases the turtle
- previously selected. The names of floor turtles are numbers like
- \f30\f1 and \f31\f1. If you are using
- a graphics display terminal (not just a text display trminal), you can
- control the display turtle by using the word \f3display\f1 (or the
- abbreviation \f3dpy\f1) as the turtle name. (As usual, the word
- must be preceded by a quotation mark.) If you use a graphics primitive
- without selecting a turtle, Logo assumes that you want to use the
- display turtle. But once you select a floor turtle, you must say
- \f3turtle "display\f1 explicitly to switch to the display.
- .sp 1
- The word \f3off\f1 as input to the \f3turtle\f1 command releases a floor
- turtle, if you have one, or turns off the graphics display if you have
- been using the display turtle. This also happens when you leave Logo.
- .OU
- \f3forward\f1 \(em Command, one input. Abbreviation: \f3fd\f1
- .IN
- The input is a number, the distance you would like the turtle
- to move. For a floor turtle, the unit of distance is however
- far the turtle can travel in 1/30 second. For a display turtle,
- the unit is one dot on the TV screen. (Note: on some displays, one
- dot horizontally may not be the same length as one dot vertically. The
- \f3setscrunch\f1 command allows you to control the
- relative sizes so that squares come out
- square.) The turtle moves in whatever direction it is pointing
- when you use the command.
- .OU
- \f3back\f1 \(em Command, one input. Abbreviation: \f3bk\f1
- .IN
- The input is a number, a distance to move, as in the \f3forward\f1
- command. The difference is that the turtle moves backward, i.e.,
- in the direction exactly opposite to the way it's pointing.
- .OU
- \f3left\f1 \(em Command, one input. Abbreviation: \f3lt\f1
- .IN
- The input is a number, the number of degrees of angle through
- which the turtle should turn counterclockwise. This command
- does not change the \f2position\f1 of the turtle, but merely
- its \f2heading\f1 (the direction in which it points). The
- turn will be only approximately correct for the floor turtle,
- because of mechanical errors. For the display turtle, the
- angle will be perfectly reproducible, although it may not look
- quite right on the screen because of the difference in size
- between horizontal and vertical dots. Nevertheless, a display
- turtle program will work in the sense that when the turtle is
- supposed to return to its starting point, it will do so.
- .OU
- \f3right\f1 \(em Command, one input. Abbreviation: \f3rt\f1
- .IN
- The input is a number; the turtle turns through the specified
- number of degrees clockwise.
- .OU
- \f3penup\f1 \(em Command, no inputs. Abbreviation: \f3pu\f1
- .IN
- This command tells the turtle to raise its pen from the paper,
- so that it does not leave a trace when it moves. In the case
- of the display turtle, there is no physical pen to move
- mechanically, but the effect is the same: any \f3forward\f1 or
- \f3back\f1 commands after this point do not draw a line. The
- floor turtle starts with its pen up; the display turtle starts
- with its pen down. Note: the floor turtle will not move on
- the carpet correctly with its pen down; put it on a smooth
- surface if you want to draw pictures.
- .OU
-