\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename ucblogo.info
@settitle BERKELEY LOGO 6.1
@setchapternewpage odd
@c %**end of header

@iftex
@vsize = 8.9 in
@parskip = 7 pt
@parindent = 0 pt
@hyphenation{set-scrunch set-write-pos}
@end iftex

@ifinfo
@paragraphindent 0
@end ifinfo

@finalout

@titlepage
@title BERKELEY LOGO 6.1
@subtitle Berkeley Logo User Manual
@author Brian Harvey
@end titlepage
 

@shortcontents
@contents


@c      Node,   Next, Previous, Up
@node   Top, INTRODUCTION, (dir), (dir)

@ifinfo

This is a TeXinfo version of Berkeley Logo User Manual

Original written by: Brian Harvey

@end ifinfo


@menu
* INTRODUCTION::                
* DATA STRUCTURE PRIMITIVES::   
* COMMUNICATION::               
* ARITHMETIC::                  
* LOGICAL OPERATIONS::          
* GRAPHICS::                    
* WORKSPACE MANAGEMENT::        
* CONTROL STRUCTURES::          
* MACROS::                      
* ERROR PROCESSING::            
* SPECIAL VARIABLES::           
* INTERNATIONALIZATION::        
* INDEX::                       
@end menu


@c      Node,   Next, Previous, Up
@node  INTRODUCTION, DATA STRUCTURE PRIMITIVES, Top, Top
@chapter Introduction

@menu
* OVERVIEW::                    
* GETTER/SETTER VARIBLE SYNTAX::  
* ENTERING AND LEAVING LOGO::   
* TOKENIZATION::                
@end menu


@c      Node,   Next, Previous, Up
@node   OVERVIEW, GETTER/SETTER VARIBLE SYNTAX, INTRODUCTION, INTRODUCTION
@section Overview

@cindex Copyright
@cindex Computer_Science_Logo_Style

Copyright @copyright{} 1993 by the Regents of the University of California

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but @var{WITHOUT ANY WARRANTY}; without even the implied warranty of
@var{MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE}.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

This is a program that is still being written.  Many things are missing,
including adequate documentation.  This manual assumes that you already know
how to program in Logo, and merely presents the details of this new
implementation.  

Read @cite{Computer Science Logo Style, Volume 1: 
 Symbolic Computing} by Brian Harvey (MIT Press, 1997) for a tutorial
on Logo programming with emphasis on symbolic computation.

Here are the special features of this dialect of Logo:

@display

Source file compatible among Unix, DOS, Windows, and Mac platforms.

Random-access arrays.

Variable number of inputs to user-defined procedures.

Mutators for list structure (dangerous).

Pause on error, and other improvements to error handling.

Comments and continuation lines; formatting is preserved when
procedure definitions are saved or edited.

Terrapin-style tokenization (e.g., [2+3] is a list with one member)
but LCSI-style syntax (no special forms except TO).  The best of
both worlds.

First-class instruction and expression templates (see APPLY).

Macros.
@end display

Features @strong{not} found in Berkeley Logo include robotics, music,
animation, parallelism, and multimedia.  For those, buy a commercial version.


@node GETTER/SETTER VARIBLE SYNTAX, ENTERING AND LEAVING LOGO, OVERVIEW, INTRODUCTION
@comment  node-name,  next,  previous,  up
@section Getter/Setter Variable Syntax
@cindex getter
@cindex setter

Logo distinguishes @var{procedures} from @var{variables}.  A procedure
is a set of instructions to carry out some computation; a variable is a
named container that holds a data value such as a number, word, list, or
array.

In traditional Logo syntax, a non-numeric word typed without punctuation
represents a request to invoke the procedure named by that word.  A word
typed with a preceding quotation mark represents the word itself.  For
example, in the instruction
@example
	PRINT FIRST "WORD
@end example
the procedures named @code{FIRST} and @code{PRINT} are invoked, but the
procedure named @var{WORD} is not invoked; the word @var{W-O-R-D} is the
input to FIRST.

What about variables?  There are two things one can do with a variable:
give it a value, and find out its value.  To give a variable a value,
Logo provides the primitive procedure @code{MAKE}, which requires two
inputs: the name of the variable and the new value to be assigned.  The
first input, the name of the variable, is just a word, and if (as is
almost always the case) the programmer wants to assign a value to a
specific variable whose name is known in advance, that input is quoted,
just as any known specific word would be:
@example
	MAKE "MY.VAR FIRST "WORD
@end example
gives the variable named @code{MY.VAR} the value @code{W} (the first letter of
@code{WORD}).

To find the value of a variable, Logo provides the primitive procedure
@code{THING}, which takes a variable name as its input, and outputs the value
of the accessible variable with that name.  Thus
@example
	PRINT THING "MY.VAR
@end example
will print @code{W} (supposing the @code{MAKE} above has been done).  Since
finding the value of a specific, known variable name is such a common
operation, Logo also provides an abbreviated notation that combines
@code{THING} with quote:
@example
	PRINT :MY.VAR
@end example
The colon (which Logo old-timers pronounce "dots") replaces @code{THING}
and @code{"} in the earlier version of the instruction.

Newcomers to Logo often complain about the need for all this punctuation.
In particular, Logo programmers who learned about dots and quotes without
also learning about @code{THING} wonder why an instruction such as
@example
	MAKE "NEW.VAR :OLD.VAR
@end example
uses two different punctuation marks to identify the two variables.
(Having read the paragraphs above, you will understand that actually
both variable names are quoted, but the procedure @code{THING} is
invoked to find the value of @code{OLD.VAR}, since it's that value, not
@code{OLD.VAR}'s name, that @code{MAKE} needs to know.  It wouldn't make
sense to ask for @code{THING} of @code{NEW.VAR}, since we haven't given
@code{NEW.VAR} a value yet.)

Although Logo's punctuation rules make sense once understood, they
do form a barrier to entry for the Logo beginner.  Why, then, couldn't
Logo be designed so that an unpunctuated word would represent a
procedure if there is a procedure by that name, or a variable if
there is a variable by that name?  Then we could say
@example
	PRINT MY.VAR
@end example
and Logo would realize that @code{MY.VAR} is the name of a variable, not
of a procedure.  The traditional reason not to use this convention
is that Logo allows the same word to name a procedure and a variable
at the same time.  This is most often important for words that name
data types, as in the following procedure:
@example
	TO PLURAL :WORD
	OUTPUT WORD :WORD "S
	END
@end example
Here the name @code{WORD} is a natural choice for the input to @code{PLURAL}, since
it describes the kind of input that @code{PLURAL} expects.  Within the procedure,
we use @code{WORD} to represent Logo's primitive procedure that combines two
input words to form a new, longer word; we use @code{:WORD} to represent the
variable containing the input, whatever actual word is given when
@code{PLURAL} is invoked.
@example
	? PRINT PLURAL "COMPUTER
	COMPUTERS
@end example

However, if a Logo instruction includes an unquoted word that is @strong{not}
the name of a procedure, Logo could look for a variable of that name instead.
This would allow a "punctuationless" Logo, @strong{provided that users who
want to work without colons for variables choose variable names that are not
also procedure names.}

What about assigning a value to a variable?  Could we do without the
quotation mark on @code{MAKE}'s first input?  Alas, no.  Although the
first input to @code{MAKE} is @strong{usually} a constant, known
variable name, sometimes it isn't, as in this example:
@example
	TO INCREMENT :VAR
	MAKE :VAR (THING :VAR)+1	; Note: it's not "VAR here!
	END

	? MAKE "X 5
	? INCREMENT "X
	? PRINT :X
	6
@end example
The procedure @code{INCREMENT} takes a variable name as its input and
changes the value of that variable.  In this example there are two
variables; the variable whose name is @code{VAR}, and whose value is the
word @code{X}; and the variable whose name is @code{X} and whose value changes
from 5 to 6.  Suppose we changed the behavior of @code{MAKE} so that it
took the word after @code{MAKE} as the name of the variable to change;
we would be unable to write @code{INCREMENT}:
@example
	TO INCREMENT :VAR		; nonworking!
	MAKE VAR (THING VAR)+1
	END
@end example
This would assign a new value to @code{VAR}, not to @code{X}.

What we can do is to allow an @strong{alternative} to @code{MAKE}, a
"setter" procedure for a particular variable.  The notation will be
@example
	? SETFOO 7
	? PRINT FOO
	7
@end example
@code{SETFOO} is a "setter procedure" that takes one input (in this case
the input 7) and assigns its value to the variable named @code{FOO}.

Berkeley Logo allows users to choose either the traditional notation, in
which case the same name can be used both for a procedure and for a
variable, or the getter/setter notation, in which variable @code{FOO} is
set with @code{SETFOO} and examined with @code{FOO}, but the same name
can't be used for procedure and variable.

Here is how this choice is allowed: Berkeley Logo uses traditional
notation, with procedures distinct from variables.  However, if there is
a variable named @code{AllowGetSet} whose value is TRUE (which
there is, by default, when Logo starts up), then if a Logo instruction
refers to a @strong{nonexistent} procedure (so that the error message
"I don't know how to ..." would result), Logo tries the following two
steps:
@cindex AllowGetSet

@display
	1.  If the name is at least four characters long, and the first three
	characters are the letters @code{SET} (upper or lower case), and if the name
	is followed in the instruction by another value, and if the name
	without the @code{SET} is the name of a variable that already exists, then
	Logo will invoke @code{MAKE} with its first input being the name without the
	@code{SET}, and its second input being the following value.

	2.  If step 1's conditions are not met, but the name is
	the name of an accessible variable, then Logo will invoke
	@code{THING} with that name as input, to find the variable's value.
@end display

Step 1 requires that the variable already exist so that misspellings of names
of @code{SETxxx} primitives (e.g., @code{SETHEADING}) will still be caught, instead of
silently creating a new variable.  The command @code{GLOBAL} can be used to create
a variable without giving it a value.

One final point:  The @code{TO} command in Logo has always been a special
case; the rest of the line starting with @code{TO} is not evaluated as
ordinary Logo expressions are.  In particular, the colons used to
mark the names of inputs to the procedure do not cause @code{THING} to be
invoked.  They are merely mnemonic aids, reminding the Logo user
that these words are names of variables.  (Arguably, this nonstantard
behavior of @code{TO} adds to Logo beginners' confusion about colons.)
To a programmer using colonless variable references, the colons in
the @code{TO} line are unnecessary and meaningless.  Berkeley Logo therefore
makes the colons optional:
@example
	TO FOO :IN1 :IN2
@end example
and
@example
	TO FOO IN1 IN2
@end example
are both allowed.


@node   ENTERING AND LEAVING LOGO, TOKENIZATION, GETTER/SETTER VARIBLE SYNTAX, INTRODUCTION
@section Entering and Leaving Logo

@cindex starting @t{ucblogo}
@cindex leaving @t{ucblogo}

The process to start Logo depends on your operating system:

@table @asis
@item Unix:
Type the word @t{logo} to the shell.  (The directory in which you've
installed Logo must be in your path.)

@item DOS:
Change directories to the one containing Logo (probably
@code{C:\UCBLOGO}).  Then type @t{UCBLOGO} for the large memory
version, or @t{BL} for the 640K version.

@item Mac:
Double-click on the @code{LOGO} icon within the "UCB Logo" folder. 

@item Windows:
Double-click on the @code{UCBWLOGO} icon in the @code{UCBLOGO} folder.
@end table

To leave Logo, enter the command @code{bye}.

On startup, Logo looks for a file named @file{startup.lg} in the system Logo
library and, if found, loads it.  Then it looks for @file{startup.lg} in the
user's home directory, or the current directory, depending on the operating
system, and loads that.  These startup files can be used to predefine
procedures, e.g., to provide non-English names for primitive procedures.

Under Unix, DOS, or Windows, if you include one or more filenames on the
command line when starting Logo, those files will be loaded before the
interpreter starts reading commands from your terminal.  If you load a file
that executes some program that includes a @code{bye} command, Logo will run
that program and exit.  You can therefore write standalone programs in Logo
and run them with shell/batch scripts.  To support this technique, Logo does
not print its usual welcoming and parting messages if you give file arguments
to the logo command.

If a command line argument is just a hyphen, then all command line arguments
after the hyphen are not taken as filenames, but are instead collected in a
list, one word per argument; the buried variable @code{COMMAND.LINE} contains
that list of arguments, or the empty list if there are none.  On my Linux
system, if the first line of an executable shell script is
@w{@t{#!/usr/local/bin/logo -}} (note the hyphen) then the script can be given
command line arguments and they all end up in @code{:COMMAND.LINE} along with
the script's path.  Experiment.

If you type your interrupt character (see table below) Logo will stop what
it's doing and return to top-level, as if you did @w{@t{THROW "TOPLEVEL}}.  If
you type your quit character Logo will pause as if you did @code{PAUSE}.

@example
            wxWidgets      Unix       DOS/Windows     Mac Classic

toplevel      alt-S   usually ctrl-C    ctrl-Q     command-. (period)

pause         alt-P   usually ctrl-\    ctrl-W     command-, (comma)
@end example

If you have an environment variable called @code{LOGOLIB} whose value is the
name of a directory, then Logo will use that directory instead of the default
library.  If you invoke a procedure that has not been defined, Logo first
looks for a file in the current directory named @file{@var{proc}.lg} where
@var{proc} is the procedure name in lower case letters.  If such a file
exists, Logo loads that file.  If the missing procedure is still undefined, or
if there is no such file, Logo then looks in the library directory for a file
named @file{@var{proc}} (no @file{.lg}) and, if it exists, loads it.  If
neither file contains a definition for the procedure, then Logo signals an
error.  Several procedures that are primitive in most versions of Logo are
included in the default library, so if you use a different library you may
want to include some or all of the default library in it.


@node   TOKENIZATION,  , ENTERING AND LEAVING LOGO, INTRODUCTION
@section Tokenization

Names of procedures, variables, and property lists are case-insensitive.  So
are the special words @code{END}, @code{TRUE}, and @code{FALSE}.  Case of
letters is preserved in everything you type, however.

@cindex case-insensitive
@cindex delimiters
@cindex runparsing
@cindex line-continuation
@cindex comments

Within square brackets, words are delimited only by spaces and square
brackets.  @code{[2+3]} is a list containing one word.  Note, however, that
the Logo primitives that interpret such a list as a Logo instruction or
expression (@code{RUN}, @code{IF}, etc.) reparse the list as if it had not
been typed inside brackets.

After a quotation mark outside square brackets, a word is delimited by
a space, a square bracket, or a parenthesis.

A word not after a quotation mark or inside square brackets is delimited by a
space, a bracket, a parenthesis, or an infix operator @code{+-*/=<>}.  Note
that words following colons are in this category.  Note that quote and colon
are not delimiters.  Each infix operator character is a word in itself, except
that the two-character sequences @code{<=}, @code{>=}, and @code{<>} (the
latter meaning not-equal) with no intervening space are recognized as a single
word.

A word consisting of a question mark followed by a number (e.g., @code{?37}),
when runparsed (i.e., where a procedure name is expected), is treated
as if it were the sequence

@example
( ? 37 )
@end example

making the number an input to the ? procedure.  (See the discussion of
templates, below.)  This special treatment does not apply to words read
as data, to words with a non-number following the question mark, or if
the question mark is backslashed.

A line (an instruction line or one read by @code{READLIST} or @code{READWORD})
can be continued onto the following line if its last character is a tilde (@code{~}).
@code{READWORD} preserves the tilde and the newline; @code{READLIST} does not.

Lines read with @code{READRAWLINE} are never continued.

An instruction line or a line read by @code{READLIST} (but not by @code{READWORD})
is automatically continued to the next line, as if ended with a tilde,
if there are unmatched brackets, parentheses, braces, or vertical bars
pending.  However, it's an error if the continuation line contains
only the word @code{END}; this is to prevent runaway procedure definitions.
Lines explicitly continued with a tilde avoid this restriction.

If a line being typed interactively on the keyboard is continued, either
with a tilde or automatically, Logo will display a tilde as a prompt
character for the continuation line.

A semicolon begins a comment in an instruction line.  Logo ignores
characters from the semicolon to the end of the line.  A tilde as the
last character still indicates a continuation line, but not a continuation
of the comment.  For example, typing the instruction

@example
print "abc;comment ~
def
@end example

will print the word @code{abcdef}.  Semicolon has no special meaning in data
lines read by @code{READWORD} or @code{READLIST}, but such a line can later be reparsed
using @code{RUNPARSE} and then comments will be recognized.

The two-character sequence @code{#!}@: at the beginning of a line also starts a
comment.  Unix users can therefore write a file containing Logo commands,
starting with the line
@example
#! /usr/local/bin/logo
@end example
(or wherever your Logo executable lives) and the file will be executable
directly from the shell.

To include an otherwise delimiting character (including semicolon or tilde)
in a word, precede it with backslash (@code{\}).  If the last character of a line
is a backslash, then the newline character following the backslash will be
part of the last word on the line, and the line continues onto the following
line.  To include a backslash in a word, use @code{\\}.  If the combination
backslash-newline is entered at the terminal, Logo will issue a backslash as
a prompt character for the continuation line.  All of this applies to data
lines read with @code{READWORD} or @code{READLIST} as well as to instruction lines.

A line read with @code{READRAWLINE} has no special quoting mechanism; both
backslash and vertical bar (described below) are just ordinary characters.

An alternative notation to include otherwise delimiting characters in words
is to enclose a group of characters in vertical bars.  All characters between
vertical bars are treated as if they were letters.  In data read with @code{READWORD}
the vertical bars are preserved in the resulting word.  In data read with
@code{READLIST} (or resulting from a @code{PARSE} or @code{RUNPARSE} of a word) the vertical bars
do not appear explicitly; all potentially delimiting characters (including
spaces, brackets, parentheses, and infix operators) appear unmarked, but
tokenized as though they were letters.  Within vertical bars, backslash may
still be used; the only characters that must be backslashed in this context
are backslash and vertical bar themselves.

Characters entered between vertical bars are forever special, even if the
word or list containing them is later reparsed with @code{PARSE} or @code{RUNPARSE}.
Characters typed after a backslash are treated somewhat differently:  When a
quoted word containing a backslashed character is runparsed, the backslashed
character loses its special quality and acts thereafter as if typed normally.
This distinction is important only if you are building a Logo expression out
of parts, to be @code{RUN} later, and want to use parentheses.  For example,

@example
PRINT RUN (SE "\( 2 "+ 3 "\))
@end example

will print 5, but

@example
RUN (SE "MAKE ""|(| 2)
@end example

will create a variable whose name is open-parenthesis.  (Each example would
fail if vertical bars and backslashes were interchanged.)

A normally delimiting character entered within vertical bars is @code{EQUALP}
to the same character without the vertical bars, but can be distinguished by
the @code{VBARREDP} predicate.  (However, @code{VBARREDP} returns @code{TRUE}
only for characters for which special treatment is necessary: whitespace,
parentheses, brackets, infix operators, backslash, vertical bar, tilde, quote,
question mark, colon, and semicolon.)


@node   DATA STRUCTURE PRIMITIVES, COMMUNICATION, INTRODUCTION, Top
@chapter Data Structure Primitives

@menu
* CONSTRUCTORS::                
* SELECTORS::                   
* MUTATORS::                    
* PREDICATES::                  
* QUERIES::                     
@end menu


@node  CONSTRUCTORS, SELECTORS, DATA STRUCTURE PRIMITIVES, DATA STRUCTURE PRIMITIVES
@section Constructors

@menu
* WORD::                        
* LIST::                        
* SENTENCE::                    
* FPUT::                        
* LPUT::                        
* ARRAY::                       
* MDARRAY::                     
* LISTTOARRAY::                 
* ARRAYTOLIST::                 
* COMBINE::                     
* REVERSE::                     
* GENSYM::                      
@end menu


@node  WORD, LIST, CONSTRUCTORS, CONSTRUCTORS
@unnumberedsubsec word
@cindex word

@example
WORD word1 word2
(WORD word1 word2 word3 ...)
@end example

outputs a word formed by concatenating its inputs.

@node  LIST, SENTENCE, WORD, CONSTRUCTORS
@unnumberedsubsec list
@cindex list

@example
LIST thing1 thing2
(LIST thing1 thing2 thing3 ...)
@end example

outputs a list whose members are its inputs, which can be any Logo datum
(word, list, or array).


@node  SENTENCE, FPUT, LIST, CONSTRUCTORS
@unnumberedsubsec sentence
@cindex sentence
@cindex se

@example
SENTENCE thing1 thing2
SE thing1 thing2
(SENTENCE thing1 thing2 thing3 ...)
(SE thing1 thing2 thing3 ...)
@end example

outputs a list whose members are its inputs, if those inputs are not
lists, or the members of its inputs, if those inputs are lists.

@node  FPUT, LPUT, SENTENCE, CONSTRUCTORS
@unnumberedsubsec fput
@cindex fput

@example
FPUT thing list
@end example

outputs a list equal to its second input with one extra member, the
first input, at the beginning.  If the second input is a word,
then the first input must be a one-letter word, and FPUT is
equivalent to WORD.



@node  LPUT, ARRAY, FPUT, CONSTRUCTORS
@unnumberedsubsec lput
@cindex lput

@example
LPUT thing list
@end example

outputs a list equal to its second input with one extra member, the
first input, at the end.  If the second input is a word,
then the first input must be a one-letter word, and LPUT is
equivalent to WORD with its inputs in the other order.

@node  ARRAY, MDARRAY, LPUT, CONSTRUCTORS
@unnumberedsubsec array
@cindex array

@example
ARRAY size
(ARRAY size origin)
@end example

outputs an array of @var{size} members (must be a positive integer), each of
which initially is an empty list.  Array members can be selected with
@code{ITEM} and changed with @code{SETITEM}.  The first member of the array is member
number 1 unless an @var{origin} input (must be an integer) is given, in
which case the first member of the array has that number as its index.
(Typically 0 is used as the origin if anything.)  Arrays are printed by
@code{PRINT} and friends, and can be typed in, inside curly braces; indicate an
origin with @w{@t{@{a b c@}@@0}}.


@xref{ITEM} ,
@ref{SETITEM} ,
@ref{PRINT} .

@node  MDARRAY, LISTTOARRAY, ARRAY, CONSTRUCTORS
@unnumberedsubsec mdarray
@cindex mdarray

@example
MDARRAY sizelist				(library procedure)
(MDARRAY sizelist origin)
@end example

outputs a multi-dimensional array.  The first input must be a list of
one or more positive integers.  The second input, if present, must be a
single integer that applies to every dimension of the array.  

Ex: @w{@t{(MDARRAY [3 5] 0)}} outputs a two-dimensional array whose members
range from @w{@t{[0 0]}} to @w{@t{[2 4]}}.


@node  LISTTOARRAY, ARRAYTOLIST, MDARRAY, CONSTRUCTORS
@unnumberedsubsec listtoarray
@cindex listtoarray

@example
LISTTOARRAY list
(LISTTOARRAY list origin)
@end example

outputs an array of the same size as the input list, whose members are
the members of the input list.


@node  ARRAYTOLIST, COMBINE, LISTTOARRAY, CONSTRUCTORS
@unnumberedsubsec arraytolist
@cindex arraytolist

@example
ARRAYTOLIST array
@end example

outputs a list whose members are the members of the input array.  The
first member of the output is the first member of the array, regardless
of the array's origin.


@node  COMBINE, REVERSE, ARRAYTOLIST, CONSTRUCTORS
@unnumberedsubsec combine
@cindex combine

@example
COMBINE thing1 thing2				(library procedure)
@end example

if @var{thing2} is a word, outputs @w{@t{WORD thing1 thing2}}.  If @var{thing2}
is a list, outputs @w{@t{FPUT thing1 thing2}}.

@xref{WORD} ,
@ref{FPUT}

@node  REVERSE, GENSYM, COMBINE, CONSTRUCTORS
@unnumberedsubsec reverse
@cindex reverse

@example
REVERSE list					(library procedure)
@end example

outputs a list whose members are the members of the input list, in
reverse order.

@node  GENSYM,  , REVERSE, CONSTRUCTORS
@unnumberedsubsec gensym
@cindex gensym

@example
GENSYM						(library procedure)
@end example

outputs a unique word each time it's invoked.  The words are of the form
@code{G1}, @code{G2}, etc.

@node  SELECTORS, MUTATORS, CONSTRUCTORS, DATA STRUCTURE PRIMITIVES
@section Data Selectors

@menu
* FIRST::                       
* FIRSTS::                      
* LAST::                        
* BUTFIRST::                    
* BUTFIRSTS::                   
* BUTLAST::                     
* ITEM::                        
* MDITEM::                      
* PICK::                        
* REMOVE::                      
* REMDUP::                      
* QUOTED::                      
@end menu

@node FIRST, FIRSTS, SELECTORS, SELECTORS
@unnumberedsubsec first
@cindex first

@example
FIRST thing
@end example

if the input is a word, outputs the first character of the word.  If the
input is a list, outputs the first member of the list.  If the input is
an array, outputs the origin of the array (that is, the @emph{index of} the
first member of the array).

@node FIRSTS, LAST, FIRST, SELECTORS
@unnumberedsubsec firsts
@cindex firsts

@example
FIRSTS list
@end example

outputs a list containing the @code{FIRST} of each member of the input list.
It is an error if any member of the input list is empty.  (The input
itself may be empty, in which case the output is also empty.)  This
could be written as

@example
to firsts :list
output map "first :list
end
@end example

but is provided as a primitive in order to speed up the iteration tools
@code{MAP}, @code{MAP.SE}, and @code{FOREACH}.

@example
to transpose :matrix
if emptyp first :matrix [op []]
op fput firsts :matrix transpose bfs :matrix
end
@end example

@xref{MAP} ,
@ref{MAPdSE} ,
@ref{FOREACH}

@node LAST, BUTFIRST, FIRSTS, SELECTORS
@unnumberedsubsec last
@cindex last

@example
LAST wordorlist
@end example

if the input is a word, outputs the last character of the word.  If the
input is a list, outputs the last member of the list.

@node BUTFIRST, BUTFIRSTS, LAST, SELECTORS
@unnumberedsubsec butfirst
@cindex butfirst
@cindex bf

@example
BUTFIRST wordorlist
BF wordorlist
@end example

if the input is a word, outputs a word containing all but the first
character of the input.  If the input is a list, outputs a list
containing all but the first member of the input.

@node BUTFIRSTS, BUTLAST, BUTFIRST, SELECTORS
@unnumberedsubsec butfirsts
@cindex butfirsts
@cindex bfs

@example
BUTFIRSTS list
BFS list
@end example

outputs a list containing the @code{BUTFIRST} of each member of the input list.
It is an error if any member of the input list is empty or an array.
(The input itself may be empty, in which case the output is also empty.)
This could be written as

@example
to butfirsts :list
output map "butfirst :list
end
@end example

but is provided as a primitive in order to speed up the iteration tools
@code{MAP}, @code{MAP.SE}, and @code{FOREACH}.

@xref{MAP} ,
@ref{MAPdSE} ,
@ref{FOREACH}

@node BUTLAST, ITEM, BUTFIRSTS, SELECTORS
@unnumberedsubsec butlast
@cindex butlast
@cindex bl

@example
BUTLAST wordorlist
BL wordorlist
@end example

if the input is a word, outputs a word containing all but the last
character of the input.  If the input is a list, outputs a list
containing all but the last member of the input.

@node ITEM, MDITEM, BUTLAST, SELECTORS
@unnumberedsubsec item
@cindex item

@example
ITEM index thing
@end example

if the @var{thing} is a word, outputs the @var{index}th character of the word.
If the @var{thing} is a list, outputs the @var{index}th member of the list.  If
the @var{thing} is an array, outputs the @var{index}th member of the array.
@var{Index} starts at 1 for words and lists; the starting index of an array
is specified when the array is created.

@node MDITEM, PICK, ITEM, SELECTORS
@unnumberedsubsec mditem
@cindex mditem

@example
MDITEM indexlist array				(library procedure)
@end example

outputs the member of the multidimensional @var{array} selected by the list
of numbers @var{indexlist}.

@node PICK, REMOVE, MDITEM, SELECTORS
@unnumberedsubsec pick
@cindex pick

@example
PICK list					(library procedure)
@end example

outputs a randomly chosen member of the input list.

@node REMOVE, REMDUP, PICK, SELECTORS
@unnumberedsubsec remove
@cindex remove

@example
REMOVE thing list				(library procedure)
@end example

outputs a copy of @var{list} with every member equal to @var{thing} removed.

@node REMDUP, QUOTED, REMOVE, SELECTORS
@unnumberedsubsec remdup
@cindex remdup

@example
REMDUP list					(library procedure)
@end example

outputs a copy of @var{list} with duplicate members removed.  If two or more
members of the input are equal, the rightmost of those members is the
one that remains in the output.

@node QUOTED,  , REMDUP, SELECTORS
@unnumberedsubsec quoted
@cindex quoted

@example
QUOTED thing					(library procedure)
@end example

outputs its input, if a list; outputs its input with a quotation mark
prepended, if a word.



@node  MUTATORS, PREDICATES, SELECTORS, DATA STRUCTURE PRIMITIVES
@section Data Mutators

@menu
* SETITEM::                     
* MDSETITEM::                   
* dSETFIRST::                   SETFIRST  
* dSETBF::                      SETBF
* dSETITEM::                    SETITEM
* PUSH::                        
* POP::                         
* QUEUE::                       
* DEQUEUE::                     
@end menu


@node SETITEM, MDSETITEM, MUTATORS, MUTATORS
@unnumberedsubsec setitem
@cindex setitem

@example
SETITEM index array value
@end example

command.  Replaces the @var{index}th member of @var{array} with the new @var{value}.
Ensures that the resulting array is not circular, i.e., @var{value} may not
be a list or array that contains @var{array}.

@node MDSETITEM, dSETFIRST, SETITEM, MUTATORS
@unnumberedsubsec mdsetitem
@cindex mdsetitem

@example
MDSETITEM indexlist array value			(library procedure)
@end example

command.  Replaces the member of @var{array} chosen by @var{indexlist} with the
new @var{value}.

@node dSETFIRST, dSETBF, MDSETITEM, MUTATORS
@unnumberedsubsec .setfirst
@cindex .setfirst

@example
.SETFIRST list value
@end example

command.  Changes the first member of @var{list} to be @var{value}.

WARNING: Primitives whose names start with a period are @strong{dangerous}.
Their use by non-experts is not recommended.  The use of @code{.SETFIRST} can
lead to circular list structures, which will get some Logo primitives
into infinite loops, and to unexpected changes to other data structures that
share storage with the list being modified.

@node dSETBF, dSETITEM, dSETFIRST, MUTATORS
@unnumberedsubsec .setbf
@cindex .setbf

@example
.SETBF list value
@end example

command.  Changes the butfirst of @var{list} to be @var{value}.
	
WARNING: Primitives whose names start with a period are @strong{dangerous}.
Their use by non-experts is not recommended.  The use of @code{.SETBF} can lead
to circular list structures, which will get some Logo primitives into
infinite loops; unexpected changes to other data structures that share
storage with the list being modified; or to Logo crashes and coredumps if the
butfirst of a list is not itself a list.

@node dSETITEM, PUSH, dSETBF, MUTATORS
@unnumberedsubsec .setitem
@cindex .setitem

@example
.SETITEM index array value
@end example

command.  Changes the @var{index}th member of @var{array} to be @var{value},
like @code{SETITEM}, but without checking for circularity.

WARNING: Primitives whose names start with a period are @b{dangerous}.
Their use by non-experts is not recommended.  The use of @code{.SETITEM} can
lead to circular arrays, which will get some Logo primitives into
infinite loops.

@xref{SETITEM}.

@node PUSH, POP, dSETITEM, MUTATORS
@unnumberedsubsec push
@cindex push

@example
PUSH stackname thing				(library procedure)
@end example

command.  Adds the @var{thing} to the stack that is the value of the
variable whose name is @var{stackname}.  This variable must have a list as
its value; the initial value should be the empty list.  New members are
added at the front of the list.

@node POP, QUEUE, PUSH, MUTATORS
@unnumberedsubsec pop
@cindex pop

@example
POP stackname					(library procedure)
@end example

outputs the most recently @code{PUSH}ed member of the stack that is the value
of the variable whose name is @var{stackname} and removes that member from
the stack.

@node QUEUE, DEQUEUE, POP, MUTATORS
@unnumberedsubsec queue
@cindex queue

@example
QUEUE queuename thing				(library procedure)
@end example

command.  Adds the @var{thing} to the queue that is the value of the
variable whose name is @var{queuename}.  This variable must have a list as
its value; the initial value should be the empty list.  New members are
added at the back of the list.

@node DEQUEUE,  , QUEUE, MUTATORS
@unnumberedsubsec dequeue
@cindex dequeue
 
@example
DEQUEUE queuename				(library procedure)
@end example

outputs the least recently @code{QUEUE}d member of the queue that is the value
of the variable whose name is @var{queuename} and removes that member from
the queue.


@node  PREDICATES, QUERIES, MUTATORS, DATA STRUCTURE PRIMITIVES
@section Predicates

@menu
* WORDP::                       
* LISTP::                       
* ARRAYP::                      
* EMPTYP::                      
* EQUALP::                      
* NOTEQUALP::
* BEFOREP::                     
* dEQ::                         EQ
* MEMBERP::                     
* SUBSTRINGP::                  
* NUMBERP::                     
* VBARREDP::                
@end menu

@node  WORDP, LISTP, PREDICATES, PREDICATES
@unnumberedsubsec wordp
@cindex wordp

@example
WORDP thing
WORD? thing
@end example

outputs @code{TRUE} if the input is a word, @code{FALSE} otherwise.

@node  LISTP, ARRAYP, WORDP, PREDICATES
@unnumberedsubsec listp
@cindex listp
@cindex list?

@example
LISTP thing
LIST? thing
@end example

outputs @code{TRUE} if the input is a list, @code{FALSE} otherwise.

@node  ARRAYP, EMPTYP, LISTP, PREDICATES
@unnumberedsubsec arrayp
@cindex arrayp
@cindex array?

@example
ARRAYP thing
ARRAY? thing
@end example

outputs @code{TRUE} if the input is an array, @code{FALSE} otherwise.

@node  EMPTYP, EQUALP, ARRAYP, PREDICATES
@unnumberedsubsec emptyp
@cindex emptyp
@cindex empty?

@example
EMPTYP thing
EMPTY? thing
@end example

outputs @code{TRUE} if the input is the empty word or the empty list, @code{FALSE}
otherwise.

@node  EQUALP, NOTEQUALP, EMPTYP, PREDICATES
@unnumberedsubsec equalp
@cindex equalp
@cindex equal?
@cindex =

@example
EQUALP thing1 thing2
EQUAL? thing1 thing2
thing1 = thing2
@end example

outputs @code{TRUE} if the inputs are equal, @code{FALSE} otherwise.  Two numbers are
equal if they have the same numeric value.  Two non-numeric words are
equal if they contain the same characters in the same order.  If there
is a variable named @code{CASEIGNOREDP} whose value is @code{TRUE}, then an upper case
letter is considered the same as the corresponding lower case letter.
(This is the case by default.)  Two lists are equal if their members are
equal.  An array is only equal to itself; two separately created arrays
are never equal even if their members are equal.  (It is important to be
able to know if two expressions have the same array as their value
because arrays are mutable; if, for example, two variables have the same
array as their values then performing @code{SETITEM} on one of them will also
change the other.)

@xref{CASEIGNOREDP} ,
@ref{SETITEM}

@node  NOTEQUALP, BEFOREP, EQUALP, PREDICATES
@unnumberedsubsec notequalp
@cindex notequalp
@cindex notequal?
@cindex <>

@example
NOTEQUALP thing1 thing2
NOTEQUAL? thing1 thing2
thing1 <> thing2
@end example

outputs @code{FALSE} if the inputs are equal, @code{TRUE} otherwise.  See @code{EQUALP}
for the meaning of equality for different data types.

@node  BEFOREP, dEQ, NOTEQUALP, PREDICATES
@unnumberedsubsec beforep
@cindex beforep
@cindex before?

@example
BEFOREP word1 word2
BEFORE? word1 word2
@end example

outputs @code{TRUE} if @var{word1} comes before @var{word2} in ASCII collating sequence
(for words of letters, in alphabetical order).  Case-sensitivity is
determined by the value of @code{CASEIGNOREDP}.  Note that if the inputs are
numbers, the result may not be the same as with @code{LESSP}; for example,
@w{@t{BEFOREP 3 12}} is false because 3 collates after 1.

@xref{CASEIGNOREDP} ,
@ref{LESSP} 

@node  dEQ, MEMBERP, BEFOREP, PREDICATES
@unnumberedsubsec .eq
@cindex .eq

@example
.EQ thing1 thing2
@end example

outputs @code{TRUE} if its two inputs are the same datum, so that applying a
mutator to one will change the other as well.  Outputs @code{FALSE} otherwise,
even if the inputs are equal in value.  

WARNING: Primitives whose names start with a period are @strong{dangerous}.
Their use by non-experts is not recommended.  The use of mutators can
lead to circular data structures, infinite loops, or Logo crashes.

@node  MEMBERP, SUBSTRINGP, dEQ, PREDICATES
@unnumberedsubsec memberp
@cindex memberp
@cindex member?

@example
MEMBERP thing1 thing2
MEMBER? thing1 thing2
@end example

if @var{thing2} is a list or an array, outputs @code{TRUE} if @var{thing1} is
@code{EQUALP} to a member of @var{thing2}, @code{FALSE} otherwise.  If
@var{thing2} is a word, outputs @code{TRUE} if @var{thing1} is a one-character
word @code{EQUALP} to a character of @var{thing2}, @code{FALSE} otherwise.

@xref{EQUALP} .

@node  SUBSTRINGP, NUMBERP, MEMBERP, PREDICATES
@unnumberedsubsec substringp
@cindex substringp
@cindex substring?

@example
SUBSTRINGP thing1 thing2
SUBSTRING? thing1 thing2
@end example

if @var{thing1} or @var{thing2} is a list or an array, outputs @code{FALSE}.  If
@var{thing2} is a word, outputs @code{TRUE} if @var{thing1} is @code{EQUALP} to a substring of
@var{thing2}, @code{FALSE} otherwise.

@xref{EQUALP} .

@node  NUMBERP, VBARREDP, SUBSTRINGP, PREDICATES
@unnumberedsubsec numberp
@cindex numberp
@cindex number?

@example
NUMBERP thing
NUMBER? thing
@end example

outputs @code{TRUE} if the input is a number, @code{FALSE} otherwise.

@node  VBARREDP,  , NUMBERP, PREDICATES
@unnumberedsubsec vbarredp
@cindex vbarredp
@cindex vbarred?

@example
VBARREDP char
VBARRED? char
BACKSLASHEDP char                               (library procedure)
BACKSLASHED? char                               (library procedure)
@end example

outputs @code{TRUE} if the input character was originally entered into Logo
within vertical bars (|) to prevent its usual special syntactic meaning,
@code{FALSE} otherwise.  (Outputs @code{TRUE} only if the character is a
backslashed space, tab, newline, or one of @code{()[]+-*/=<>":;\~?|} )

The names @code{BACKSLASHEDP} and @code{BACKSLASHED?}@: are included in the
Logo library for backward compatibility with the former names of this
primitive, although it does @emph{not} output @code{TRUE} for characters
originally entered with backslashes.



@node  QUERIES,  , PREDICATES, DATA STRUCTURE PRIMITIVES
@section Queries

@menu
* COUNT::                       
* ASCII::                       
* RAWASCII::                    
* CHAR::                        
* MEMBER::                      
* LOWERCASE::                   
* UPPERCASE::                   
* STANDOUT::                    
* PARSE::                       
* RUNPARSE::                    
@end menu


@node  COUNT, ASCII, QUERIES, QUERIES
@unnumberedsubsec count
@cindex count

@example
COUNT thing
@end example

outputs the number of characters in the input, if the input is a word;
outputs the number of members in the input, if it is a list or an array.
(For an array, this may or may not be the index of the last member,
depending on the array's origin.)

@node  ASCII, RAWASCII, COUNT, QUERIES
@unnumberedsubsec ascii
@cindex ascii

@example
ASCII char
@end example

outputs the integer (between 0 and 255) that represents the input
character in the ASCII code.  Interprets control characters as
representing vbarred punctuation, and returns the character code for
the corresponding punctuation character without vertical bars.  (Compare
@code{RAWASCII}.)

@node  RAWASCII, CHAR, ASCII, QUERIES
@unnumberedsubsec rawascii
@cindex rawascii

@example
RAWASCII char
@end example

outputs the integer (between 0 and 255) that represents the input
character in the ASCII code.  Interprets control characters as
representing themselves.  To find out the ASCII code of an arbitrary
keystroke, use @w{@t{RAWASCII RC}}.

@node  CHAR, MEMBER, RAWASCII, QUERIES
@unnumberedsubsec char
@cindex char

@example
CHAR int
@end example

outputs the character represented in the ASCII code by the input, which
must be an integer between 0 and 255.

@xref{ASCII} .

@node  MEMBER, LOWERCASE, CHAR, QUERIES
@unnumberedsubsec member
@cindex member

@example
MEMBER thing1 thing2
@end example

if @var{thing2} is a word or list and if @code{MEMBERP} with these inputs would
output @code{TRUE}, outputs the portion of @var{thing2} from the first instance of
@var{thing1} to the end.  If @code{MEMBERP} would output @code{FALSE}, outputs the empty
word or list according to the type of @var{thing2}.  It is an error for
@var{thing2} to be an array.

@xref{MEMBERP} .

@node  LOWERCASE, UPPERCASE, MEMBER, QUERIES
@unnumberedsubsec lowercase
@cindex lowercase

@example
LOWERCASE word
@end example

outputs a copy of the input word, but with all uppercase letters changed
to the corresponding lowercase letter.

@node  UPPERCASE, STANDOUT, LOWERCASE, QUERIES
@unnumberedsubsec uppercase
@cindex uppercase

@example
UPPERCASE word
@end example

outputs a copy of the input word, but with all lowercase letters changed
to the corresponding uppercase letter.

@node  STANDOUT, PARSE, UPPERCASE, QUERIES
@unnumberedsubsec standout
@cindex standout

@example
STANDOUT thing
@end example

outputs a word that, when printed, will appear like the input but
displayed in standout mode (boldface, reverse video, or whatever your
version does for standout).  The word contains machine-specific magic
characters at the beginning and end; in between is the printed form (as
if displayed using @code{TYPE}) of the input.  The output is always a word,
even if the input is of some other type, but it may include spaces and
other formatting characters.  Note: a word output by @code{STANDOUT} while Logo
is running on one machine will probably not have the desired effect if
printed on another type of machine.

In the Macintosh classic version, the way that standout works is incompatible with the
use of characters whose ASCII code is greater than 127.  Therefore, you
have a choice to make:  The instruction 
@example
CANINVERSE 0 
@end example
disables standout, but enables the display of ASCII codes above 127, and
the instruction
@example
CANINVERSE 1 
@end example
restores the default situation in which standout is enabled and the
extra graphic characters cannot be printed.

@node  PARSE, RUNPARSE, STANDOUT, QUERIES
@unnumberedsubsec parse
@cindex parse

@example
PARSE word
@end example

outputs the list that would result if the input word were entered in
response to a @code{READLIST} operation.  That is, @w{@t{PARSE READWORD}} has the same
value as @code{READLIST} for the same characters read.

@xref{READLIST} ,
@ref{READWORD}

@node  RUNPARSE,  , PARSE, QUERIES
@unnumberedsubsec runparse
@cindex runparse

@example
RUNPARSE wordorlist
@end example

outputs the list that would result if the input word or list were
entered as an instruction line; characters such as infix operators and
parentheses are separate members of the output.  Note that sublists of a
runparsed list are not themselves runparsed.



@node   COMMUNICATION, ARITHMETIC, DATA STRUCTURE PRIMITIVES, Top
@chapter Communication

@menu
* TRANSMITTERS::                
* RECEIVERS::                   
* FILE ACCESS::                 
* TERMINAL ACCESS::             
@end menu


@node  TRANSMITTERS, RECEIVERS, COMMUNICATION, COMMUNICATION
@section Transmitters

@menu
* PRINT::                       
* TYPE::                        
* SHOW::                        
@end menu

Note:  If there is a variable named @code{PRINTDEPTHLIMIT} with a nonnegative
integer value, then complex list and array structures will be printed
only to the allowed depth.  That is, members of members of... of members
will be allowed only so far.  The members omitted because
they are just past the depth limit are indicated by an ellipsis for each
one, so a too-deep list of two members will print as @w{@t{[... ...]}}.

If there is a variable named @code{PRINTWIDTHLIMIT} with a nonnegative integer
value, then only the first so many members of any array or
list will be printed.  A single ellipsis replaces all missing data
within the structure.  The width limit also applies to the number of
characters printed in a word, except that a @code{PRINTWIDTHLIMIT} between 0 and 9
will be treated as if it were 10 when applied to words.  This limit
applies not only to the top-level printed datum but to any substructures
within it.

@xref{PRINTDEPTHLIMIT} ,
@ref{PRINTWIDTHLIMIT}

If there is a variable named @code{FULLPRINTP} whose value is @code{TRUE}, then
words that were created using backslash or vertical bar (to include
characters that would otherwise not be treated as part of a word) are
printed with the backslashes or vertical bars shown, so that the printed
result could be re-read by Logo to produce the same value.  If
@code{FULLPRINTP} is @code{TRUE} then the empty word (however it was created) prints
as @code{||}.  (Otherwise it prints as nothing at all.)

@xref{FULLPRINTP} .

@node  PRINT, TYPE, TRANSMITTERS, TRANSMITTERS
@unnumberedsubsec print
@cindex print
@cindex pr

@example
PRINT thing
PR thing
(PRINT thing1 thing2 ...)
(PR thing1 thing2 ...)
@end example

command.  Prints the input or inputs to the current write stream
(initially the screen).  All the inputs are printed on a single line,
separated by spaces, ending with a newline.  If an input is a list,
square brackets are not printed around it, but brackets are printed
around sublists.  Braces are always printed around arrays.

@node  TYPE, SHOW, PRINT, TRANSMITTERS
@unnumberedsubsec type
@cindex type

@example
TYPE thing
(TYPE thing1 thing2 ...)
@end example

command.  Prints the input or inputs like @code{PRINT}, except that no newline
character is printed at the end and multiple inputs are not separated by
spaces.  Note: printing to the screen is ordinarily @dfn{line buffered};
that is, the characters you print using @code{TYPE} will not actually appear on
the screen until either a newline character is printed (for example, by
@code{PRINT} or @code{SHOW}) or Logo tries to read from the keyboard (either at the
request of your program or after an instruction prompt).  This buffering
makes the program much faster than it would be if each character
appeared immediately, and in most cases the effect is not disconcerting.
To accommodate programs that do a lot of positioned text display using
@code{TYPE}, Logo will force printing whenever @code{SETCURSOR} is invoked.  This
solves most buffering problems.  Still, on occasion you may find it
necessary to force the buffered characters to be printed explicitly;
this can be done using the @code{WAIT} command.  @w{@t{WAIT 0}} will force printing
without actually waiting.

@xref{SETCURSOR} ,
@ref{WAIT}

@node  SHOW,  , TYPE, TRANSMITTERS
@unnumberedsubsec show
@cindex show

@example
SHOW thing
(SHOW thing1 thing2 ...)
@end example

command.  Prints the input or inputs like @code{PRINT}, except that if an input
is a list it is printed inside square brackets.

@xref{PRINT} .


@node  RECEIVERS, FILE ACCESS, TRANSMITTERS, COMMUNICATION
@section Receivers

@menu
* READLIST::                    
* READWORD::                    
* READRAWLINE::                 
* READCHAR::                    
* READCHARS::                   
* SHELL::                       
@end menu


@node  READLIST, READWORD, RECEIVERS, RECEIVERS
@unnumberedsubsec readlist
@cindex readlist
@cindex rl

@example
READLIST
RL
@end example

reads a line from the read stream (initially the keyboard) and outputs
that line as a list.  The line is separated into members as though it
were typed in square brackets in an instruction.  If the read stream is
a file, and the end of file is reached, @code{READLIST} outputs the empty word
(not the empty list).  @code{READLIST} processes backslash, vertical bar, and
tilde characters in the read stream; the output list will not contain
these characters but they will have had their usual effect.  @code{READLIST}
does not, however, treat semicolon as a comment character.

@node  READWORD, READRAWLINE, READLIST, RECEIVERS
@unnumberedsubsec readword
@cindex readword
@cindex rw

@example
READWORD
RW
@end example

reads a line from the read stream and outputs that line as a word.  The
output is a single word even if the line contains spaces, brackets, etc.
If the read stream is a file, and the end of file is reached, @code{READWORD}
outputs the empty list (not the empty word).  @code{READWORD} processes
backslash, vertical bar, and tilde characters in the read stream.  In
the case of a tilde used for line continuation, the output word @emph{does}
include the tilde and the newline characters, so that the user program
can tell exactly what the user entered.  Vertical bars in the line are
also preserved in the output.  Backslash characters are not preserved in
the output.


@node READRAWLINE, READCHAR, READWORD, RECEIVERS
@comment  node-name,  next,  previous,  up
@unnumberedsubsec readrawline
@cindex readrawline

@example
READRAWLINE
@end example

reads a line from the read stream and outputs that line as a word.  The
output is a single word even if the line contains spaces, brackets, etc.
If the read stream is a file, and the end of file is reached, @code{READRAWLINE}
outputs the empty list (not the empty word).  @code{READRAWLINE} outputs the
exact string of characters as they appear in the line, with no special
meaning for backslash, vertical bar, tilde, or any other formatting
characters.

@xref{READWORD} .

@node  READCHAR, READCHARS, READRAWLINE, RECEIVERS
@unnumberedsubsec readchar
@cindex readchar
@cindex rc

@example
READCHAR
RC
@end example

reads a single character from the read stream and outputs that character
as a word.  If the read stream is a file, and the end of file is
reached, @code{READCHAR} outputs the empty list (not the empty word).  If the
read stream is the keyboard, echoing is turned off when @code{READCHAR} is
invoked, and remains off until @code{READLIST} or @code{READWORD} is invoked or a Logo
prompt is printed.  Backslash, vertical bar, and tilde characters have
no special meaning in this context.

@xref{READLIST} .

@node  READCHARS, SHELL, READCHAR, RECEIVERS
@unnumberedsubsec readchars
@cindex readchars
@cindex rcs

@example
READCHARS num
RCS num
@end example

reads @var{num} characters from the read stream and outputs those characters
as a word.  If the read stream is a file, and the end of file is
reached, @code{READCHARS} outputs the empty list (not the empty word).  If the
read stream is the keyboard, echoing is turned off when @code{READCHARS} is
invoked, and remains off until @code{READLIST} or @code{READWORD} is invoked or a Logo
prompt is printed.  Backslash, vertical bar, and tilde characters have
no special meaning in this context.

@xref{READLIST} ,
@ref{READWORD}

@node  SHELL,  , READCHARS, RECEIVERS
@unnumberedsubsec shell
@cindex shell

@example
SHELL command
(SHELL command wordflag)
@end example

Under Unix, outputs the result of running @var{command} as a shell command.
(The command is sent to @samp{/bin/sh}, not @samp{csh} or other alternatives.)
If the command is a literal list in the instruction line, and if you want a
backslash character sent to the shell, you must use @code{\\} to get the
backslash through Logo's reader intact.  The output is a list containing
one member for each line generated by the shell command.  Ordinarily
each such line is represented by a list in the output, as though the
line were read using @code{READLIST}.  If a second input is given, regardless
of the value of the input, each line is represented by a word in the
output as though it were read with @code{READWORD}.  Example:

@example
to dayofweek
output first first shell [date]
end
@end example

This is @code{first first} to extract the first word of the first (and only)
line of the shell output.

Under MacOS X, @code{SHELL} works as under Unix.  @code{SHELL} is not
available under Mac Classic.

Under DOS, @code{SHELL} is a command, not an operation; it sends its input to a
DOS command processor but does not collect the result of the command.

Under Windows, the wxWidgets version of Logo behaves as under Unix (except
that DOS-style commands are understood; use @code{dir} rather than @code{ls}).
The non-wxWidgets version behaves like the DOS version.


@node  FILE ACCESS, TERMINAL ACCESS, RECEIVERS, COMMUNICATION
@section File Access

@menu
* SETPREFIX::                   
* PREFIX::                      
* OPENREAD::                    
* OPENWRITE::                   
* OPENAPPEND::                  
* OPENUPDATE::                  
* CLOSE::                       
* ALLOPEN::                     
* CLOSEALL::                    
* ERASEFILE::                   
* DRIBBLE::                     
* NODRIBBLE::                   
* SETREAD::                     
* SETWRITE::                    
* READER::                      
* WRITER::                      
* SETREADPOS::                  
* SETWRITEPOS::                 
* READPOS::                     
* WRITEPOS::                    
* EOFP::                        
* FILEP::                       
@end menu


@node SETPREFIX, PREFIX, FILE ACCESS, FILE ACCESS
@comment  node-name,  next,  previous,  up
@unnumberedsubsec setprefix
@cindex setprefix

@example
SETPREFIX string
@end example

command.  Sets a prefix that will be used as the implicit beginning of
filenames in @code{OPENREAD}, @code{OPENWRITE}, @code{OPENAPPEND},
@code{OPENUPDATE}, @code{LOAD}, and @code{SAVE} commands.  Logo will put the
appropriate separator character (slash for Unix, backslash for DOS/Windows,
colon for MacOS Classic) between the prefix and the filename entered by the
user.  The input to @code{SETPREFIX} must be a word, unless it is the empty list, to
indicate that there should be no prefix.

@xref{OPENREAD} , 
@xref{OPENWRITE} ,
@xref{OPENAPPEND} ,
@xref{OPENUPDATE} ,
@xref{LOAD} ,
@xref{SAVE} .

@node PREFIX, OPENREAD, SETPREFIX, FILE ACCESS
@comment  node-name,  next,  previous,  up
@unnumberedsubsec prefix
@cindex prefix

@example
PREFIX
@end example

outputs the current file prefix, or [] if there is no prefix.

@xref{SETPREFIX} .


@node  OPENREAD, OPENWRITE, PREFIX, FILE ACCESS
@unnumberedsubsec openread
@cindex openread

@example
OPENREAD filename
@end example

command.  Opens the named file for reading.  The read position is
initially at the beginning of the file.

@node  OPENWRITE, OPENAPPEND, OPENREAD, FILE ACCESS
@unnumberedsubsec openwrite
@cindex openwrite

@example
OPENWRITE filename
@end example

command.  Opens the named file for writing.  If the file already
existed, the old version is deleted and a new, empty file created.

@code{OPENWRITE}, but not the other @code{OPEN} variants, will accept as input
a two-element list, in which the first element must be a variable
name, and the second must be a positive integer.  A character
buffer of the specified size will be created.  When a @code{SETWRITE} is
done with this same list (in the sense of .EQ, not a copy, so
you must do something like

@example
? make "buf [foo 100]
? openwrite :buf
? setwrite :buf
    [...]
? close :buf
@end example

and not just

@example
? openwrite [foo 100]
? setwrite [foo 100]
@end example

and so on), the printed characters are stored in the buffer;
when a @code{CLOSE} is done with the same list as input, the characters
from the buffer (treated as one long word, even if spaces and
newlines are included) become the value of the specified variable.

@node  OPENAPPEND, OPENUPDATE, OPENWRITE, FILE ACCESS
@unnumberedsubsec openappend
@cindex openappend

@example
OPENAPPEND filename
@end example

command.  Opens the named file for writing.  If the file already exists,
the write position is initially set to the end of the old file, so that
newly written data will be appended to it.

@node  OPENUPDATE, CLOSE, OPENAPPEND, FILE ACCESS
@unnumberedsubsec openupdate
@cindex openupdate

@example
OPENUPDATE filename
@end example

command.  Opens the named file for reading and writing.  The read and
write position is initially set to the end of the old file, if any.
Note: each open file has only one position, for both reading and
writing.  If a file opened for update is both @code{READER} and @code{WRITER} at the
same time, then @code{SETREADPOS} will also affect @code{WRITEPOS} and vice versa.
Also, if you alternate reading and writing the same file, you must
@code{SETREADPOS} between a write and a read, and @code{SETWRITEPOS} between a read
and a write.

@xref{READER} ,
@ref{WRITER} ,
@ref{SETREADPOS} ,
@ref{SETWRITEPOS}

@node  CLOSE, ALLOPEN, OPENUPDATE, FILE ACCESS
@unnumberedsubsec close
@cindex close

@example
CLOSE filename
@end example

command.  Closes the named file.  If the file was currently the
reader or writer, then the reader or writer is changed to the
keyboard or screen, as if @w{@t{SETREAD []}} or @w{@t{SETWRITE []}} had been done.


@node  ALLOPEN, CLOSEALL, CLOSE, FILE ACCESS
@unnumberedsubsec allopen
@cindex allopen

@example
ALLOPEN
@end example

outputs a list whose members are the names of all files currently open.
This list does not include the dribble file, if any.

@node  CLOSEALL, ERASEFILE, ALLOPEN, FILE ACCESS
@unnumberedsubsec closeall
@cindex closeall

@example
CLOSEALL					(library procedure)
@end example

command. Closes all open files. Abbreviates @w{@t{FOREACH ALLOPEN [CLOSE ?]}}

@xref{FOREACH} ,
@ref{CLOSE}

@node  ERASEFILE, DRIBBLE, CLOSEALL, FILE ACCESS
@unnumberedsubsec erasefile
@cindex erasefile
@cindex erf

@example
ERASEFILE filename
ERF filename
@end example

command.  Erases (deletes, removes) the named file, which should not
currently be open.

@node  DRIBBLE, NODRIBBLE, ERASEFILE, FILE ACCESS
@unnumberedsubsec dribble
@cindex dribble

@example
DRIBBLE filename
@end example

command.  Creates a new file whose name is the input, like @code{OPENWRITE},
and begins recording in that file everything that is read from the
keyboard or written to the terminal.  That is, this writing is in
addition to the writing to @code{WRITER}.  The intent is to create a transcript
of a Logo session, including things like prompt characters and
interactions.

@xref{OPENWRITE} ,
@ref{WRITER}

@node  NODRIBBLE, SETREAD, DRIBBLE, FILE ACCESS
@unnumberedsubsec nodribble
@cindex nodribble

@example
NODRIBBLE
@end example

command.  Stops copying information into the dribble file, and closes
the file.

@node  SETREAD, SETWRITE, NODRIBBLE, FILE ACCESS
@unnumberedsubsec setread
@cindex setread

@example
SETREAD filename
@end example

command.  Makes the named file the read stream, used for @code{READLIST}, etc.
The file must already be open with @code{OPENREAD} or @code{OPENUPDATE}.  If the input
is the empty list, then the read stream becomes the keyboard, as usual.
Changing the read stream does not close the file that was previously the
read stream, so it is possible to alternate between files.

@xref{READLIST} ,
@ref{OPENREAD} ,
@ref{OPENUPDATE}

@node  SETWRITE, READER, SETREAD, FILE ACCESS
@unnumberedsubsec setwrite
@cindex setwrite

@example
SETWRITE filename
@end example

command.  Makes the named file the write stream, used for @code{PRINT},
etc.  The file must already be open with @code{OPENWRITE}, @code{OPENAPPEND}, or
@code{OPENUPDATE}.  If the input is the empty list, then the write stream
becomes the screen, as usual.  Changing the write stream does
not close the file that was previously the write stream, so it is
possible to alternate between files.

If the input is a list, then its first element must be a variable
name, and its second and last element must be a positive integer; a
buffer of that many characters will be allocated, and will become the
writestream.  If the same list (same in the @code{.EQ} sense, not a copy)
has been used as input to @code{OPENWRITE}, then the already-allocated
buffer will be used, and the writer can be changed to and from this
buffer, with all the characters accumulated as in a file.  When the
same list is used as input to @code{CLOSE}, the contents of the buffer
(as an unparsed word, which may contain newline characters) will
become the value of the named variable.  For compatibility with
earlier versions, if the list has not been opened when the @code{SETWRITE}
is done, it will be opened implicitly, but the first @code{SETWRITE} after
this one will implicitly close it, setting the variable and freeing
the allocated buffer.

@xref{PRINT} ,
@ref{OPENWRITE} ;
@ref{OPENAPPEND} ;
@ref{OPENUPDATE}

@node  READER, WRITER, SETWRITE, FILE ACCESS
@unnumberedsubsec reader
@cindex reader

@example
READER
@end example

outputs the name of the current read stream file, or the empty list if
the read stream is the terminal.

@node  WRITER, SETREADPOS, READER, FILE ACCESS
@unnumberedsubsec writer
@cindex writer

@example
WRITER
@end example

outputs the name of the current write stream file, or the empty list if
the write stream is the screen.

@node  SETREADPOS, SETWRITEPOS, WRITER, FILE ACCESS
@unnumberedsubsec setreadpos
@cindex setreadpos

@example
SETREADPOS charpos
@end example

command.  Sets the file pointer of the read stream file so that the next
@code{READLIST}, etc., will begin reading at the @var{charpos}th character in the
file, counting from 0.  (That is, @w{@t{SETREADPOS 0}} will start reading from
the beginning of the file.)  Meaningless if the read stream is the
keyboard.

@xref{READLIST} .

@node  SETWRITEPOS, READPOS, SETREADPOS, FILE ACCESS
@unnumberedsubsec setwritepos
@cindex setwritepos

@example
SETWRITEPOS charpos
@end example

command.  Sets the file pointer of the write stream file so that the
next @code{PRINT}, etc., will begin writing at the @var{charpos}th character in the
file, counting from 0.  (That is, @w{@t{SETWRITEPOS 0}} will start writing from
the beginning of the file.)  Meaningless if the write stream is the
screen.

@xref{PRINT} .

@node  READPOS, WRITEPOS, SETWRITEPOS, FILE ACCESS
@unnumberedsubsec readpos
@cindex readpos

@example
READPOS
@end example

outputs the file position of the current read stream file.

@node  WRITEPOS, EOFP, READPOS, FILE ACCESS
@unnumberedsubsec writepos
@cindex writepos

@example
WRITEPOS
@end example

outputs the file position of the current write stream file.

@node  EOFP, FILEP, WRITEPOS, FILE ACCESS
@unnumberedsubsec eofp
@cindex eofp
@cindex eof?

@example
EOFP
EOF?
@end example

predicate, outputs @code{TRUE} if there are no more characters to be read in
the read stream file, @code{FALSE} otherwise.

@node  FILEP,  , EOFP, FILE ACCESS
@unnumberedsubsec filep
@cindex filep
@cindex file?

@example
FILEP filename
FILE? filename					(library procedure)
@end example

predicate, outputs @code{TRUE} if a file of the specified name exists and can
be read, @code{FALSE} otherwise.


@node  TERMINAL ACCESS,  , FILE ACCESS, COMMUNICATION
@section Terminal Access

@menu
* KEYP::                        
* CLEARTEXT::                   
* SETCURSOR::                   
* CURSOR::                      
* SETMARGINS::                  
* SETTEXTCOLOR::                
* INCREASEFONT::
* SETTEXTSIZE::
* TEXTSIZE::
* SETFONT::
* FONT::
@end menu


@node  KEYP, CLEARTEXT, TERMINAL ACCESS, TERMINAL ACCESS
@unnumberedsubsec keyp
@cindex keyp
@cindex key?

@example
KEYP
KEY?
@end example

predicate, outputs @code{TRUE} if there are characters waiting to be read from
the read stream.  If the read stream is a file, this is equivalent to
@w{@t{NOT EOFP}}.  If the read stream is the terminal, then echoing is turned
off and the terminal is set to @code{cbreak} (character at a time instead of
line at a time) mode.  It remains in this mode until some line-mode
reading is requested (e.g., @code{READLIST}).  The Unix operating system
forgets about any pending characters when it switches modes, so the
first @code{KEYP} invocation will always output @code{FALSE}.

@xref{EOFP} ,
@ref{READLIST}

@node  CLEARTEXT, SETCURSOR, KEYP, TERMINAL ACCESS
@unnumberedsubsec cleartext
@cindex cleartext
@cindex ct

@example
CLEARTEXT
CT
@end example

command.  Clears the text window.

@node  SETCURSOR, CURSOR, CLEARTEXT, TERMINAL ACCESS
@unnumberedsubsec setcursor
@cindex setcursor

@example
SETCURSOR vector
@end example

command.  The input is a list of two numbers, the x and y coordinates of
a text window position (origin in the upper left corner, positive direction
is southeast).  The text cursor is moved to the requested position.
This command also forces the immediate printing of any buffered
characters.

@node  CURSOR, SETMARGINS, SETCURSOR, TERMINAL ACCESS
@unnumberedsubsec cursor
@cindex cursor

@example
CURSOR
@end example

outputs a list containing the current x and y coordinates of the text
cursor.  Logo may get confused about the current cursor position if,
e.g., you type in a long line that wraps around or your program prints
escape codes that affect the screen strangely.

@node  SETMARGINS, SETTEXTCOLOR, CURSOR, TERMINAL ACCESS
@unnumberedsubsec setmargins
@cindex setmargins

@example
SETMARGINS vector
@end example

command.  The input must be a list of two numbers, as for @code{SETCURSOR}.
The effect is to clear the screen and then arrange for all further
printing to be shifted down and to the right according to the indicated
margins.  Specifically, every time a newline character is printed
(explicitly or implicitly) Logo will type @var{x_margin} spaces, and on every
invocation of @code{SETCURSOR} the margins will be added to the input x and y
coordinates.  (@code{CURSOR} will report the cursor position relative to the
margins, so that this shift will be invisible to Logo programs.)  The
purpose of this command is to accommodate the display of terminal
screens in lecture halls with inadequate TV monitors that miss the top
and left edges of the screen.

@xref{SETCURSOR} .


@node  SETTEXTCOLOR, INCREASEFONT, SETMARGINS, TERMINAL ACCESS
@unnumberedsubsec settextcolor
@cindex settextcolor
@cindex settc

@example
SETTEXTCOLOR foreground background
SETTC foreground background
@end example

command (wxWidgets only).  The inputs are color numbers, or RGB color lists,
as for turtle graphics.  The foreground and background colors for the
textscreen/splitscreen text window are changed to the given values.  The
change affects text already printed as well as future text printing; there is
only one text color for the entire window.

Command (non-wxWidgets Windows and DOS extended only).  The inputs are color
numbers, as for turtle graphics.  Future printing to the text window will use
the specified colors for foreground (the characters printed) and background
(the space under those characters).  Using @code{STANDOUT} will revert to the default
text window colors.  In the DOS extended (@file{ucblogo.exe}) version, colors in
textscreen mode are limited to numbers 0-7, and the coloring applies only to
text printed by the program, not to the echoing of text typed by the user.
Neither limitation applies to the text portion of splitscreen mode, which is
actually drawn as graphics internally.

@xref{STANDOUT} .

@node  INCREASEFONT, SETTEXTSIZE, SETTEXTCOLOR, TERMINAL ACCESS
@unnumberedsubsec increasefont
@cindex increasefont
@cindex decreasefont

@example
INCREASEFONT
DECREASEFONT
@end example

command (wxWidgets only).  Increase or decrease the size of the font
used in the text and edit windows to the next larger or smaller
available size.

@node  SETTEXTSIZE, TEXTSIZE, INCREASEFONT, TERMINAL ACCESS
@unnumberedsubsec settextsize
@cindex settextsize

@example
SETTEXTSIZE height
@end example

command (wxWidgets only).  Set the "point size" of the font used in
the text and edit windows to the given integer input.  The desired
size may not be available, in which case the nearest available size
will be used.  Note: There is only a slight correlation between these
integers and pixel sizes.  Our rough estimate is that the number of
pixels of height is about 1.5 times the point size, but it varies for
different fonts.  See @code{SETLABELHEIGHT} for a different approach used for
the graphics window.

@node TEXTSIZE, SETFONT, SETTEXTSIZE, TERMINAL ACCESS
@unnumberedsubsec textsize
@cindex textsize

@example
TEXTSIZE
@end example

(wxWidgets only) outputs the "point size" of the font used in the text
and edit windows.  See @code{SETTEXTSIZE} for a discussion of font sizing.
See @code{LABELSIZE} for a different approach used for the graphics window.

@node SETFONT, FONT, TEXTSIZE, TERMINAL ACCESS
@unnumberedsubsec setfont
@cindex setfont

@example
SETFONT fontname
@end example

command (wxWidgets only).  Set the font family used in all windows
to the one named by the input.  Try @file{Courier} or @file{Monospace} as likely
possibilities.  Not all computers have the same fonts installed.  It's
a good idea to stick with monospace fonts (ones in which all
characters have the same width).

@node FONT, , SETFONT, TERMINAL ACCESS
@unnumberedsubsec font
@cindex font

@example
FONT
@end example

(wxWidgets only) outputs the name of the font family used in all
windows.



@node   ARITHMETIC, LOGICAL OPERATIONS, COMMUNICATION, Top
@chapter Arithmetic

@menu
* NUMERIC OPERATIONS::          
* NUMERIC PREDICATES::          
* RANDOM NUMBERS::              
* PRINT FORMATTING::            
* BITWISE OPERATIONS::          
@end menu



@node  NUMERIC OPERATIONS, NUMERIC PREDICATES, ARITHMETIC, ARITHMETIC
@section Numeric Operations

@menu
* SUM::                         
* DIFFERENCE::                  
* MINUS::                       
* PRODUCT::                     
* QUOTIENT::                    
* REMAINDER::                   
* MODULO::                      
* INT::                         
* ROUND::                       
* SQRT::                        
* POWER::                       
* EXP::                         
* LOG10::                       
* LN::                          
* SIN::                         
* RADSIN::                      
* COS::                         
* RADCOS::                      
* ARCTAN::                      
* RADARCTAN::                   
* ISEQ::                        
* RSEQ::                        
@end menu


@node  SUM, DIFFERENCE, NUMERIC OPERATIONS, NUMERIC OPERATIONS
@unnumberedsubsec sum
@cindex sum
@cindex +

@example
SUM num1 num2
(SUM num1 num2 num3 ...)
num1 + num2
@end example

outputs the sum of its inputs.

@node  DIFFERENCE, MINUS, SUM, NUMERIC OPERATIONS
@unnumberedsubsec difference
@cindex difference
@cindex -

@example
DIFFERENCE num1 num2
num1 - num2
@end example

outputs the difference of its inputs.  Minus sign means infix difference
in ambiguous contexts (when preceded by a complete expression), unless
it is preceded by a space and followed by a nonspace.  (See also @code{MINUS}.)

@node  MINUS, PRODUCT, DIFFERENCE, NUMERIC OPERATIONS
@unnumberedsubsec minus
@cindex minus

@example
MINUS num
- num
@end example

outputs the negative of its input.  Minus sign means unary minus if
the previous token is an infix operator or open parenthesis, or it is
preceded by a space and followed by a nonspace.  There is a difference
in binding strength between the two forms:

@example
MINUS 3 + 4     means   -(3+4)
- 3 + 4         means   (-3)+4
@end example

@node  PRODUCT, QUOTIENT, MINUS, NUMERIC OPERATIONS
@unnumberedsubsec product
@cindex product
@cindex *

@example
PRODUCT num1 num2
(PRODUCT num1 num2 num3 ...)
num1 * num2
@end example

outputs the product of its inputs.

@node  QUOTIENT, REMAINDER, PRODUCT, NUMERIC OPERATIONS
@unnumberedsubsec quotient
@cindex quotient
@cindex /

@example
QUOTIENT num1 num2
(QUOTIENT num)
num1 / num2
@end example

outputs the quotient of its inputs.  The quotient of two integers is an
integer if and only if the dividend is a multiple of the divisor.  (In
other words, @w{@t{QUOTIENT 5 2}} is 2.5, not 2, but @w{@t{QUOTIENT 4 2}}
is 2, not 2.0 --- it does the right thing.)  With a single input,
@code{QUOTIENT} outputs the reciprocal of the input.

@node  REMAINDER, MODULO, QUOTIENT, NUMERIC OPERATIONS
@unnumberedsubsec remainder
@cindex remainder

@example
REMAINDER num1 num2
@end example

outputs the remainder on dividing @var{num1} by @var{num2}; both must be
integers and the result is an integer with the same sign as @var{num1}.

@node  MODULO, INT, REMAINDER, NUMERIC OPERATIONS
@unnumberedsubsec modulo
@cindex modulo

@example
MODULO num1 num2
@end example

outputs the remainder on dividing @var{num1} by @var{num2}; both must be
integers and the result is an integer with the same sign as @var{num2}.

@node  INT, ROUND, MODULO, NUMERIC OPERATIONS
@unnumberedsubsec int
@cindex int

@example
INT num
@end example

outputs its input with fractional part removed, i.e., an integer
with the same sign as the input, whose absolute value is the
largest integer less than or equal to the absolute value of
the input.

@node  ROUND, SQRT, INT, NUMERIC OPERATIONS
@unnumberedsubsec round
@cindex round

@example
ROUND num
@end example

outputs the nearest integer to the input.

@node  SQRT, POWER, ROUND, NUMERIC OPERATIONS
@unnumberedsubsec sqrt
@cindex sqrt

@example
SQRT num
@end example

outputs the square root of the input, which must be nonnegative.

@node  POWER, EXP, SQRT, NUMERIC OPERATIONS
@unnumberedsubsec power
@cindex power

@example
POWER num1 num2
@end example

outputs @var{num1} to the @var{num2} power.  If @var{num1} is negative, then
@var{num2} must be an integer.

@node  EXP, LOG10, POWER, NUMERIC OPERATIONS
@unnumberedsubsec exp
@cindex exp

@example
EXP num
@end example

outputs @i{e} (2.718281828+) to the input power.

@node  LOG10, LN, EXP, NUMERIC OPERATIONS
@unnumberedsubsec log10
@cindex log10

@example
LOG10 num
@end example

outputs the common logarithm of the input.

@node  LN, SIN, LOG10, NUMERIC OPERATIONS
@unnumberedsubsec ln
@cindex ln

@example
LN num
@end example

outputs the natural logarithm of the input.

@node  SIN, RADSIN, LN, NUMERIC OPERATIONS
@unnumberedsubsec sin
@cindex sin

@example
SIN degrees
@end example

outputs the sine of its input, which is taken in degrees.

@node  RADSIN, COS, SIN, NUMERIC OPERATIONS
@unnumberedsubsec radsin
@cindex radsin

@example
RADSIN radians
@end example

outputs the sine of its input, which is taken in radians.

@node  COS, RADCOS, RADSIN, NUMERIC OPERATIONS
@unnumberedsubsec cos
@cindex cos

@example
COS degrees
@end example

outputs the cosine of its input, which is taken in degrees.

@node  RADCOS, ARCTAN, COS, NUMERIC OPERATIONS
@unnumberedsubsec radcos
@cindex radcos

@example
RADCOS radians
@end example

outputs the cosine of its input, which is taken in radians.

@node  ARCTAN, RADARCTAN, RADCOS, NUMERIC OPERATIONS
@unnumberedsubsec arctan
@cindex arctan

@example
ARCTAN num
(ARCTAN x y)
@end example

outputs the arctangent, in degrees, of its input.  With two inputs,
outputs the arctangent of y/x, if x is nonzero, or 90 or --90 depending
on the sign of y, if x is zero.

@node  RADARCTAN, ISEQ, ARCTAN, NUMERIC OPERATIONS
@unnumberedsubsec radarctan
@cindex radarctan

@example
RADARCTAN num
(RADARCTAN x y)
@end example

outputs the arctangent, in radians, of its input.  With two inputs,
outputs the arctangent of y/x, if x is nonzero, or pi/2 or --pi/2
depending on the sign of y, if x is zero.

The expression @w{@t{2*(RADARCTAN 0 1)}} can be used to get the value of pi.

@node  ISEQ, RSEQ, RADARCTAN, NUMERIC OPERATIONS
@unnumberedsubsec iseq
@cindex iseq

@example
ISEQ from to					(library procedure)
@end example

outputs a list of the integers from @var{from} to @var{to}, inclusive.

@example
? show iseq 3 7
[3 4 5 6 7]
? show iseq 7 3
[7 6 5 4 3]
@end example

@node  RSEQ,  , ISEQ, NUMERIC OPERATIONS
@unnumberedsubsec rseq
@cindex rseq

@example
RSEQ from to count				(library procedure)
@end example

outputs a list of @var{count} equally spaced rational numbers between
@var{from} and @var{to}, inclusive.

@example
? show rseq 3 5 9 
[3 3.25 3.5 3.75 4 4.25 4.5 4.75 5] 
? show rseq 3 5 5
[3 3.5 4 4.5 5]
@end example


@node  NUMERIC PREDICATES, RANDOM NUMBERS, NUMERIC OPERATIONS, ARITHMETIC
@section  Numeric Predicates 

@menu
* LESSP::                       
* GREATERP::                    
* LESSEQUALP::                    
* GREATEREQUALP::                    

@end menu


@node  LESSP, GREATERP, NUMERIC PREDICATES, NUMERIC PREDICATES
@unnumberedsubsec lessp
@cindex lessp
@cindex less?
@cindex <

@example
LESSP num1 num2
LESS? num1 num2
num1 < num2
@end example

outputs @code{TRUE} if its first input is strictly less than its second.

@node  GREATERP, LESSEQUALP, LESSP, NUMERIC PREDICATES
@unnumberedsubsec greaterp
@cindex greaterp
@cindex greater?
@cindex >

@example
GREATERP num1 num2
GREATER? num1 num2
num1 > num2
@end example

outputs @code{TRUE} if its first input is strictly greater than its second.

@node  LESSEQUALP, GREATEREQUALP, GREATERP, NUMERIC PREDICATES
@unnumberedsubsec lessequalp
@cindex lessequalp
@cindex lessequal?
@cindex <=

@example
LESSEQUALP num1 num2
LESSEQUAL? num1 num2
num1 <= num2
@end example

outputs @code{TRUE} if its first input is less than or equal to its second.

@node  GREATEREQUALP,  , LESSEQUALP, NUMERIC PREDICATES
@unnumberedsubsec greaterequalp
@cindex greaterequalp
@cindex greaterequal?
@cindex >=

@example
GREATEREQUALP num1 num2
GREATEREQUAL? num1 num2
num1 >= num2
@end example

outputs @code{TRUE} if its first input is greater than or equal to its second.


@node  RANDOM NUMBERS, PRINT FORMATTING, NUMERIC PREDICATES, ARITHMETIC
@section  Random Numbers

@menu
* RANDOM::                      
* RERANDOM::                    
@end menu


@node  RANDOM, RERANDOM, RANDOM NUMBERS, RANDOM NUMBERS
@unnumberedsubsec random
@cindex random

@example
RANDOM num
(RANDOM start end)
@end example

with one input, outputs a random nonnegative integer less than its
input, which must be a positive integer.

With two inputs, @code{RANDOM} outputs a random integer greater than or
equal to the first input, and less than or equal to the second
input.  Both inputs must be integers, and the first must be less
than the second.  @w{@t{(RANDOM 0 9)}} is equivalent to @w{@t{RANDOM 10}};
@w{@t{(RANDOM 3 8)}} is equivalent to @w{@t{(RANDOM 6)+3}}.

@node  RERANDOM,  , RANDOM, RANDOM NUMBERS
@unnumberedsubsec rerandom
@cindex rerandom

@example
RERANDOM
(RERANDOM seed)
@end example

command.  Makes the results of @code{RANDOM} reproducible.  Ordinarily the
sequence of random numbers is different each time Logo is used.  If you need
the same sequence of pseudo-random numbers repeatedly, e.g. to debug a
program, say @code{RERANDOM} before the first invocation of @code{RANDOM}.  If
you need more than one repeatable sequence, you can give @code{RERANDOM} an integer
input; each possible input selects a unique sequence of numbers.


@node  PRINT FORMATTING, BITWISE OPERATIONS, RANDOM NUMBERS, ARITHMETIC
@section Print Formatting

@menu
* FORM::                        
@end menu


@node  FORM,  , PRINT FORMATTING, PRINT FORMATTING
@unnumberedsubsec form
@cindex form

@example
FORM num width precision
@end example

outputs a word containing a printable representation of @var{num}, possibly
preceded by spaces (and therefore not a number for purposes of
performing arithmetic operations), with at least @var{width} characters,
including exactly @var{precision} digits after the decimal point.  (If
@var{precision} is 0 then there will be no decimal point in the output.)

As a debugging feature, (@w{@t{FORM num -1 format}}) will print the floating
point @var{num} according to the C printf @var{format}, to allow

@example
to hex :num
op form :num -1 "|%08X %08X|
end
@end example

to allow finding out the exact result of floating point operations.  The
precise format needed may be machine-dependent.


@node  BITWISE OPERATIONS,  , PRINT FORMATTING, ARITHMETIC
@section Bitwise Operations

@menu
* BITAND::                      
* BITOR::                       
* BITXOR::                      
* BITNOT::                      
* ASHIFT::                      
* LSHIFT::                      
@end menu


@node  BITAND, BITOR, BITWISE OPERATIONS, BITWISE OPERATIONS
@unnumberedsubsec bitand
@cindex bitand 

@example
BITAND num1 num2
(BITAND num1 num2 num3 ...)
@end example

outputs the bitwise @var{and} of its inputs, which must be integers.

@xref{AND} .

@node  BITOR, BITXOR, BITAND, BITWISE OPERATIONS
@unnumberedsubsec bitor
@cindex bitor

@example
BITOR num1 num2
(BITOR num1 num2 num3 ...)
@end example

outputs the bitwise @var{or} of its inputs, which must be integers.

@xref{OR} .

@node  BITXOR, BITNOT, BITOR, BITWISE OPERATIONS
@unnumberedsubsec bitxor
@cindex bitxor

@example
BITXOR num1 num2
(BITXOR num1 num2 num3 ...)
@end example

outputs the bitwise @var{exclusive or} of its inputs, which must be integers.

@xref{OR} .

@node  BITNOT, ASHIFT, BITXOR, BITWISE OPERATIONS
@unnumberedsubsec bitnot
@cindex bitnot

@example
BITNOT num
@end example

outputs the bitwise @var{not} of its input, which must be an integer.

@xref{NOT} .

@node  ASHIFT, LSHIFT, BITNOT, BITWISE OPERATIONS
@unnumberedsubsec ashift
@cindex ashift

@example
ASHIFT num1 num2
@end example

outputs @var{num1} arithmetic-shifted to the left by @var{num2} bits.  If
@var{num2} is negative, the shift is to the right with sign extension.  The
inputs must be integers.

@node  LSHIFT,  , ASHIFT, BITWISE OPERATIONS
@unnumberedsubsec lshift
@cindex lshift

@example
LSHIFT num1 num2
@end example

outputs @var{num1} logical-shifted to the left by @var{num2} bits.  If
@var{num2} is negative, the shift is to the right with zero fill.  The inputs
must be integers.



@node   LOGICAL OPERATIONS, GRAPHICS, ARITHMETIC, Top
@chapter Logical Operations

@menu
* AND::                         
* OR::                          
* NOT::                         
@end menu


@node  AND, OR, LOGICAL OPERATIONS, LOGICAL OPERATIONS
@unnumberedsec and
@cindex and

@example
AND tf1 tf2
(AND tf1 tf2 tf3 ...)
@end example

outputs @code{TRUE} if all inputs are @code{TRUE}, otherwise @code{FALSE}.  All inputs
must be @code{TRUE} or @code{FALSE}.  (Comparison is case-insensitive regardless
of the value of @code{CASEIGNOREDP}.  That is, @code{true} or @code{True} or @code{TRUE}
are all the same.)  An input can be a list, in which case it is
taken as an expression to run; that expression must produce a @code{TRUE}
or @code{FALSE} value.  List expressions are evaluated from left to right;
as soon as a @code{FALSE} value is found, the remaining inputs are not
examined.  Example:

@example
MAKE "RESULT AND [NOT (:X = 0)] [(1 / :X) > .5]
@end example

to avoid the division by zero if the first part is false.

@xref{CASEIGNOREDP} .

@node  OR, NOT, AND, LOGICAL OPERATIONS
@unnumberedsubsec or
@cindex or

@example
OR tf1 tf2
(OR tf1 tf2 tf3 ...)
@end example

outputs @code{TRUE} if any input is @code{TRUE}, otherwise @code{FALSE}.  All inputs
must be @code{TRUE} or @code{FALSE}.  (Comparison is case-insensitive regardless
of the value of @code{CASEIGNOREDP}.  That is, @code{true} or @code{True} or @code{TRUE}
are all the same.)  An input can be a list, in which case it is
taken as an expression to run; that expression must produce a @code{TRUE}
or @code{FALSE} value.  List expressions are evaluated from left to right;
as soon as a @code{TRUE} value is found, the remaining inputs are not
examined.  Example:

@example
IF OR :X=0 [some.long.computation] [...]
@end example

to avoid the long computation if the first condition is met.

@xref{CASEIGNOREDP} .

@node  NOT,  , OR, LOGICAL OPERATIONS
@unnumberedsubsec not
@cindex not

@example
NOT tf
@end example

outputs @code{TRUE} if the input is @code{FALSE}, and vice versa.  The input can be
a list, in which case it is taken as an expression to run; that
expression must produce a @code{TRUE} or @code{FALSE} value.


@node   GRAPHICS, WORKSPACE MANAGEMENT, LOGICAL OPERATIONS, Top
@chapter Graphics

Berkeley Logo provides traditional Logo turtle graphics with one turtle.
Multiple turtles, dynamic turtles, and collision detection are not supported.
This is the most hardware-dependent part of Logo; some features may exist
on some machines but not others.  Nevertheless, the goal has been to make
Logo programs as portable as possible, rather than to take fullest advantage
of the capabilities of each machine.  In particular, Logo attempts to scale
the screen so that turtle coordinates [--100 --100] and [100 100] fit on the
graphics window, and so that the aspect ratio is 1:1.

The center of the graphics window (which may or may not be the entire
screen, depending on the machine used) is turtle location [0 0].  Positive
X is to the right; positive Y is up.  Headings (angles) are measured in
degrees clockwise from the positive Y axis.  (This differs from the common
mathematical convention of measuring angles counterclockwise from the
positive X axis.)  The turtle is represented as an isoceles triangle; the
actual turtle position is at the midpoint of the base (the short side).
However, the turtle is drawn one step behind its actual position, so that
the display of the base of the turtle's triangle does not obscure a line
drawn perpendicular to it (as would happen after drawing a square).

Colors are, of course, hardware-dependent.  However, Logo provides partial
hardware independence by interpreting color numbers 0 through 7 uniformly
on all computers:

@example
0  black        1  blue         2  green        3  cyan
4  red          5  magenta      6  yellow       7 white
@end example

Where possible, Logo provides additional user-settable colors; how many
are available depends on the hardware and operating system environment.
If at least 16 colors are available, Logo tries to provide uniform
initial settings for the colors 8-15:

@example
 8  brown        9  tan         10  forest      11  aqua
12  salmon      13  purple      14  orange      15  grey
@end example

Logo begins with a black background and white pen.

@menu
* TURTLE MOTION::               
* TURTLE MOTION QUERIES::       
* TURTLE AND WINDOW CONTROL::   
* TURTLE AND WINDOW QUERIES::   
* PEN AND BACKGROUND CONTROL::  
* PEN QUERIES::                 
* SAVING AND LOADING PICTURES::  
* MOUSE QUERIES::
@end menu



@node  TURTLE MOTION, TURTLE MOTION QUERIES, GRAPHICS, GRAPHICS
@section Turtle Motion

@menu
* FORWARD::                     
* BACK::                        
* LEFT::                        
* RIGHT::                       
* SETPOS::                      
* SETXY::                       
* SETX::                        
* SETY::                        
* SETHEADING::                  
* HOME::                        
* ARC::                         
@end menu


@node  FORWARD, BACK, TURTLE MOTION, TURTLE MOTION
@unnumberedsubsec forward
@cindex forward
@cindex fd

@example
FORWARD dist
FD dist
@end example

moves the turtle forward, in the direction that it's facing, by the
specified distance (measured in turtle steps).

@node  BACK, LEFT, FORWARD, TURTLE MOTION
@unnumberedsubsec back
@cindex back
@cindex bk

@example
BACK dist
BK dist
@end example

moves the turtle backward, i.e., exactly opposite to the direction that
it's facing, by the specified distance.  (The heading of the turtle does
not change.)

@node  LEFT, RIGHT, BACK, TURTLE MOTION
@unnumberedsubsec left
@cindex left
@cindex lt

@example
LEFT degrees
LT degrees
@end example

turns the turtle counterclockwise by the specified angle, measured in
degrees (1/360 of a circle).

@node  RIGHT, SETPOS, LEFT, TURTLE MOTION
@unnumberedsubsec right
@cindex right
@cindex rt

@example
RIGHT degrees
RT degrees
@end example

turns the turtle clockwise by the specified angle, measured in degrees
(1/360 of a circle).

@node  SETPOS, SETXY, RIGHT, TURTLE MOTION
@unnumberedsubsec setpos
@cindex setpos

@example
SETPOS pos
@end example

moves the turtle to an absolute position in the graphics window.  The input is
a list of two numbers, the X and Y coordinates.

@node  SETXY, SETX, SETPOS, TURTLE MOTION
@unnumberedsubsec setxy
@cindex setxy

@example
SETXY xcor ycor
@end example

moves the turtle to an absolute position in the graphics window.  The two
inputs are numbers, the X and Y coordinates.

@node  SETX, SETY, SETXY, TURTLE MOTION
@unnumberedsubsec setx
@cindex setx

@example
SETX xcor
@end example

moves the turtle horizontally from its old position to a new absolute
horizontal coordinate.  The input is the new X coordinate.

@node  SETY, SETHEADING, SETX, TURTLE MOTION
@unnumberedsubsec sety
@cindex sety

@example
SETY ycor
@end example

moves the turtle vertically from its old position to a new absolute
vertical coordinate.  The input is the new Y coordinate.

@node  SETHEADING, HOME, SETY, TURTLE MOTION
@unnumberedsubsec setheading
@cindex setheading
@cindex seth

@example
SETHEADING degrees
SETH degrees
@end example

turns the turtle to a new absolute heading.  The input is a number,
the heading in degrees clockwise from the positive Y axis.

@node  HOME, ARC, SETHEADING, TURTLE MOTION
@unnumberedsubsec home
@cindex home

@example
HOME
@end example

moves the turtle to the center of the screen.  Equivalent to 
@w{@t{SETPOS [0 0] SETHEADING 0.}}

@xref{SETPOS} ,
@xref{SETHEADING} .

@node  ARC,  , HOME, TURTLE MOTION
@unnumberedsubsec arc
@cindex arc

@example
ARC angle radius
@end example

draws an arc of a circle, with the turtle at the center, with the
specified radius, starting at the turtle's heading and extending
clockwise through the specified angle.  The turtle does not move.


@node  TURTLE MOTION QUERIES, TURTLE AND WINDOW CONTROL, TURTLE MOTION, GRAPHICS
@section Turtle Motion Queries

@menu
* POS::                         
* XCOR::                        
* YCOR::                        
* HEADING::                     
* TOWARDS::                     
* SCRUNCH::                     
@end menu


@node  POS, XCOR, TURTLE MOTION QUERIES, TURTLE MOTION QUERIES
@unnumberedsubsec pos
@cindex pos

@example
POS
@end example

outputs the turtle's current position, as a list of two numbers, the X
and Y coordinates.

@node  XCOR, YCOR, POS, TURTLE MOTION QUERIES
@unnumberedsubsec xcor
@cindex xcor

@example
XCOR						(library procedure)
@end example

outputs a number, the turtle's X coordinate.

@node  YCOR, HEADING, XCOR, TURTLE MOTION QUERIES
@unnumberedsubsec ycor
@cindex ycor

@example
YCOR						(library procedure)
@end example

outputs a number, the turtle's Y coordinate.

@node  HEADING, TOWARDS, YCOR, TURTLE MOTION QUERIES
@unnumberedsubsec heading
@cindex heading

@example
HEADING
@end example

outputs a number, the turtle's heading in degrees.

@node  TOWARDS, SCRUNCH, HEADING, TURTLE MOTION QUERIES
@unnumberedsubsec towards
@cindex towards

@example
TOWARDS pos
@end example

outputs a number, the heading at which the turtle should be facing so
that it would point from its current position to the position given as
the input.

@node  SCRUNCH,  , TOWARDS, TURTLE MOTION QUERIES
@unnumberedsubsec scrunch
@cindex scrunch

@example
SCRUNCH
@end example

outputs a list containing two numbers, the X and Y scrunch factors, as used by
@code{SETSCRUNCH}.  (But note that @code{SETSCRUNCH} takes two numbers as inputs, not one
list of numbers.)

@xref{SETSCRUNCH} .



@node  TURTLE AND WINDOW CONTROL, TURTLE AND WINDOW QUERIES, TURTLE MOTION QUERIES, GRAPHICS
@section Turtle and Window Control

@menu
* SHOWTURTLE::                  
* HIDETURTLE::                  
* CLEAN::                       
* CLEARSCREEN::                 
* WRAP::                        
* WINDOW::                      
* FENCE::                       
* FILL::                        
* FILLED::
* LABEL::                       
* SETLABELHEIGHT::
* TEXTSCREEN::                  
* FULLSCREEN::                  
* SPLITSCREEN::                 
* SETSCRUNCH::                  
* REFRESH::                     
* NOREFRESH::                   
@end menu


@node  SHOWTURTLE, HIDETURTLE, TURTLE AND WINDOW CONTROL, TURTLE AND WINDOW CONTROL
@unnumberedsubsec showturtle
@cindex showturtle
@cindex st

@example
SHOWTURTLE
ST
@end example

makes the turtle visible.

@node  HIDETURTLE, CLEAN, SHOWTURTLE, TURTLE AND WINDOW CONTROL
@unnumberedsubsec hideturtle
@cindex hideturtle
@cindex ht

@example
HIDETURTLE
HT
@end example

makes the turtle invisible.  It's a good idea to do this while you're in
the middle of a complicated drawing, because hiding the turtle speeds up
the drawing substantially.

@node  CLEAN, CLEARSCREEN, HIDETURTLE, TURTLE AND WINDOW CONTROL
@unnumberedsubsec clean
@cindex clean

@example
CLEAN
@end example

erases all lines that the turtle has drawn on the graphics window.  The
turtle's state (position, heading, pen mode, etc.) is not changed.

@node  CLEARSCREEN, WRAP, CLEAN, TURTLE AND WINDOW CONTROL
@unnumberedsubsec clearscreen
@cindex clearscreen
@cindex cs

@example
CLEARSCREEN
CS
@end example

erases the graphics window and sends the turtle to its initial position
and heading.  Like @code{HOME} and @code{CLEAN} together.

@xref{HOME} .

@node  WRAP, WINDOW, CLEARSCREEN, TURTLE AND WINDOW CONTROL
@unnumberedsubsec wrap
@cindex wrap

@example
WRAP
@end example

tells the turtle to enter wrap mode:  From now on, if the turtle is
asked to move past the boundary of the graphics window, it will "wrap
around" and reappear at the opposite edge of the window.  The top edge
wraps to the bottom edge, while the left edge wraps to the right edge.
(So the window is topologically equivalent to a torus.)  This is the
turtle's initial mode.  Compare @code{WINDOW} and @code{FENCE}.

@xref{FENCE} .

@node  WINDOW, FENCE, WRAP, TURTLE AND WINDOW CONTROL
@unnumberedsubsec window
@cindex window

@example
WINDOW
@end example

tells the turtle to enter window mode:  From now on, if the turtle is
asked to move past the boundary of the graphics window, it will move
offscreen.  The visible graphics window is considered as just part of an
infinite graphics plane; the turtle can be anywhere on the plane.  (If
you lose the turtle, @code{HOME} will bring it back to the center of the
window.)  Compare @code{WRAP} and @code{FENCE}.

@xref{HOME} .

@node  FENCE, FILL, WINDOW, TURTLE AND WINDOW CONTROL
@unnumberedsubsec fence
@cindex fence

@example
FENCE
@end example

tells the turtle to enter fence mode:  From now on, if the turtle is
asked to move past the boundary of the graphics window, it will move as
far as it can and then stop at the edge with an "out of bounds" error
message.  Compare @code{WRAP} and @code{WINDOW}.

@xref{WRAP} .

@node  FILL, FILLED, FENCE, TURTLE AND WINDOW CONTROL
@unnumberedsubsec fill
@cindex fill

@example
FILL
@end example

fills in a region of the graphics window containing the turtle and
bounded by lines that have been drawn earlier.  This is not portable; it
doesn't work for all machines, and may not work exactly the same way on
different machines.

@node  FILLED, LABEL, FILL, TURTLE AND WINDOW CONTROL
@unnumberedsubsec filled
@cindex filled

@example
FILLED color instructions
@end example

runs the instructions, remembering all points visited by turtle
motion commands, starting @emph{and ending} with the turtle's initial
position.  Then draws (ignoring penmode) the resulting polygon,
in the current pen color, filling the polygon with the given color,
which can be a color number or an RGB list.  The instruction list
cannot include another FILLED invocation.  (wxWidgets only)

@node  LABEL, SETLABELHEIGHT, FILLED, TURTLE AND WINDOW CONTROL
@unnumberedsubsec label
@cindex label

@example
LABEL text
@end example

takes a word or list as input, and prints the input on the graphics
window, starting at the turtle's position.

@node  SETLABELHEIGHT, TEXTSCREEN, LABEL, TURTLE AND WINDOW CONTROL
@unnumberedsubsec setlabelheight
@cindex setlabelheight

@example
SETLABELHEIGHT height
@end example

command (wxWidgets only).  Takes a positive integer argument and tries
to set the font size so that the character height (including
descenders) is that many turtle steps.  This will be different from
the number of screen pixels if @code{SETSCRUNCH} has been used.  Also, note
that @code{SETSCRUNCH} changes the font size to try to preserve this height
in turtle steps.  Note that the query operation corresponding to this
command is @code{LABELSIZE}, not @code{LABELHEIGHT}, because it tells you the width
as well as the height of characters in the current font.

@node TEXTSCREEN, FULLSCREEN, SETLABELHEIGHT, TURTLE AND WINDOW CONTROL
@unnumberedsubsec textscreen
@cindex textscreen

@example
TEXTSCREEN
TS
@end example

rearranges the size and position of windows to maximize the space
available in the text window (the window used for interaction with
Logo).  The details differ among machines.  Compare @code{SPLITSCREEN} and
@code{FULLSCREEN}.

@xref{SPLITSCREEN} .

@node  FULLSCREEN, SPLITSCREEN, TEXTSCREEN, TURTLE AND WINDOW CONTROL
@unnumberedsubsec fullscreen
@cindex fullscreen
@cindex fs

@example
FULLSCREEN
FS
@end example

rearranges the size and position of windows to maximize the space
available in the graphics window.  The details differ among machines.
Compare @code{SPLITSCREEN} and @code{TEXTSCREEN}.

Since there must be a text window to allow printing (including the printing of
the Logo prompt), Logo automatically switches from fullscreen to splitscreen
whenever anything is printed.

In the DOS version, switching from fullscreen to splitscreen loses the part of
the picture that's hidden by the text window.  [This design decision follows
from the scarcity of memory, so that the extra memory to remember an invisible
part of a drawing seems too expensive.]

@node  SPLITSCREEN, SETSCRUNCH, FULLSCREEN, TURTLE AND WINDOW CONTROL
@unnumberedsubsec splitscreen
@cindex splitscreen
@cindex ss

@example
SPLITSCREEN
SS
@end example

rearranges the size and position of windows to allow some room for text
interaction while also keeping most of the graphics window visible.  The
details differ among machines.  Compare @code{TEXTSCREEN} and @code{FULLSCREEN}.

@xref{TEXTSCREEN} .

@node  SETSCRUNCH, REFRESH, SPLITSCREEN, TURTLE AND WINDOW CONTROL
@unnumberedsubsec setscrunch
@cindex setscrunch
@cindex scrunch.dat

@example
SETSCRUNCH xscale yscale
@end example

adjusts the aspect ratio and scaling of the graphics display.  After
this command is used, all further turtle motion will be adjusted by
multiplying the horizontal and vertical extent of the motion by the two
numbers given as inputs.  For example, after the instruction
@w{@t{SETSCRUNCH 2 1}} motion at a heading of 45 degrees will move twice
as far horizontally as vertically.  If your squares don't come out
square, try this.  (Alternatively, you can deliberately misadjust the
aspect ratio to draw an ellipse.)

For all modern computers, both scale factors are initially 1.
For DOS machines, the scale factors are initially set according to what
the hardware claims the aspect ratio is, but the hardware sometimes
lies.  For DOS, the values set by @code{SETSCRUNCH} are remembered in a file (called
@file{scrunch.dat}) and are automatically put into effect when a Logo session
begins.

@node  REFRESH, NOREFRESH, SETSCRUNCH, TURTLE AND WINDOW CONTROL
@unnumberedsubsec refresh
@cindex refresh

@example
REFRESH
@end example

(command) tells Logo to remember the turtle's motions so that they
can be used for high-resolution printing (wxWidgets) or to refresh
the graphics window if it is moved, resized, or overlayed
(non-wxWidgets).  This is the default.

@node  NOREFRESH,  , REFRESH, TURTLE AND WINDOW CONTROL
@unnumberedsubsec norefresh
@cindex norefresh

@example
NOREFRESH
@end example

(command) tells Logo not to remember the turtle's motions, which may
be useful to save time and memory if your program is interactive or
animated, rather than drawing a static picture you'll want to print
later (wxWidgets).  In non-wxWidgets versions, using NOREFRESH may
prevent Logo from restoring the graphics image after the window is
moved, resized, or overlayed.


@node  TURTLE AND WINDOW QUERIES, PEN AND BACKGROUND CONTROL, TURTLE AND WINDOW CONTROL, GRAPHICS
@section Turtle and Window Queries

@menu
* SHOWNP::                      
* SCREENMODE::                  
* TURTLEMODE::                  
* LABELSIZE::
@end menu


@node  SHOWNP, SCREENMODE, TURTLE AND WINDOW QUERIES, TURTLE AND WINDOW QUERIES
@unnumberedsubsec shownp
@cindex shownp
@cindex shown?

@example
SHOWNP
SHOWN?
@end example

outputs @code{TRUE} if the turtle is shown (visible), @code{FALSE} if the turtle is
hidden.  See @code{SHOWTURTLE} and @code{HIDETURTLE}.

@xref{SHOWTURTLE} ,
@ref{HIDETURTLE} .


@node SCREENMODE, TURTLEMODE, SHOWNP, TURTLE AND WINDOW QUERIES
@unnumberedsubsec screenmode
@cindex screenmode

@example
SCREENMODE
@end example

outputs the word @code{TEXTSCREEN}, @code{SPLITSCREEN}, or @code{FULLSCREEN} depending
on the current screen mode.

@node TURTLEMODE, LABELSIZE, SCREENMODE, TURTLE AND WINDOW QUERIES
@unnumberedsubsec turtlemode
@cindex turtlemode

@example
TURTLEMODE
@end example

outputs the word @code{WRAP}, @code{FENCE}, or @code{WINDOW} depending on the current
turtle mode.

@node  LABELSIZE, , TURTLEMODE, TURTLE AND WINDOW QUERIES
@unnumberedsubsec labelsize
@cindex labelsize

@example
LABELSIZE
@end example

(wxWidgets only) outputs a list of two positive integers, the width
and height of characters displayed by @code{LABEL} measured in turtle steps
(which will be different from screen pixels if @code{SETSCRUNCH} has been
used).  There is no @code{SETLABELSIZE} because the width and height of a
font are not separately controllable, so the inverse of this operation
is @code{SETLABELHEIGHT}, which takes just one number for the desired height.



@node  PEN AND BACKGROUND CONTROL, PEN QUERIES, TURTLE AND WINDOW QUERIES, GRAPHICS
@section Pen and Background Control

The turtle carries a pen that can draw pictures.  At any time the pen
can be UP (in which case moving the turtle does not change what's on the
graphics screen) or DOWN (in which case the turtle leaves a trace).
If the pen is down, it can operate in one of three modes: PAINT (so that it
draws lines when the turtle moves), ERASE (so that it erases any lines
that might have been drawn on or through that path earlier), or REVERSE
(so that it inverts the status of each point along the turtle's path).


@menu
* PENDOWN::                     
* PENUP::                       
* PENPAINT::                    
* PENERASE::                    
* PENREVERSE::                  
* SETPENCOLOR::                 
* SETPALETTE::                  
* SETPENSIZE::                  
* SETPENPATTERN::               
* SETPEN::                      
* SETBACKGROUND::               
@end menu


@node  PENDOWN, PENUP, PEN AND BACKGROUND CONTROL, PEN AND BACKGROUND CONTROL
@unnumberedsubsec pendown
@cindex pendown
@cindex pd

@example
PENDOWN
PD
@end example

sets the pen's position to @code{DOWN}, without changing its mode.

@node  PENUP, PENPAINT, PENDOWN, PEN AND BACKGROUND CONTROL
@unnumberedsubsec penup
@cindex penup
@cindex pu

@example
PENUP
PU
@end example

sets the pen's position to @code{UP}, without changing its mode.

@node  PENPAINT, PENERASE, PENUP, PEN AND BACKGROUND CONTROL
@unnumberedsubsec penpaint
@cindex penpaint
@cindex ppt

@example
PENPAINT
PPT
@end example

sets the pen's position to @code{DOWN} and mode to @code{PAINT}.

@node  PENERASE, PENREVERSE, PENPAINT, PEN AND BACKGROUND CONTROL
@unnumberedsubsec penerase
@cindex penerase
@cindex pe

@example
PENERASE
PE
@end example

sets the pen's position to @code{DOWN} and mode to @code{ERASE}.

@xref{ERASE} .

@node  PENREVERSE, SETPENCOLOR, PENERASE, PEN AND BACKGROUND CONTROL
@unnumberedsubsec penreverse
@cindex penreverse
@cindex px

@example
PENREVERSE
PX
@end example

sets the pen's position to @code{DOWN} and mode to @code{REVERSE}.  (This may interact
in system-dependent ways with use of color.)

@xref{REVERSE} .

@node  SETPENCOLOR, SETPALETTE, PENREVERSE, PEN AND BACKGROUND CONTROL
@unnumberedsubsec setpencolor
@cindex setpencolor
@cindex setpc

@example
SETPENCOLOR colornumber.or.rgblist
SETPC colornumber.or.rgblist
@end example

sets the pen color to the given number, which must be a nonnegative
integer.  There are initial assignments for the first 16 colors:

@example
 0  black	 1  blue	 2  green	 3  cyan
 4  red		 5  magenta	 6  yellow	 7 white
 8  brown	 9  tan		10  forest	11  aqua
12  salmon	13  purple	14  orange	15  grey
@end example

but other colors can be assigned to numbers by the @code{PALETTE} command.
Alternatively, sets the pen color to the given RGB values (a list of
three nonnegative numbers less than 100 specifying the percent saturation
of red, green, and blue in the desired color).

@node  SETPALETTE, SETPENSIZE, SETPENCOLOR, PEN AND BACKGROUND CONTROL
@unnumberedsubsec setpalette
@cindex setpalette 

@example
SETPALETTE colornumber rgblist
@end example

sets the actual color corresponding to a given number, if allowed by the
hardware and operating system.  Colornumber must be an integer greater than or
equal to 8.  (Logo tries to keep the first 8 colors constant.)  The second
input is a list of three nonnegative numbers less than 100 specifying the
percent saturation of red, green, and blue in the desired color.

@node  SETPENSIZE, SETPENPATTERN, SETPALETTE, PEN AND BACKGROUND CONTROL
@unnumberedsubsec setpensize
@cindex setpensize

@example
SETPENSIZE size
@end example

sets the thickness of the pen.  The input is either a single positive
integer or a list of two positive integers (for horizontal and
vertical thickness).  Some versions pay no attention to the second
number, but always have a square pen.

@node  SETPENPATTERN, SETPEN, SETPENSIZE, PEN AND BACKGROUND CONTROL
@unnumberedsubsec setpenpattern
@cindex setpenpattern

@example
SETPENPATTERN pattern
@end example

sets hardware-dependent pen characteristics.  This command is not
guaranteed compatible between implementations on different machines.

@node  SETPEN, SETBACKGROUND, SETPENPATTERN, PEN AND BACKGROUND CONTROL
@unnumberedsubsec setpen
@cindex setpen

@example
SETPEN list					(library procedure)
@end example

sets the pen's position, mode, thickness, and hardware-dependent
characteristics according to the information in the input list, which should
be taken from an earlier invocation of @code{PEN}.

@xref{PEN} .

@node  SETBACKGROUND,  , SETPEN, PEN AND BACKGROUND CONTROL
@unnumberedsubsec setbackground
@cindex setbackground
@cindex setbg

@example
SETBACKGROUND colornumber.or.rgblist
SETBG colornumber.or.rgblist
@end example

set the screen background color by slot number or RGB values.
See @code{SETPENCOLOR} for details.

@xref{SETPENCOLOR} .

@node  PEN QUERIES, SAVING AND LOADING PICTURES, PEN AND BACKGROUND CONTROL, GRAPHICS
@section Pen Queries

@menu
* PENDOWNP::                    
* PENMODE::                     
* PENCOLOR::                    
* PALETTE::                     
* PENSIZE::                     
* PEN::                         
* BACKGROUND::                  
@end menu


@node  PENDOWNP, PENMODE, PEN QUERIES, PEN QUERIES
@unnumberedsubsec pendownp
@cindex pendownp
@cindex pendown?

@example
PENDOWNP
PENDOWN?
@end example

outputs @code{TRUE} if the pen is down, @code{FALSE} if it's up.

@node  PENMODE, PENCOLOR, PENDOWNP, PEN QUERIES
@unnumberedsubsec penmode
@cindex penmode

@example
PENMODE
@end example

outputs one of the words @code{PAINT}, @code{ERASE}, or @code{REVERSE} according to the
current pen mode.

@xref{ERASE} ,
@ref{REVERSE} .

@node  PENCOLOR, PALETTE, PENMODE, PEN QUERIES
@unnumberedsubsec pencolor
@cindex pencolor
@cindex pc

@example
PENCOLOR
PC
@end example

outputs a color number, a nonnegative integer that is associated with
a particular color, or a list of RGB values if such a list was used as
the most recent input to @code{SETPENCOLOR}.  There are initial assignments
for the first 16 colors:

@example
 0  black        1  blue         2  green        3  cyan
 4  red          5  magenta      6  yellow       7 white
 8  brown        9  tan         10  forest      11  aqua
12  salmon      13  purple      14  orange      15  grey
@end example

but other colors can be assigned to numbers by the @code{PALETTE} command.

@node  PALETTE, PENSIZE, PENCOLOR, PEN QUERIES
@unnumberedsubsec palette
@cindex palette

@example
PALETTE colornumber
@end example

outputs a list of three nonnegative numbers less than 100 specifying the
percent saturation of red, green, and blue in the color associated with the
given number.

@node  PENSIZE, PEN, PALETTE, PEN QUERIES
@unnumberedsubsec pensize
@cindex pensize
@cindex penpattern

@example
PENSIZE
@end example

outputs a list of two positive integers, specifying the horizontal
and vertical thickness of the turtle pen.  (In some implementations,
including wxWidgets, the two numbers are always equal.)

@example
PENPATTERN
@end example

outputs system-specific pen information.

@node  PEN, BACKGROUND, PENSIZE, PEN QUERIES
@unnumberedsubsec pen
@cindex pen

@example
PEN						(library procedure)
@end example

outputs a list containing the pen's position, mode, thickness, and
hardware-specific characteristics, for use by @code{SETPEN}.

@xref{SETPEN} .

@node  BACKGROUND,  , PEN, PEN QUERIES
@unnumberedsubsec background
@cindex background
@cindex bg

@example
BACKGROUND
BG
@end example

outputs the graphics background color, either as a slot number or
as an RGB list, whichever way it was set.  (See @code{PENCOLOR}.)

@node SAVING AND LOADING PICTURES, MOUSE QUERIES, PEN QUERIES, GRAPHICS
@comment  node-name,  next,  previous,  up
@section Saving and Loading Pictures

@menu
* SAVEPICT::                    
* LOADPICT::                    
* EPSPICT::                     
@end menu

@node SAVEPICT, LOADPICT, SAVING AND LOADING PICTURES, SAVING AND LOADING PICTURES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec savepict
@cindex savepict

@example
SAVEPICT filename
@end example

command.  Writes a file with the specified name containing the state of
the graphics window, including any nonstandard color palette settings,
in Logo's internal format.  This picture can be restored to the screen
using @code{LOADPICT}.  The format is not portable between platforms, nor is it
readable by other programs.  @ref{EPSPICT} to export Logo graphics for
other programs.


@node LOADPICT, EPSPICT, SAVEPICT, SAVING AND LOADING PICTURES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec loadpict
@cindex loadpict

@example
LOADPICT filename
@end example

command.  Reads the specified file, which must have been written by a
@code{SAVEPICT} command, and restores the graphics window and color palette
settings to the values stored in the file.  Any drawing previously on
the screen is cleared.

@xref{SAVEPICT} .


@node EPSPICT,  , LOADPICT, SAVING AND LOADING PICTURES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec epspict
@cindex epspict

@example
EPSPICT filename
@end example

command.  Writes a file with the specified name, containing an
Encapsulated Postscript (EPS) representation of the state of the
graphics window.  This file can be imported into other programs that
understand EPS format.  Restrictions: the drawing cannot use @code{FILL},
@code{PENERASE}, or @code{PENREVERSE}; any such instructions will be ignored in the
translation to Postscript form.

@xref{FILL} ,
@xref{PENERASE} ,
@xref{PENREVERSE} .


@node MOUSE QUERIES,  , SAVING AND LOADING PICTURES, GRAPHICS
@comment  node-name,  next,  previous,  up
@section Mouse Queries

@menu
* MOUSEPOS::                    
* CLICKPOS::
* BUTTONP::                    
* BUTTON::                     
@end menu

@node MOUSEPOS, CLICKPOS, MOUSE QUERIES, MOUSE QUERIES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec mousepos
@cindex mousepos

@example
MOUSEPOS
@end example

outputs the coordinates of the mouse, provided that it's within the
graphics window, in turtle coordinates.  If the mouse is outside the
graphics window, then the last position within the window is returned.
Exception:  If a mouse button is pressed within the graphics window
and held while the mouse is dragged outside the window, the mouse's
position is returned as if the window were big enough to include it.

@node CLICKPOS, BUTTONP, MOUSEPOS, MOUSE QUERIES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec clickpos
@cindex clickpos

@example
CLICKPOS
@end example

outputs the coordinates that the mouse was at when a mouse button
was most recently pushed, provided that that position was within the
graphics window, in turtle coordinates.  (wxWidgets only)

@node BUTTONP, BUTTON, CLICKPOS, MOUSE QUERIES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec buttonp
@cindex buttonp
@cindex button?

@example
BUTTONP
BUTTON?
@end example

outputs @code{TRUE} if a mouse button is down and the mouse is over the
graphics window.  Once the button is down, @code{BUTTONP} remains true until
the button is released, even if the mouse is dragged out of the
graphics window.

@node BUTTON, , BUTTONP, MOUSE QUERIES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec button
@cindex button

@example
BUTTON
@end example

outputs 0 if no mouse button has been pushed inside the Logo window
since the last call to @code{BUTTON}.  Otherwise, it outputs an integer
between 1 and 3 indicating which button was most recently pressed.
Ordinarily 1 means left, 2 means right, and 3 means center, but
operating systems may reconfigure these.

@node   WORKSPACE MANAGEMENT, CONTROL STRUCTURES, GRAPHICS, Top
@chapter Workspace Management

@menu
* PROCEDURE DEFINITION::        
* VARIABLE DEFINITION::         
* PROPERTY LISTS::              
* WORKSPACE PREDICATES::        
* WORKSPACE QUERIES::           
* WORKSPACE INSPECTION::        
* WORKSPACE CONTROL::           
@end menu


@node  PROCEDURE DEFINITION, VARIABLE DEFINITION, WORKSPACE MANAGEMENT, WORKSPACE MANAGEMENT
@section Procedure Definition

@menu
* TO::                          
* DEFINE::                      
* TEXT::                        
* FULLTEXT::                    
* COPYDEF::                     
@end menu

@node TO, DEFINE, PROCEDURE DEFINITION, PROCEDURE DEFINITION
@unnumberedsubsec to
@cindex to

@example
TO procname :input1 :input2 ...			(special form)
@end example

command.  Prepares Logo to accept a procedure definition.  The procedure
will be named @var{procname} and there must not already be a procedure by
that name.  The inputs will be called @var{input1} etc.  Any number of
inputs are allowed, including none.  Names of procedures and inputs are
case-insensitive.

Unlike every other Logo procedure, TO takes as its inputs the actual
words typed in the instruction line, as if they were all quoted, rather
than the results of evaluating expressions to provide the inputs.
(That's what @dfn{special form} means.)

This version of Logo allows variable numbers of inputs to a procedure.
After the procedure name come four kinds of things, @emph{in this order}:

@example
    1.   0 or more REQUIRED inputs    :FOO :FROBOZZ
    2.   0 or more OPTIONAL inputs    [:BAZ 87] [:THINGO 5+9]
    3.   0 or 1 REST input            [:GARPLY]
    4.   0 or 1 DEFAULT number        5
@end example

Every procedure has a @var{minimum}, @var{default}, and @var{maximum} number of inputs.
(The latter can be infinite.)

The @var{minimum} number of inputs is the number of required inputs, which
must come first.  A required input is indicated by the

@example
:inputname
@end example

notation.

After all the required inputs can be zero or more optional inputs,
each of which is represented by the following notation:

@example
[:inputname default.value.expression]
@end example

When the procedure is invoked, if actual inputs are not supplied for
these optional inputs, the @var{default value expression}s are evaluated to
set values for the corresponding input names.  The inputs are processed
from left to right, so a default value expression can be based on
earlier inputs.  Example:

@example
to proc :inlist [:startvalue first :inlist]
@end example

If the procedure is invoked by saying

@example
proc [a b c]
@end example

then the variable @code{inlist} will have the value @w{@t{[A B C]}} and the
variable @code{startvalue} will have the value @t{A}.  If the procedure is invoked
by saying

@example
(proc [a b c] "x)
@end example

then @code{inlist} will have the value @w{@t{[A B C]}} and @code{startvalue}
will have the value @t{X}.

After all the required and optional input can come a single @dfn{rest}
input, represented by the following notation:

@example
[:inputname]
@end example

This is a rest input rather than an optional input because there is no
default value expression.  There can be at most one rest input.  When
the procedure is invoked, the value of this @var{inputname} will be a list
containing all of the actual inputs provided that were not used for
required or optional inputs.  Example:

@example
to proc :in1 [:in2 "foo] [:in3 "baz] [:in4]
@end example

If this procedure is invoked by saying

@example
proc "x
@end example

then @code{in1} has the value @t{X}, @code{in2} has the value @t{FOO},
@code{in3} has the value @t{BAZ}, and @code{in4} has the value @t{[]} (the
empty list).  If it's invoked by saying

@example
(proc "a "b "c "d "e)
@end example

then @code{in1} has the value @t{A}, @code{in2} has the value @t{B},
@code{in3} has the value @t{C}, and @code{in4} has the value @w{@t{[D E]}}.

The @emph{maximum} number of inputs for a procedure is infinite if a rest input
is given; otherwise, it is the number of required inputs plus the number
of optional inputs.

The @emph{default} number of inputs for a procedure, which is the number of
inputs that it will accept if its invocation is not enclosed in
parentheses, is ordinarily equal to the minimum number.  If you want a
different default number you can indicate that by putting the desired
default number as the last thing on the @code{TO} line.  example:

@example
to proc :in1 [:in2 "foo] [:in3] 3
@end example

This procedure has a minimum of one input, a default of three inputs,
and an infinite maximum.

Logo responds to the @code{TO} command by entering procedure definition mode.
The prompt character changes from @code{?} to @code{>} and whatever instructions you type become part of the definition until you type a line containing
only the word @code{END}.

@node DEFINE, TEXT, TO, PROCEDURE DEFINITION
@unnumberedsubsec define
@cindex define

@example
DEFINE procname text
@end example

command.  Defines a procedure with name @var{procname} and text @var{text}.  If
there is already a procedure with the same name, the new definition
replaces the old one.  The @var{text} input must be a list whose members are
lists.  The first member is a list of inputs; it looks like a @code{TO} line
but without the word @code{TO}, without the procedure name, and without the
colons before input names.  In other words, the members of this first
sublist are words for the names of required inputs and lists for the
names of optional or rest inputs.  The remaining sublists of the @var{text}
input make up the body of the procedure, with one sublist for each
instruction line of the body.  (There is no @code{END} line in the text input.)
It is an error to redefine a primitive procedure unless the variable
@code{REDEFP} has the value @code{TRUE}.

@xref{REDEFP} .

@node TEXT, FULLTEXT, DEFINE, PROCEDURE DEFINITION
@unnumberedsubsec text
@cindex text

@example
TEXT procname
@end example

outputs the text of the procedure named @var{procname} in the form expected
by @code{DEFINE}: a list of lists, the first of which describes the inputs to
the procedure and the rest of which are the lines of its body.  The text
does not reflect formatting information used when the procedure was
defined, such as continuation lines and extra spaces.

@node FULLTEXT, COPYDEF, TEXT, PROCEDURE DEFINITION
@unnumberedsubsec fulltext
@cindex fulltext

@example
FULLTEXT procname
@end example

outputs a representation of the procedure @var{procname} in which formatting
information is preserved.  If the procedure was defined with @code{TO}, @code{EDIT},
or @code{LOAD}, then the output is a list of words.  Each word represents one
entire line of the definition in the form output by @code{READWORD}, including
extra spaces and continuation lines.  The last member of the output
represents the @code{END} line.  If the procedure was defined with @code{DEFINE}, then
the output is a list of lists.  If these lists are printed, one per
line, the result will look like a definition using @code{TO}.  Note: the output
from @code{FULLTEXT} is not suitable for use as input to @code{DEFINE}!

@xref{TO} ,
@ref{EDIT} ,
@ref{LOAD} ,
@ref{DEFINE} .

@node COPYDEF,  , FULLTEXT, PROCEDURE DEFINITION
@unnumberedsubsec copydef
@cindex copydef

@example
COPYDEF newname oldname
@end example

command.  Makes @var{newname} a procedure identical to @var{oldname}.  The
latter may be a primitive.  If @var{newname} was already defined, its
previous definition is lost.  If @var{newname} was already a primitive, the
redefinition is not permitted unless the variable @code{REDEFP} has the value
@code{TRUE}.

Note: dialects of Logo differ as to the order of inputs to @code{COPYDEF}.
This dialect uses "@code{MAKE} order," not "@code{NAME} order."

@xref{REDEFP} ,
@ref{SAVE} ,
@ref{PO} ,
@ref{POT} .


@node  VARIABLE DEFINITION, PROPERTY LISTS, PROCEDURE DEFINITION, WORKSPACE MANAGEMENT
@section Variable Definition

@menu
* MAKE::                        
* NAME::                        
* LOCAL::                       
* LOCALMAKE::                   
* THING::                       
* GLOBAL::                      
@end menu

@node MAKE, NAME, VARIABLE DEFINITION, VARIABLE DEFINITION
@unnumberedsubsec make
@cindex make 

@example
MAKE varname value
@end example

command.  Assigns the value @var{value} to the variable named @var{varname},
which must be a word.  Variable names are case-insensitive.  If a
variable with the same name already exists, the value of that variable
is changed.  If not, a new global variable is created.

@node NAME, LOCAL, MAKE, VARIABLE DEFINITION
@unnumberedsubsec name
@cindex name

@example
NAME value varname				(library procedure)
@end example

command.  Same as @code{MAKE} but with the inputs in reverse order.

@node LOCAL, LOCALMAKE, NAME, VARIABLE DEFINITION
@unnumberedsubsec local
@cindex local

@example
LOCAL varname
LOCAL varnamelist
(LOCAL varname1 varname2 ...)
@end example

command.  Accepts as inputs one or more words, or a list of words.  A
variable is created for each of these words, with that word as its name.
The variables are local to the currently running procedure.  Logo
variables follow dynamic scope rules; a variable that is local to a
procedure is available to any subprocedure invoked by that procedure.
The variables created by @code{LOCAL} have no initial value; they must be
assigned a value (e.g., with @code{MAKE}) before the procedure attempts to read
their value.

@xref{MAKE} .

@node LOCALMAKE, THING, LOCAL, VARIABLE DEFINITION
@comment  node-name,  next,  previous,  up
@unnumberedsubsec localmake
@cindex localmake

@example
LOCALMAKE varname value				(library procedure)
@end example

command.  Makes the named variable local, like @code{LOCAL}, and assigns it the
given value, like @code{MAKE}.

@xref{LOCAL} ,
@xref{MAKE} .


@node THING, GLOBAL, LOCALMAKE, VARIABLE DEFINITION
@unnumberedsubsec thing
@cindex thing

@example
THING varname
:quoted.varname
@end example

outputs the value of the variable whose name is the input.  If there is
more than one such variable, the innermost local variable of that name
is chosen.  The colon notation is an abbreviation not for @code{THING} but for
the combination

@example
thing "
@end example

so that @w{@t{:FOO}} means @w{@t{THING "FOO}}.

@node GLOBAL,  , THING, VARIABLE DEFINITION
@unnumberedsubsec global
@cindex global

@example
GLOBAL varname
GLOBAL varnamelist
(GLOBAL varname1 varname2 ...)
@end example

command.  Accepts as inputs one or more words, or a list of
words.  A global variable is created for each of these words, with
that word as its name.  The only reason this is necessary is that
you might want to use the "setter" notation @code{SETXYZ} for a variable
@code{XYZ} that does not already have a value; @w{@t{GLOBAL "XYZ}} makes that legal.
Note: If there is currently a local variable of the same name, this
command does *not* make Logo use the global value instead of the
local one.


@node  PROPERTY LISTS, WORKSPACE PREDICATES, VARIABLE DEFINITION, WORKSPACE MANAGEMENT
@section Property Lists

Note: Names of property lists are always case-insensitive.  Names of
individual properties are case-sensitive or case-insensitive depending
on the value of @code{CASEIGNOREDP}, which is @code{TRUE} by default.

@xref{CASEIGNOREDP} .

In principle, every possible name is the name of a property list, which is
initially empty.  So Logo never gives a "no such property list" error, as it
would for undefined procedure or variable names.  But the primitive procedures
that deal with "all" property lists (@code{CONTENTS}, @code{PLISTS}, etc.)
list only nonempty ones.  To "erase" a property list @ref{ERASE} means to make
it empty, removing all properties from it.


@menu
* PPROP::                       
* GPROP::                       
* REMPROP::                     
* PLIST::                       
@end menu

@node  PPROP, GPROP, PROPERTY LISTS, PROPERTY LISTS
@unnumberedsubsec pprop
@cindex pprop 

@example
PPROP plistname propname value
@end example

command.  Adds a property to the @var{plistname} property list with name
@var{propname} and value @var{value}.

@node  GPROP, REMPROP, PPROP, PROPERTY LISTS
@unnumberedsubsec gprop
@cindex gprop 

@example
GPROP plistname propname
@end example

outputs the value of the @var{propname} property in the @var{plistname} property
list, or the empty list if there is no such property.

@node  REMPROP, PLIST, GPROP, PROPERTY LISTS
@unnumberedsubsec remprop
@cindex remprop 

@example
REMPROP plistname propname
@end example

command.  Removes the property named @var{propname} from the property list
named @var{plistname}.

@node  PLIST,  , REMPROP, PROPERTY LISTS
@unnumberedsubsec plist
@cindex plist  

@example
PLIST plistname
@end example

outputs a list whose odd-numbered members are the names, and whose
even-numbered members are the values, of the properties in the property
list named @var{plistname}.  The output is a copy of the actual property
list; changing properties later will not magically change a list output
earlier by @code{PLIST}.


@node  WORKSPACE PREDICATES, WORKSPACE QUERIES, PROPERTY LISTS, WORKSPACE MANAGEMENT
@section Workspace Predicates

@menu
* PROCEDUREP::                  
* PRIMITIVEP::                  
* DEFINEDP::                    
* NAMEP::                       
* PLISTP::                      
@end menu

@node PROCEDUREP, PRIMITIVEP, WORKSPACE PREDICATES, WORKSPACE PREDICATES
@unnumberedsubsec procedurep
@cindex procedurep
@cindex procedure?

@example
PROCEDUREP name
PROCEDURE? name
@end example

outputs @code{TRUE} if the input is the name of a procedure.

@node PRIMITIVEP, DEFINEDP, PROCEDUREP, WORKSPACE PREDICATES
@unnumberedsubsec primitivep
@cindex primitivep
@cindex primitive?

@example
PRIMITIVEP name
PRIMITIVE? name
@end example

outputs @code{TRUE} if the input is the name of a primitive procedure (one
built into Logo).  Note that some of the procedures described in this
document are library procedures, not primitives.

@node DEFINEDP, NAMEP, PRIMITIVEP, WORKSPACE PREDICATES
@unnumberedsubsec definedp
@cindex definedp
@cindex defined?

@example
DEFINEDP name
DEFINED? name
@end example

outputs @code{TRUE} if the input is the name of a user-defined procedure,
including a library procedure.

@node NAMEP, PLISTP, DEFINEDP, WORKSPACE PREDICATES
@unnumberedsubsec namep
@cindex namep
@cindex name?

@example
NAMEP name
NAME? name
@end example

outputs @code{TRUE} if the input is the name of a variable.

@node PLISTP,  , NAMEP, WORKSPACE PREDICATES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec plistp
@cindex plistp
@cindex plist?

@example
PLISTP name
PLIST? name
@end example

outputs @code{TRUE} if the input is the name of a @emph{nonempty} property list.
(In principle every word is the name of a property list; if you haven't
put any properties in it, @code{PLIST} of that name outputs an empty list,
rather than giving an error message.)


@node  WORKSPACE QUERIES, WORKSPACE INSPECTION, WORKSPACE PREDICATES, WORKSPACE MANAGEMENT
@section Workspace Queries

@menu
* CONTENTS::                    
* BURIED::                      
* TRACED::                      
* STEPPED::                     
* PROCEDURES::                  
* PRIMITIVES::                   
* NAMES::                       
* PLISTS::                      
* NAMELIST::                    
* PLLIST::                      
* ARITY::                       
* NODES::                       
@end menu

Note:  All procedures whose input is indicated as @var{contentslist} will
accept a single word (taken as a procedure name), a list of words (taken
as names of procedures), or a list of three lists as described under the
@code{CONTENTS} command above.

@node CONTENTS, BURIED, WORKSPACE QUERIES, WORKSPACE QUERIES
@unnumberedsubsec contents
@cindex contents

@example
CONTENTS
@end example

outputs a "contents list," i.e., a list of three lists containing names
of defined procedures, variables, and property lists respectively.  This
list includes all unburied named items in the workspace.

@node BURIED, TRACED, CONTENTS, WORKSPACE QUERIES
@unnumberedsubsec buried
@cindex buried

@example
BURIED
@end example

outputs a contents list including all buried named items in the
workspace.

@node TRACED, STEPPED, BURIED, WORKSPACE QUERIES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec traced
@cindex traced

@example
TRACED
@end example

outputs a contents list including all traced named items in the
workspace.

@node STEPPED, PROCEDURES, TRACED, WORKSPACE QUERIES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec stepped
@cindex stepped

@example
STEPPED
@end example

outputs a contents list including all stepped named items in the
workspace.


@node PROCEDURES, PRIMITIVES, STEPPED, WORKSPACE QUERIES
@unnumberedsubsec procedures
@cindex procedures

@example
PROCEDURES
@end example

outputs a list of the names of all unburied user-defined procedures in
the workspace.  Note that this is a list of names, not a contents list.
(However, procedures that require a contents list as input will accept
this list.)


@node PRIMITIVES, NAMES, PROCEDURES, WORKSPACE QUERIES
@unnumberedsubsec primitives
@cindex primitives

@example
PRIMITIVES
@end example

outputs a list of the names of all primitive procedures
in the workspace.  Note that this is a list of names, not a
contents list.  (However, procedures that require a contents list
as input will accept this list.)

@node NAMES, PLISTS, PRIMITIVES, WORKSPACE QUERIES
@unnumberedsubsec names
@cindex names

@example
NAMES
@end example

outputs a contents list consisting of an empty list (indicating no
procedure names) followed by a list of all unburied variable names in
the workspace.

@node PLISTS, NAMELIST, NAMES, WORKSPACE QUERIES
@unnumberedsubsec plists
@cindex plists

@example
PLISTS
@end example

outputs a contents list consisting of two empty lists (indicating no
procedures or variables) followed by a list of all unburied nonempty property
lists in the workspace.

@node NAMELIST, PLLIST, PLISTS, WORKSPACE QUERIES
@unnumberedsubsec namelist
@cindex namelist

@example
NAMELIST varname				(library procedure)
NAMELIST varnamelist
@end example

outputs a contents list consisting of an empty list followed by a list
of the name or names given as input.  This is useful in conjunction with
workspace control procedures that require a contents list as input.

@node PLLIST, ARITY, NAMELIST, WORKSPACE QUERIES
@unnumberedsubsec pllist
@cindex pllist

@example
PLLIST plname					(library procedure)
PLLIST plnamelist
@end example

outputs a contents list consisting of two empty lists followed by a list
of the name or names given as input.  This is useful in conjunction with
workspace control procedures that require a contents list as input.

@xref{CONTENTS} .

@node ARITY, NODES, PLLIST, WORKSPACE QUERIES
@unnumberedsubsec arity
@cindex arity

@example
ARITY procedurename
@end example

outputs a list of three numbers: the minimum, default, and maximum
number of inputs for the procedure whose name is the input.  It is an
error if there is no such procedure.  A maximum of -1 means that the
number of inputs is unlimited.

@node NODES,  , ARITY, WORKSPACE QUERIES
@unnumberedsubsec nodes
@cindex nodes

@example
NODES
@end example

outputs a list of two numbers.  The first represents the number of nodes
of memory currently in use.  The second shows the maximum number of
nodes that have been in use at any time since the last invocation of
@code{NODES}.  (A node is a small block of computer memory as used by Logo.
Each number uses one node.  Each non-numeric word uses one node, plus
some non-node memory for the characters in the word.  Each array takes
one node, plus some non-node memory, as well as the memory required by
its elements.  Each list requires one node per element, as well as the
memory within the elements.)  If you want to track the memory use of an
algorithm, it is best if you invoke @code{GC} at the beginning of each
iteration, since otherwise the maximum will include storage that is
unused but not yet collected.

@node  WORKSPACE INSPECTION, WORKSPACE CONTROL, WORKSPACE QUERIES, WORKSPACE MANAGEMENT
@section Workspace Inspection

@menu
* PO::                          
* POALL::                       
* POPS::                        
* PONS::                        
* POPLS::                       
* PON::                         
* POPL::                        
* POT::                         
* POTS::                        
@end menu


@node PO, POALL, WORKSPACE INSPECTION, WORKSPACE INSPECTION
@unnumberedsubsec po
@cindex printout
@cindex po

@example
PRINTOUT contentslist
PO contentslist
@end example

command.  Prints to the write stream the definitions of all procedures,
variables, and property lists named in the input contents list.

@node POALL, POPS, PO, WORKSPACE INSPECTION
@unnumberedsubsec poall
@cindex poall

@example
POALL						(library procedure)
@end example

command.  Prints all unburied definitions in the workspace.  Abbreviates
@w{@t{PO CONTENTS}}.

@xref{CONTENTS} .

@node POPS, PONS, POALL, WORKSPACE INSPECTION
@unnumberedsubsec pops
@cindex pops

@example
POPS						(library procedure)
@end example

command.  Prints the definitions of all unburied procedures in the
workspace.  Abbreviates @w{@t{PO PROCEDURES}}.

@xref{PO} ,
@ref{PROCEDURES} .

@node PONS, POPLS, POPS, WORKSPACE INSPECTION
@unnumberedsubsec pons
@cindex pons

@example
PONS						(library procedure)
@end example

command.  Prints the definitions of all unburied variables in the
workspace.  Abbreviates @w{@t{PO NAMES}}.

@xref{PO} ,
@ref{NAMES} .

@node POPLS, PON, PONS, WORKSPACE INSPECTION
@unnumberedsubsec popls
@cindex popls

@example
POPLS						(library procedure)
@end example

command.  Prints the contents of all unburied nonempty property lists in the
workspace.  Abbreviates @w{@t{PO PLISTS}}.

@xref{PO} ,
@ref{PLISTS} .

@node PON, POPL, POPLS, WORKSPACE INSPECTION
@unnumberedsubsec pon
@cindex pon

@example
PON varname					(library procedure)
PON varnamelist
@end example

command.  Prints the definitions of the named variable(s).  
@*
Abbreviates @w{@t{PO NAMELIST varname(list)}}.

@xref{PO} ,
@ref{NAMELIST} .

@node POPL, POT, PON, WORKSPACE INSPECTION
@unnumberedsubsec popl
@cindex popl

@example
POPL plname					(library procedure)
POPL plnamelist
@end example

command.  Prints the definitions of the named property list(s).
@*
Abbreviates @w{@t{PO PLLIST plname(list)}}.

@xref{PO} ,
@ref{PLLIST} .

@node POT, POTS, POPL, WORKSPACE INSPECTION
@unnumberedsubsec pot
@cindex pot

@example
POT contentslist
@end example

command.  Prints the title lines of the named procedures and the
definitions of the named variables and property lists.  For property
lists, the entire list is shown on one line instead of as a series of
@code{PPROP} instructions as in @code{PO}.

@xref{PPROP} ,
@ref{PO} .

@node POTS,  , POT, WORKSPACE INSPECTION
@unnumberedsubsec pots
@cindex pots

@example
POTS						(library procedure)
@end example

command.  Prints the title lines of all unburied procedures in the
workspace.  Abbreviates @w{@t{POT PROCEDURES}}.

@xref{PROCEDURES} .


@node  WORKSPACE CONTROL,  , WORKSPACE INSPECTION, WORKSPACE MANAGEMENT
@section Workspace Control

@menu
* ERASE::                       
* ERALL::                       
* ERPS::                        
* ERNS::                        
* ERPLS::                       
* ERN::                         
* ERPL::                        
* BURY::                        
* BURYALL::                     
* BURYNAME::                    
* UNBURY::                      
* UNBURYALL::                   
* UNBURYNAME::                  
* BURIEDP::                     
* TRACE::                       
* UNTRACE::                     
* TRACEDP::                     
* STEP::                        
* UNSTEP::                      
* STEPPEDP::                    
* EDIT::                        
* EDITFILE::                    
* EDALL::                       
* EDPS::                        
* EDNS::                        
* EDPLS::                       
* EDN::                         
* EDPL::                        
* SAVE::                        
* SAVEL::                       
* LOAD::                        
* CSLSLOAD::                    
* HELP::                        
* SETEDITOR::                   
* SETLIBLOC::                   
* SETHELPLOC::                  
* SETCSLSLOC::                  
* SETTEMPLOC::                  
* GC::                          
* .SETSEGMENTSIZE::             
@end menu


@node ERASE, ERALL, WORKSPACE CONTROL, WORKSPACE CONTROL
@unnumberedsubsec erase
@cindex erase
@cindex er

@example
ERASE contentslist
ER contentslist
@end example

command.  Erases from the workspace the procedures, variables, and
property lists named in the input.  Primitive procedures may not be
erased unless the variable @code{REDEFP} has the value @code{TRUE}.

@xref{REDEFP} .

@node ERALL, ERPS, ERASE, WORKSPACE CONTROL
@unnumberedsubsec erall
@cindex erall

@example
ERALL
@end example

command.  Erases all unburied procedures, variables, and property lists
from the workspace.  Abbreviates @w{@t{ERASE CONTENTS}}.

@xref{CONTENTS} .

@node ERPS, ERNS, ERALL, WORKSPACE CONTROL
@unnumberedsubsec erps
@cindex erps

@example
ERPS
@end example

command.  Erases all unburied procedures from the workspace.
@*
Abbreviates @w{@t{ERASE PROCEDURES}}.

@xref{ERASE} ,
@ref{PROCEDURES} .

@node ERNS, ERPLS, ERPS, WORKSPACE CONTROL
@unnumberedsubsec erns
@cindex erns 

@example
ERNS
@end example

command.  Erases all unburied variables from the workspace.  Abbreviates
@w{@t{ERASE NAMES}}.

@xref{ERASE} ,
@ref{NAMES} .

@node ERPLS, ERN, ERNS, WORKSPACE CONTROL
@unnumberedsubsec erpls
@cindex erpls

@example
ERPLS
@end example

command.  Erases all unburied property lists from the workspace.
@*
Abbreviates @w{@t{ERASE PLISTS}}.

@xref{ERASE} ,
@ref{PLISTS} .

@node ERN, ERPL, ERPLS, WORKSPACE CONTROL
@unnumberedsubsec ern
@cindex ern

@example
ERN varname					(library procedure)
ERN varnamelist
@end example

command.  Erases from the workspace the variable(s) named in the input.
Abbreviates @w{@t{ERASE NAMELIST @var{varname(list)}}}.

@xref{ERASE} ,
@ref{NAMELIST} .

@node ERPL, BURY, ERN, WORKSPACE CONTROL
@unnumberedsubsec erpl
@cindex erpl

@example
ERPL plname					(library procedure)
ERPL plnamelist
@end example

command.  Erases from the workspace the property list(s) named in the
input.  Abbreviates @w{@t{ERASE PLLIST @var{plname(list)}}}.

@xref{ERASE} ,
@ref{PLLIST} .

@node BURY, BURYALL, ERPL, WORKSPACE CONTROL
@unnumberedsubsec bury
@cindex bury

@example
BURY contentslist
@end example

command.  Buries the procedures, variables, and property lists named in
the input.  A buried item is not included in the lists output by
@code{CONTENTS}, @code{PROCEDURES}, @code{VARIABLES}, and @code{PLISTS}, but is included in the list
output by @code{BURIED}.  By implication, buried things are not printed by
@code{POALL} or saved by @code{SAVE}.

@xref{CONTENTS} ,
@ref{PROCEDURES} ,
@ref{PONS} ,
@ref{PLISTS} ,
@ref{POALL} ,
@ref{SAVE} .

@node BURYALL, BURYNAME, BURY, WORKSPACE CONTROL
@unnumberedsubsec buryall
@cindex buryall

@example
BURYALL                                         (library procedure)
@end example

command.  Abbreviates @t{BURY CONTENTS}.

@xref{CONTENTS} .

@node BURYNAME, UNBURY, BURYALL, WORKSPACE CONTROL
@unnumberedsubsec buryname
@cindex buryname

@example
BURYNAME varname				(library procedure)
BURYNAME varnamelist
@end example

command.  Abbreviates @t{BURY NAMELIST @code{varname(list)}}.

@xref{BURY} ,
@ref{NAMELIST} .

@node UNBURY, UNBURYALL, BURYNAME, WORKSPACE CONTROL
@unnumberedsubsec unbury
@cindex unbury

@example
UNBURY contentslist
@end example

command.  Unburies the procedures, variables, and property lists named
in the input.  That is, the named items will be returned to view in
@code{CONTENTS}, etc.

@xref{CONTENTS} .

@node UNBURYALL, UNBURYNAME, UNBURY, WORKSPACE CONTROL
@unnumberedsubsec unburyall
@cindex unburyall

@example
UNBURYALL					(library procedure)
@end example

command.  Abbreviates @t{UNBURY BURIED}.

@xref{BURIED} .

@node UNBURYNAME, BURIEDP, UNBURYALL, WORKSPACE CONTROL
@unnumberedsubsec unburyname
@cindex unburyname

@example
UNBURYNAME varname				(library procedure)
UNBURYNAME varnamelist
@end example

command.  Abbreviates @t{UNBURY NAMELIST @var{varname(list)}}.

@xref{UNBURY} ,
@ref{NAMELIST} .

@node BURIEDP, TRACE, UNBURYNAME, WORKSPACE CONTROL
@comment  node-name,  next,  previous,  up
@unnumberedsubsec buriedp
@cindex buriedp
@cindex buried?

@example
BURIEDP contentslist
BURIED? contentslist
@end example

outputs @code{TRUE} if the first procedure, variable, or property list named in
the contents list is buried, @code{FALSE} if not.  Only the first thing in the
list is tested; the most common use will be with a word as input, naming
a procedure, but a contents list is allowed so that you can @code{BURIEDP [[]
[@var{variable}]]} or @code{BURIEDP [[] [] [@var{proplist}]]}.



@node TRACE, UNTRACE, BURIEDP, WORKSPACE CONTROL
@unnumberedsubsec trace
@cindex trace

@example
TRACE contentslist
@end example

command.  Marks the named items for tracing.  A message is printed
whenever a traced procedure is invoked, giving the actual input values,
and whenever a traced procedure @code{STOP}s or @code{OUTPUT}s.  A message is printed
whenever a new value is assigned to a traced variable using @code{MAKE}.  A
message is printed whenever a new property is given to a traced property
list using @code{PPROP}.

@xref{STOP} ,
@ref{OUTPUT} ,
@ref{MAKE} ,
@ref{PPROP} .

@node UNTRACE, TRACEDP, TRACE, WORKSPACE CONTROL
@unnumberedsubsec untrace
@cindex untrace

@example
UNTRACE contentslist
@end example

command.  Turns off tracing for the named items.

@node TRACEDP, STEP, UNTRACE, WORKSPACE CONTROL
@comment  node-name,  next,  previous,  up
@unnumberedsubsec tracedp
@cindex tracedp
@cindex traced?

@example
TRACEDP contentslist
TRACED? contentslist
@end example

outputs @code{TRUE} if the first procedure, variable, or property list named in
the contents list is traced, @code{FALSE} if not.  Only the first thing in the
list is tested; the most common use will be with a word as input, naming
a procedure, but a contents list is allowed so that you can @code{TRACEDP [[]
[@var{variable}]]} or @code{TRACEDP [[] [] [@var{proplist}]]}.


@node STEP, UNSTEP, TRACEDP, WORKSPACE CONTROL
@unnumberedsubsec step
@cindex step

@example
STEP contentslist
@end example

command.  Marks the named items for stepping.  Whenever a stepped
procedure is invoked, each instruction line in the procedure body is
printed before being executed, and Logo waits for the user to type a
newline at the terminal.  A message is printed whenever a stepped
variable name is @dfn{shadowed} because a local variable of the same name is
created either as a procedure input or by the @code{LOCAL} command.

@xref{LOCAL} .

@node UNSTEP, STEPPEDP, STEP, WORKSPACE CONTROL
@unnumberedsubsec unstep
@cindex unstep

@example
UNSTEP contentslist
@end example

command.  Turns off stepping for the named items.


@node STEPPEDP, EDIT, UNSTEP, WORKSPACE CONTROL
@comment  node-name,  next,  previous,  up
@unnumberedsubsec steppedp
@cindex steppedp
@cindex stepped?

@example
STEPPEDP contentslist
STEPPED? contentslist
@end example

outputs @code{TRUE} if the first procedure, variable, or property list named in
the contents list is stepped, @code{FALSE} if not.  Only the first thing in the
list is tested; the most common use will be with a word as input, naming
a procedure, but a contents list is allowed so that you can @code{STEPPEDP [[]
[@var{variable}]]} or @code{STEPPEDP [[] [] [@var{proplist}]]}.



@node EDIT, EDITFILE, STEPPEDP, WORKSPACE CONTROL
@unnumberedsubsec edit
@cindex editor
@cindex temp
@cindex edit
@cindex ed

@example
EDIT contentslist
ED contentslist
(EDIT)
(ED)
@end example

command.  If invoked with an input, @code{EDIT} writes the definitions of the
named items into a temporary file and edits that file, using an editor that
depends on the platform you're using.  In wxWidgets, and in the MacOS Classic
version, there is an editor built into Logo.  In the non-wxWidgets versions
for Unix, MacOS X, Windows, and DOS, Logo uses your favorite editor as
determined by the @env{EDITOR} environment variable.  If you don't have an
@env{EDITOR} variable, edits the definitions using @command{jove}.  If invoked
without an input, @code{EDIT} edits the same file left over from a previous
@code{EDIT} or @code{EDITFILE} instruction.  When you leave the editor, Logo
reads the revised definitions and modifies the workspace accordingly.  It is
not an error if the input includes names for which there is no previous
definition.

If there is a variable @code{LOADNOISILY} whose value is @code{TRUE}, then,
after leaving the editor, @code{TO} commands in the temporary file print
@samp{@var{procname} defined} (where @var{procname} is the name of the
procedure being defined); if @code{LOADNOISILY} is @code{FALSE} or undefined,
@code{TO} commands in the file are carried out silently.

If there is an environment variable called @env{TEMP}, then Logo uses its
value as the directory in which to write the temporary file used for
editing.

Exceptionally, the @code{EDIT} command can be used without its default input
and without parentheses provided that nothing follows it on the
instruction line.

@xref{LOADNOISILY} ,
@xref{EDITFILE} .

@node EDITFILE, EDALL, EDIT, WORKSPACE CONTROL
@comment  node-name,  next,  previous,  up
@unnumberedsubsec editfile
@cindex editfile

@example
EDITFILE filename
@end example

command.  Starts the Logo editor, like @code{EDIT}, but instead of editing a
temporary file it edits the file specified by the input.  When you leave the
editor, Logo reads the revised file, as for @code{EDIT}.  @code{EDITFILE} also
remembers the filename, so that a subsequent @code{EDIT} command with no input will
re-edit the same file.

@code{EDITFILE} is intended as an alternative to @code{LOAD} and @code{SAVE}.
You can maintain a workspace file yourself, controlling the order in which
definitions appear, maintaining comments in the file, and so on.

In the wxWidgets version, @code{EDITFILE} asks whether or not you want to
load the file into Logo when you finish editing.  This allows you to use
@code{EDITFILE} to edit data files without leaving Logo.


@node EDALL, EDPS, EDITFILE, WORKSPACE CONTROL
@unnumberedsubsec edall
@cindex edall

@example
EDALL						(library procedure)
@end example

command.  Abbreviates @t{EDIT CONTENTS}.

@xref{CONTENTS} .

@node EDPS, EDNS, EDALL, WORKSPACE CONTROL
@unnumberedsubsec edps
@cindex edps

@example
EDPS						(library procedure)
@end example

command.  Abbreviates @t{EDIT PROCEDURES}.

@xref{EDIT} ,
@ref{PROCEDURES} .

@node EDNS, EDPLS, EDPS, WORKSPACE CONTROL
@unnumberedsubsec edns
@cindex edns

@example
EDNS						(library procedure)
@end example

command.  Abbreviates @t{EDIT NAMES}.

@xref{EDIT} ,
@ref{NAMES} .

@node EDPLS, EDN, EDNS, WORKSPACE CONTROL
@unnumberedsubsec edpls
@cindex edpls

@example
EDPLS						(library procedure)
@end example

command.  Abbreviates @t{EDIT PLISTS}.

@xref{EDIT} ,
@ref{PLISTS} .

@node EDN, EDPL, EDPLS, WORKSPACE CONTROL
@unnumberedsubsec edn
@cindex edn

@example
EDN varname					(library procedure)
EDN varnamelist
@end example

command.  Abbreviates @t{EDIT NAMELIST @var{varname(list)}}.

@xref{EDIT} , 
@ref{NAMELIST} .

@node EDPL, SAVE, EDN, WORKSPACE CONTROL
@unnumberedsubsec edpl
@cindex edpl

@example
EDPL plname					(library procedure)
EDPL plnamelist
@end example

command.  Abbreviates @t{EDIT PLLIST @var{plname(list)}}.

@xref{EDIT} , 
@ref{PLLIST} .

@node SAVE, SAVEL, EDPL, WORKSPACE CONTROL
@unnumberedsubsec save
@cindex save

@example
SAVE filename
@end example

command.  Saves the definitions of all unburied procedures, variables,
and nonempty property lists in the named file.  Equivalent to

@example
to save :filename
local "oldwriter
make "oldwriter writer
openwrite :filename
setwrite :filename
poall
setwrite :oldwriter
close :filename
end
@end example

Exceptionally, @code{SAVE} can be used with no input and without parentheses
if it is the last thing on the command line.  In this case, the
filename from the most recent @code{LOAD} or @code{SAVE} command will be used.  (It
is an error if there has been no previous @code{LOAD} or @code{SAVE}.)

@node SAVEL, LOAD, SAVE, WORKSPACE CONTROL
@unnumberedsubsec savel
@cindex savel

@example
SAVEL contentslist filename			(library procedure)
@end example

command.  Saves the definitions of the procedures, variables, and
property lists specified by @var{contentslist} to the file named @var{filename}.

@node LOAD, CSLSLOAD, SAVEL, WORKSPACE CONTROL
@unnumberedsubsec load
@cindex load

@example
LOAD filename
@end example

command.  Reads instructions from the named file and executes them.  The file
can include procedure definitions with @code{TO}, and these are accepted even
if a procedure by the same name already exists.  If the file assigns a list
value to a variable named @code{STARTUP}, then that list is run as an
instructionlist after the file is loaded. If there is a variable
@code{LOADNOISILY} whose value is @code{TRUE}, then @code{TO} commands in the
file print @samp{@var{procname} defined} (where @var{procname} is the name of
the procedure being defined); if @code{LOADNOISILY} is @code{FALSE} or
undefined, @code{TO} commands in the file are carried out silently.

@xref{STARTUP} ,
@xref{LOADNOISILY} .


@node CSLSLOAD, HELP, LOAD, WORKSPACE CONTROL
@unnumberedsubsec cslsload
@cindex cslsload

@example
CSLSLOAD name
@end example

command.  Loads the named file, like @code{LOAD}, but from the directory
containing the Computer Science Logo Style programs instead of the
current user's directory.

@xref{LOAD} .

@node HELP, SETEDITOR, CSLSLOAD, WORKSPACE CONTROL
@unnumberedsubsec help
@cindex logohelp
@cindex help

@example
HELP name
(HELP)
@end example

command.  Prints information from the reference manual about the
primitive procedure named by the input.  With no input, lists all the
primitives about which help is available.  If there is an environment
variable @env{LOGOHELP}, then its value is taken as the directory in which to
look for help files, instead of the default help directory.

If @code{HELP} is called with the name of a defined procedure for which there
is no help file, it will print the title line of the procedure
followed by lines from the procedure body that start with semicolon,
stopping when a non-semicolon line is seen.

Exceptionally, the @code{HELP} command can be used without its default input
and without parentheses provided that nothing follows it on the
instruction line.

@node SETEDITOR, SETLIBLOC, HELP, WORKSPACE CONTROL
@unnumberedsubsec seteditor
@cindex seteditor

@example
SETEDITOR path
@end example

command.  Tells Logo to use the specified program as its editor
instead of the default editor.  The format of a path depends on your
operating system.

@node SETLIBLOC, SETCSLSLOC, SETEDITOR, WORKSPACE CONTROL
@unnumberedsubsec setlibloc
@cindex setlibloc

@example
SETLIBLOC path
@end example

command.  Tells Logo to use the specified directory as its library
instead of the default.  (Note that many Logo "primitive" procedures
are actually found in the library, so they may become unavailable if
your new library does not include them!)  The format of a path depends
on your operating system.

@node SETCSLSLOC, SETHELPLOC, SETLIBLOC, WORKSPACE CONTROL
@unnumberedsubsec setcslsloc
@cindex setcslsloc

@example
SETCSLSLOC path
@end example

command.  Tells Logo to use the specified directory for the @code{CSLSLOAD}
command, instead of the default directory.  The format of a path
depends on your operating system.

@xref{CSLSLOAD} .

@node SETHELPLOC, SETTEMPLOC, SETCSLSLOC, WORKSPACE CONTROL
@unnumberedsubsec sethelploc
@cindex sethelploc

@example
SETHELPLOC path
@end example

command.  Tells Logo to look in the specified directory for the information
provided by the HELP command, instead of the default directory.
The format of a path depends on your operating system.

@node SETTEMPLOC, GC, SETHELPLOC, WORKSPACE CONTROL
@unnumberedsubsec settemploc
@cindex settemploc

@example
SETTEMPLOC path
@end example

command.  Tells Logo to write editor temporary files in the specified
directory rather than in the default directory.  You must have write
permission for this directory.  The format of a path depends on your
operating system.

@node GC, .SETSEGMENTSIZE, SETTEMPLOC, WORKSPACE CONTROL
@unnumberedsubsec gc
@cindex gc

@example
GC
(GC anything)
@end example

command.  Runs the garbage collector, reclaiming unused nodes.  Logo
does this when necessary anyway, but you may want to use this command to
control exactly when Logo does it.  In particular, the numbers output by
the @code{NODES} operation will not be very meaningful unless garbage has been
collected.  Another reason to use @code{GC} is that a garbage collection takes
a noticeable fraction of a second, and you may want to schedule
collections for times before or after some time-critical animation.  If
invoked with an argument (of any value), @code{GC} runs a full garbage
collection, including @acronym{GCTWA} (Garbage Collect Truly Worthless Atoms,
which means that it removes from Logo's memory words that used to be
procedure or variable names but aren't any more); without an argument,
@code{GC} does a generational garbage collection, which means that only
recently created nodes are examined.  (The latter is usually good
enough.)


@node .SETSEGMENTSIZE,  , GC, WORKSPACE CONTROL
@unnumberedsubsec .setsegmentsize
@cindex .setsegmentsize

@example
.SETSEGMENTSIZE num
@end example

command.  Sets the number of nodes that Logo allocates from the
operating system at once to @var{num}, which must be a positive integer.
The name is dotted because bad things will happen if you use a
number that's too small or too large for your computer.  The
initial value is 16,000 for most systems, but is smaller for
68000-based Macs.  Making it larger will speed up computations
(by reducing the number of garbage collections) at the cost of
allocating more memory than necessary.


@node   CONTROL STRUCTURES, MACROS, WORKSPACE MANAGEMENT, Top
@chapter Control Structures

@menu
* CONTROL::                     
* TEMPLATE-BASED ITERATION::    
@end menu


@node CONTROL, TEMPLATE-BASED ITERATION, CONTROL STRUCTURES, CONTROL STRUCTURES
@section Control

Note: in the following descriptions, an @dfn{instructionlist} can be a list or
a word.  In the latter case, the word is parsed into list form before it is
run.  Thus, @w{@t{RUN READWORD}} or @w{@t{RUN READLIST}} will work.  The
former is slightly preferable because it allows for a continued line (with @code{~})
that includes a comment (with @code{;}) on the first line.

A @var{tf} input must be the word @code{TRUE}, the word @code{FALSE}, or a list.  If it's a
list, then it must be a Logo expression, which will be evaluated to produce
a value that must be @code{TRUE} or @code{FALSE}.  The comparisons with @code{TRUE} and @code{FALSE}
are always case-insensitive.

A runlist can consist of either a single expression (that produces a value)
or zero or more instructions (that do something, rather than output a value),
depending on the context:

@example
PRINT IFELSE :X<0 ["NEGATIVE] ["POSITIVE]  ; one value in each case
REPEAT 4 [PRINT "A PRINT "B]  ; two instructions
@end example

@menu
* RUN::                         
* RUNRESULT::                   
* REPEAT::                      
* FOREVER::                     
* REPCOUNT::                    
* IF::                          
* IFELSE::                      
* TEST::                        
* IFTRUE::                      
* IFFALSE::                     
* STOP::                        
* OUTPUT::                      
* CATCH::                       
* THROW::                       
* ERROR::                       
* PAUSE::                       
* CONTINUE::                    
* WAIT::                        
* BYE::                         
* dMAYBEOUTPUT::                MAYBEOUTPUT
* GOTO::                        
* TAG::                         
* IGNORE::                      
* back-quote::                  
* FOR::                         
* DOdWHILE::                    DO.WHILE
* WHILE::                       
* DOdUNTIL::                    DO.UNTIL
* UNTIL::                       
* CASE::                        
* COND::                        
@end menu

@node RUN, RUNRESULT, CONTROL, CONTROL
@unnumberedsubsec run
@cindex run

@example
RUN instructionlist
@end example

command or operation.  Runs the Logo instructions in the input list;
outputs if the list contains an expression that outputs.

@xref{READWORD} ,
@ref{READLIST} .

@node RUNRESULT, REPEAT, RUN, CONTROL
@unnumberedsubsec runresult
@cindex runresult

@example
RUNRESULT instructionlist
@end example

runs the instructions in the input; outputs an empty list if those
instructions produce no output, or a list whose only member is the
output from running the input instructionlist.  Useful for inventing
command-or-operation control structures:

@example
local "result
make "result runresult [something]
if emptyp :result [stop]
output first :result
@end example

@node REPEAT, FOREVER, RUNRESULT, CONTROL
@unnumberedsubsec repeat
@cindex repeat

@example
REPEAT num instructionlist
@end example

command.  Runs the @var{instructionlist} repeatedly, @var{num} times.

@node FOREVER, REPCOUNT, REPEAT, CONTROL
@comment  node-name,  next,  previous,  up
@unnumberedsubsec forever
@cindex forever

@example
FOREVER instructionlist
@end example

command.  Runs the "instructionlist" repeatedly, until something inside
the instructionlist (such as @code{STOP} or @code{THROW}) makes it stop.

@xref{STOP} ,
@xref{THROW} .


@node REPCOUNT, IF, FOREVER, CONTROL
@unnumberedsubsec repcount
@cindex repcount

@example
REPCOUNT
@end example

outputs the repetition count of the innermost current @code{REPEAT} or
@code{FOREVER}, starting from 1.  If no @code{REPEAT} or @code{FOREVER}
is active, outputs --1.

The abbreviation @code{#} can be used for @code{REPCOUNT} unless the
@code{REPEAT} is inside the template input to a higher order procedure
such as @code{FOREACH}, in which case @code{#} has a different meaning.

@node IF, IFELSE, REPCOUNT, CONTROL
@unnumberedsubsec if
@cindex if

@example
IF tf instructionlist
(IF tf instructionlist1 instructionlist2)
@end example

command.  If the first input has the value @code{TRUE}, then @code{IF} runs the second
input.  If the first input has the value @code{FALSE}, then @code{IF} does nothing.
(If given a third input, IF acts like @code{IFELSE}, as described below.)  It
is an error if the first input is not either @code{TRUE} or @code{FALSE}.

For compatibility with earlier versions of Logo, if an @code{IF} instruction is
not enclosed in parentheses, but the first thing on the instruction line
after the second input expression is a literal list (i.e., a list in
square brackets), the @code{IF} is treated as if it were @code{IFELSE}, but a warning
message is given.  If this aberrant @code{IF} appears in a procedure body, the
warning is given only the first time the procedure is invoked in each
Logo session.

@node IFELSE, TEST, IF, CONTROL
@unnumberedsubsec ifelse
@cindex ifelse

@example
IFELSE tf instructionlist1 instructionlist2
@end example

command or operation.  If the first input has the value @code{TRUE}, then
@code{IFELSE} runs the second input.  If the first input has the value @code{FALSE},
then @code{IFELSE} runs the third input.  @code{IFELSE} outputs a value if the
@var{instructionlist} contains an expression that outputs a value.

@node TEST, IFTRUE, IFELSE, CONTROL
@unnumberedsubsec test
@cindex test

@example
TEST tf
@end example

command.  Remembers its input, which must be @code{TRUE} or @code{FALSE}, for
use by later @code{IFTRUE} or @code{IFFALSE} instructions.  The effect of
@code{TEST} is local to the procedure in which it is used; any corresponding
@code{IFTRUE} or @code{IFFALSE} must be in the same procedure or a subprocedure.

@xref{IFFALSE} .

@node IFTRUE, IFFALSE, TEST, CONTROL
@unnumberedsubsec iftrue
@cindex iftrue
@cindex ift

@example
IFTRUE instructionlist
IFT instructionlist
@end example

command.  Runs its input if the most recent @code{TEST} instruction had a @code{TRUE}
input.  The @code{TEST} must have been in the same procedure or a
superprocedure.

@node IFFALSE, STOP, IFTRUE, CONTROL
@unnumberedsubsec iffalse
@cindex iffalse
@cindex iff

@example
IFFALSE instructionlist
IFF instructionlist
@end example

command.  Runs its input if the most recent @code{TEST} instruction had a @code{FALSE}
input.  The @code{TEST} must have been in the same procedure or a
superprocedure.

@xref{TEST} .

@node STOP, OUTPUT, IFFALSE, CONTROL
@unnumberedsubsec stop
@cindex stop

@example
STOP
@end example

command.  Ends the running of the procedure in which it appears.
Control is returned to the context in which that procedure was invoked.
The stopped procedure does not output a value.

@node OUTPUT, CATCH, STOP, CONTROL
@unnumberedsubsec output
@cindex output
@cindex op

@example
OUTPUT value
OP value
@end example

command.  Ends the running of the procedure in which it appears.  That
procedure outputs the value @var{value} to the context in which it was
invoked.  Don't be confused: @code{OUTPUT} itself is a command, but the
procedure that invokes @code{OUTPUT} is an operation.

@node CATCH, THROW, OUTPUT, CONTROL
@unnumberedsubsec catch
@cindex catch

@example
CATCH tag instructionlist
@end example

command or operation.  Runs its second input.  Outputs if that
@var{instructionlist} outputs.  If, while running the instructionlist, a
@code{THROW} instruction is executed with a tag equal to the first input
(case-insensitive comparison), then the running of the @var{instructionlist} is
terminated immediately.  In this case the @code{CATCH} outputs if a value input is
given to @code{THROW}.  The @var{tag} must be a word.

If the tag is the word @code{ERROR}, then any error condition that arises
during the running of the instructionlist has the effect of @w{@t{THROW "ERROR}}
instead of printing an error message and returning to toplevel.  The
@code{CATCH} does not output if an error is caught.  Also, during the running
of the instructionlist, the variable @code{ERRACT} is temporarily unbound.  (If
there is an error while @code{ERRACT} has a value, that value is taken as an
instructionlist to be run after printing the error message.  Typically
the value of @code{ERRACT}, if any, is the list @code{[PAUSE]}.)

@xref{ERROR} ,
@ref{ERRACT} ,
@ref{PAUSE} .

@node THROW, ERROR, CATCH, CONTROL
@unnumberedsubsec throw
@cindex throw

@example
THROW tag
(THROW tag value)
@end example

command.  Must be used within the scope of a @code{CATCH} with an equal tag.
Ends the running of the instructionlist of the @code{CATCH}.  If @code{THROW} is used
with only one input, the corresponding @code{CATCH} does not output a value.
If @code{THROW} is used with two inputs, the second provides an output for the
@code{CATCH}.

@w{@t{THROW "TOPLEVEL}} can be used to terminate all running procedures and
interactive pauses, and return to the toplevel instruction prompt.  Typing the
system interrupt character (@key{alt-S} for wxWidgets; otherwise normally
@key{control-C} for Unix, @key{control-Q} for DOS, or @key{command-period} for
Mac) has the same effect.

@w{@t{THROW "ERROR}} can be used to generate an error condition.  If the error
is not caught, it prints a message (@w{@code{THROW "ERROR}}) with the usual
indication of where the error (in this case the @code{THROW}) occurred.  If a
second input is used along with a tag of @code{ERROR}, that second input is
used as the text of the error message instead of the standard message.
Also, in this case, the location indicated for the error will be, not
the location of the @code{THROW}, but the location where the procedure
containing the @code{THROW} was invoked.  This allows user-defined procedures
to generate error messages as if they were primitives.  Note: in this
case the corresponding @w{@t{CATCH "ERROR}}, if any, does not output, since the
second input to @code{THROW} is not considered a return value.

@w{@t{THROW "SYSTEM}} immediately leaves Logo, returning to the operating
system, without printing the usual parting message and without deleting
any editor temporary file written by EDIT.

@xref{EDIT} .

@node ERROR, PAUSE, THROW, CONTROL
@unnumberedsubsec error
@cindex error

@example
ERROR
@end example

outputs a list describing the error just caught, if any.  If there was not an
error caught since the last use of @code{ERROR}, the empty list will be
output.  The error list contains four members: an integer code corresponding
to the type of error, the text of the error message (as a single word
including spaces), the name of the procedure in which the error occurred, and
the instruction line on which the error occurred.

@node PAUSE, CONTINUE, ERROR, CONTROL
@unnumberedsubsec pause
@cindex pause

@example
PAUSE
@end example

command or operation.  Enters an interactive pause.  The user is
prompted for instructions, as at toplevel, but with a prompt that
includes the name of the procedure in which @code{PAUSE} was invoked.  Local
variables of that procedure are available during the pause.  @code{PAUSE}
outputs if the pause is ended by a @code{CONTINUE} with an input.

If the variable @code{ERRACT} exists, and an error condition occurs, the
contents of that variable are run as an instructionlist.  Typically
@code{ERRACT} is given the value @code{[PAUSE]} so that an interactive pause will be
entered in the event of an error.  This allows the user to check values
of local variables at the time of the error.

Typing the system quit character (@key{alt-S} for wxWidgets; otherwise
normally @key{control-\} for Unix, @key{control-W} for DOS, or
@key{command-comma} for Mac) will also enter a pause.

@xref{ERRACT} .

@node CONTINUE, WAIT, PAUSE, CONTROL
@unnumberedsubsec continue
@cindex continue
@cindex co

@example
CONTINUE value
CO value
(CONTINUE)
(CO)
@end example

command.  Ends the current interactive pause, returning to the context
of the @code{PAUSE} invocation that began it.  If @code{CONTINUE} is given an input,
that value is used as the output from the @code{PAUSE}.  If not, the @code{PAUSE} does
not output.

Exceptionally, the @code{CONTINUE} command can be used without its default
input and without parentheses provided that nothing follows it on the
instruction line.

@node WAIT, BYE, CONTINUE, CONTROL
@unnumberedsubsec wait
@cindex wait

@example
WAIT time
@end example

command.  Delays further execution for @var{time} 60ths of a second.  Also
causes any buffered characters destined for the terminal to be printed
immediately.  @w{@t{WAIT 0}} can be used to achieve this buffer flushing without actually waiting.

@node BYE, dMAYBEOUTPUT, WAIT, CONTROL
@unnumberedsubsec bye
@cindex bye

@example
BYE
@end example

command.  Exits from Logo; returns to the operating system.

@node dMAYBEOUTPUT, GOTO, BYE, CONTROL
@unnumberedsubsec .maybeoutput
@cindex .maybeoutput

@example
.MAYBEOUTPUT value				(special form)
@end example

works like @code{OUTPUT} except that the expression that provides the input
value might not, in fact, output a value, in which case the effect is
like @code{STOP}.  This is intended for use in control structure definitions,
for cases in which you don't know whether or not some expression
produces a value.  Example:

@example
to invoke :function [:inputs] 2
.maybeoutput apply :function :inputs
end

? (invoke "print "a "b "c)
a b c
? print (invoke "word "a "b "c)
abc
@end example

This is an alternative to @code{RUNRESULT}.  It's fast and easy to use, at the
cost of being an exception to Logo's evaluation rules.  (Ordinarily, it
should be an error if the expression that's supposed to provide an input
to something doesn't have a value.)

@xref{OUTPUT} ,
@ref{STOP} ,
@ref{RUNRESULT} .

@node GOTO, TAG, dMAYBEOUTPUT, CONTROL
@unnumberedsubsec goto
@cindex goto

@example
GOTO word
@end example

command.  Looks for a @code{TAG} command with the same input in the same
procedure, and continues running the procedure from the location of that
@code{TAG}.  It is meaningless to use @code{GOTO} outside of a procedure.

@node TAG, IGNORE, GOTO, CONTROL
@unnumberedsubsec tag
@cindex tag

@example
TAG quoted.word
@end example

command.  Does nothing.  The input must be a literal word following a
quotation mark (@code{"}), not the result of a computation.  Tags are used by
the @code{GOTO} command.

@node IGNORE, back-quote, TAG, CONTROL
@unnumberedsubsec ignore
@cindex ignore

@example
IGNORE value					(library procedure)
@end example

command.  Does nothing.  Used when an expression is evaluated for a side
effect and its actual value is unimportant.

@node back-quote, FOR, IGNORE, CONTROL
@unnumberedsubsec `
@cindex `

@example
` list						(library procedure)
@end example

outputs a list equal to its input but with certain substitutions.  If a
member of the input list is the word @samp{,} (comma) then the following
member should be an instructionlist that produces an output when run.
That output value replaces the comma and the instructionlist.  If a
member of the input list is the word @samp{,@@} (comma atsign) then the
following member should be an instructionlist that outputs a list when
run.  The members of that list replace the @samp{,@@} and the instructionlist.
Example:

@example
show `[foo baz ,[bf [a b c]] garply ,@@[bf [a b c]]]
@end example

will print

@example
[foo baz [b c] garply b c]
@end example

A word starting with @samp{,} or @samp{,@@} is treated as if the rest of the
word were a one-word list, e.g., @samp{,:foo} is equivalent to @samp{,[:Foo]}.

A word starting with @samp{",} (quote comma) or @samp{:,} (colon comma)
becomes a word starting with @samp{"} or @samp{:} but with the result of
running the substitution (or its first word, if the result is a list)
replacing what comes after the comma.

Backquotes can be nested.  Substitution is done only for commas at
the same depth as the backquote in which they are found:

@example
? show `[a `[b ,[1+2] ,[foo ,[1+3] d] e] f]
[a ` [b , [1+2] , [foo 4 d] e] f]

?make "name1 "x
?make "name2 "y
? show `[a `[b ,:,:name1 ,",:name2 d] e]
[a ` [b , [:x] , ["y] d] e]
@end example

@node FOR, DOdWHILE, back-quote, CONTROL
@unnumberedsubsec for
@cindex for

@example
FOR forcontrol instructionlist			(library procedure)
@end example

command.  The first input must be a list containing three or four
members: (1) a word, which will be used as the name of a local variable;
(2) a word or list that will be evaluated as by @code{RUN} to determine a
number, the starting value of the variable; (3) a word or list that will
be evaluated to determine a number, the limit value of the variable; (4)
an optional word or list that will be evaluated to determine the step
size.  If the fourth member is missing, the step size will be 1 or --1
depending on whether the limit value is greater than or less than the
starting value, respectively.

The second input is an instructionlist.  The effect of @code{FOR} is to run
that instructionlist repeatedly, assigning a new value to the control
variable (the one named by the first member of the @var{forcontrol} list) each
time.  First the starting value is assigned to the control variable.
Then the value is compared to the limit value.  @code{FOR} is complete when the
sign of @code{(current - limit)} is the same as the sign of the step size.  (If
no explicit step size is provided, the instructionlist is always run at
least once.  An explicit step size can lead to a zero-trip @code{FOR}, e.g.,
@w{@t{FOR [I 1 0 1] ...})}. Otherwise, the instructionlist is run, then the step is added to the current value of the control variable and FOR returns to
the comparison step.

@example
? for [i 2 7 1.5] [print :i]
2
3.5
5
6.5
?
@end example

@xref{RUN} .

@node DOdWHILE, WHILE, FOR, CONTROL
@unnumberedsubsec do.while
@cindex do.while

@example
DO.WHILE instructionlist tfexpression		(library procedure)
@end example

command.  Repeatedly evaluates the @var{instructionlist} as long as the
evaluated 
@ifinfo
@var{tfexpression}
@end ifinfo
@tex
@var{tfexpres-sion}
@end tex
remains @code{TRUE}.  Evaluates the first input first,
so the @var{instructionlist} is always run at least once.  The
@var{tfexpression} must be an expressionlist whose value when evaluated is
@code{TRUE} or @code{FALSE}.

@node WHILE, DOdUNTIL, DOdWHILE, CONTROL
@unnumberedsubsec while
@cindex while

@example
WHILE tfexpression instructionlist		(library procedure)
@end example

command.  Repeatedly evaluates the @var{instructionlist} as long as the
evaluated
@ifinfo
@var{tfexpression}
@end ifinfo
@tex
@var{tfexpres-sion}
@end tex
remains @code{TRUE}.  Evaluates the first input first,
so the @var{instructionlist} may never be run at all.  The @var{tfexpression}
must be an expressionlist whose value when evaluated is @code{TRUE} or @code{FALSE}.

@node DOdUNTIL, UNTIL, WHILE, CONTROL
@unnumberedsubsec do.until
@cindex do.until

@example
DO.UNTIL instructionlist tfexpression		(library procedure)
@end example

command.  Repeatedly evaluates the @var{instructionlist} as long as the
evaluated
@ifinfo
@var{tfexpression}
@end ifinfo
@tex
@var{tfexpres-sion}
@end tex
remains @code{FALSE}.  Evaluates the first input
first, so the @var{instructionlist} is always run at least once.  The
@var{tfexpression} must be an expressionlist whose value when evaluated is
@code{TRUE} or @code{FALSE}.

@node UNTIL, CASE, DOdUNTIL, CONTROL
@unnumberedsubsec until
@cindex until

@example
UNTIL tfexpression instructionlist		(library procedure)
@end example

command.  Repeatedly evaluates the @var{instructionlist} as long as the
evaluated
@ifinfo
@var{tfexpression}
@end ifinfo
@tex
@var{tfexpres-sion}
@end tex
remains @code{FALSE}.  Evaluates the first input
first, so the @var{instructionlist} may never be run at all.  The
@var{tfexpression} must be an expressionlist whose value when evaluated is
@code{TRUE} or @code{FALSE}.

@node CASE, COND, UNTIL, CONTROL
@unnumberedsubsec case
@cindex case

@example
CASE value clauses					(library procedure)
@end example

command or operation.  The second input is a list of lists (clauses);
each clause is a list whose first element is either a list of values
or the word @code{ELSE} and whose butfirst is a Logo expression or
instruction.  @code{CASE} examines the clauses in order.  If a clause begins
with the word @code{ELSE} (upper or lower case), then the butfirst of that
clause is evaluated and @code{CASE} outputs its value, if any.  If the first
input to CASE is a member of the first element of a clause, then the
butfirst of that clause is evaluated and @code{CASE} outputs its value, if
any.  If neither of these conditions is met, then @code{CASE} goes on to the
next clause.  If no clause is satisfied, @code{CASE} does nothing.  
Example:

@example
to vowelp :letter
output case :letter [ [[a e i o u] "true] [else "false] ]
end
@end example

@node COND,  , CASE, CONTROL
@unnumberedsubsec cond
@cindex cond

@example
COND clauses						(library procedure)
@end example

command or operation.  The input is a list of lists (clauses); each
clause is a list whose first element is either an expression whose
value is @code{TRUE} or @code{FALSE}, or the word @code{ELSE}, and whose butfirst is a Logo
expression or instruction.  @code{COND} examines the clauses in order.  If a
clause begins with the word @code{ELSE} (upper or lower case), then the
butfirst of that clause is evaluated and @code{CASE} outputs its value, if
any.  Otherwise, the first element of the clause is evaluated; the
resulting value must be @code{TRUE} or @code{FALSE}.  If it's @code{TRUE}, then the
butfirst of that clause is evaluated and @code{COND} outputs its value, if
any.  If the value is @code{FALSE}, then @code{COND} goes on to the next clause.  If
no clause is satisfied, @code{COND} does nothing.  Example:

@example
to evens :numbers	; select even numbers from a list
op cond [ [[emptyp :numbers] []]
          [[evenp first :numbers]	; assuming EVENP is defined
           fput first :numbers evens butfirst :numbers]
          [else evens butfirst :numbers] ]
end
@end example

@node TEMPLATE-BASED ITERATION,  , CONTROL, CONTROL STRUCTURES
@section Template-based Iteration
@cindex template

The procedures in this section are iteration tools based on the idea of a
@dfn{template.}  This is a generalization of an instruction list or an
expression list in which @dfn{slots} are provided for the tool to insert varying
data.  Four different forms of template can be used.

The most commonly used form for a template is @samp{explicit-slot} form, or
@samp{question mark} form.  Example:

@example
? show map [? * ?] [2 3 4 5]
[4 9 16 25]
?
@end example

In this example, the @code{MAP} tool evaluated the template @w{@code{[? * ?]}}
repeatedly, with each of the members of the data list @w{@code{[2 3 4 5]}}
substituted in turn for the question marks.  The same value was used for every
question mark in a given evaluation.  Some tools allow for more than one datum
to be substituted in parallel; in these cases the slots are indicated by
@code{?1} for the first datum, @code{?2} for the second, and so on:

@example
? show (map [(word ?1 ?2 ?1)] [a b c] [d e f])
[ada beb cfc]
?
@end example

If the template wishes to compute the datum number, the form @w{@code{(? 1)}} is
equivalent to @code{?1}, so @w{@code{(? ?1)}} means the datum whose number is given in
datum number 1.  Some tools allow additional slot designations, as shown
in the individual descriptions.

The second form of template is the @samp{named-procedure} form.  If the
template is a word rather than a list, it is taken as the name of a procedure.
That procedure must accept a number of inputs equal to the number of parallel
data slots provided by the tool; the procedure is applied to all of the
available data in order.  That is, if data @code{?1} through @code{?3} are
available, the template @code{"PROC} is equivalent to @w{@t{[PROC ?1 ?2 ?3]}}.

@example
? show (map "word [a b c] [d e f])
[ad be cf]
?

to dotprod :a :b	; vector dot product
op apply "sum (map "product :a :b)
end
@end example

The third form of template is @samp{named-slot} or @samp{lambda} form.  This
form is indicated by a template list containing more than one member, whose
first member is itself a list.  The first member is taken as a list of names;
local variables are created with those names and given the available data in
order as their values.  The number of names must equal the number of available
data.  This form is needed primarily when one iteration tool must be used
within the template list of another, and the @code{?} notation would be ambiguous in
the inner template.  Example:

@example
to matmul :m1 :m2 [:tm2 transpose :m2]	; multiply two matrices
output map [[row] map [[col] dotprod :row :col] :tm2] :m1
end
@end example

The fourth form is @samp{procedure text} form, a variant of lambda form.  In
this form, the template list contains at least two members, all of which are
lists.  This is the form used by the @code{DEFINE} and @code{TEXT} primitives,
and @code{APPLY} accepts it so that the text of a defined procedure can be
used as a template.

Note:  The fourth form of template is interpreted differently from the others,
in that Logo considers it to be an independent defined procedure for the
purposes of @code{OUTPUT} and @code{STOP}.  For example, the following two
instructions are identical:

@example
? print apply [[x] :x+3] [5]
8
? print apply [[x] [output :x+3]] [5]
8
@end example

although the first instruction is in named-slot form and the second is in
procedure-text form.  The named-slot form can be understood as telling Logo to
evaluate the expression @w{@t{:x+3}} in place of the entire invocation of
apply, with the variable @code{x} temporarily given the value @code{5}.  The
procedure-text form can be understood as invoking the procedure

@example
to foo :x
output :x+3
end
@end example

with input @code{5}, but without actually giving the procedure a name.  If
the use of @code{OUTPUT} were interchanged in these two examples, we'd get errors:

@example
? print apply [[x] output :x+3] [5]
Can only use output inside a procedure
? print apply [[x] [:x+3]] [5]
You don't say what to do with 8
@end example

The named-slot form can be used with @code{STOP} or @code{OUTPUT} inside a procedure,
to stop the enclosing procedure.

The following iteration tools are extended versions of the ones in Appendix
B of the book @cite{Computer Science Logo Style, Volume 3:  Advanced Topics} by
Brian Harvey [MIT Press, 1987].  The extensions are primarily to allow for
variable numbers of inputs.


@menu
* APPLY::                       
* INVOKE::                      
* FOREACH::                     
* MAP::                         
* MAPdSE::                      MAP.SE
* FILTER::                      
* FIND::                        
* REDUCE::                      
* CROSSMAP::                    
* CASCADE::                     
* CASCADEd2::                   CASCADE.2
* TRANSFER::                    
@end menu

@node APPLY, INVOKE, TEMPLATE-BASED ITERATION, TEMPLATE-BASED ITERATION
@unnumberedsubsec apply
@cindex apply

@example
APPLY template inputlist
@end example

command or operation.  Runs the @var{template}, filling its slots with the
members of @var{inputlist.}  The number of members in @var{inputlist} must be an
acceptable number of slots for @var{template}.  It is illegal to apply the
primitive @code{TO} as a template, but anything else is okay.  @code{APPLY} outputs
what @var{template} outputs, if anything.

@xref{TO} .

@node INVOKE, FOREACH, APPLY, TEMPLATE-BASED ITERATION
@unnumberedsubsec invoke
@cindex invoke

@example
INVOKE template input				(library procedure)
(INVOKE template input1 input2 ...)
@end example

command or operation.  Exactly like @code{APPLY} except that the inputs are
provided as separate expressions rather than in a list.

@node FOREACH, MAP, INVOKE, TEMPLATE-BASED ITERATION
@unnumberedsubsec foreach
@cindex foreach

@example
FOREACH data template				(library procedure)
(FOREACH data1 data2 ... template)
@end example

command.  Evaluates the @var{template} list repeatedly, once for each member
of the @var{data} list.  If more than one @var{data} list are given, each of them
must be the same length.  (The @var{data} inputs can be words, in which case
the template is evaluated once for each character.)

In a template, the symbol @code{?REST} represents the portion of the
@var{data} input to the right of the member currently being used as the
@code{?} slot-filler.  That is, if the @var{data} input is
@w{@code{[A B C D E]}} and the template is being evaluated with @code{?}
replaced by @code{B}, then @code{?REST} would be replaced by
@w{@code{[C D E]}}.  If multiple parallel slots are used, then
@w{@t{(?REST 1)}} goes with ?1, etc.

In a template, the symbol @code{#} represents the position in the @var{data}
input of the member currently being used as the @code{?} slot-filler.  That is, if
the data input is @w{@code{[A B C D E]}} and the template is being evaluated with
@code{?} replaced by @code{B}, then @code{#} would be replaced by @code{2}.

@node MAP, MAPdSE, FOREACH, TEMPLATE-BASED ITERATION
@unnumberedsubsec map
@cindex map

@example
MAP template data				(library procedure)
(MAP template data1 data2 ...)
@end example

outputs a word or list, depending on the type of the @var{data} input, of the
same length as that @var{data} input.  (If more than one @var{data} input are
given, the output is of the same type as @var{data1}.)  Each member of the
output is the result of evaluating the @var{template} list, filling the slots
with the corresponding member(s) of the @var{data} input(s).  (All @var{data}
inputs must be the same length.)  In the case of a word output, the results of
the template evaluation must be words, and they are concatenated with
@code{WORD}.

In a template, the symbol @code{?REST} represents the portion of the data
input to the right of the member currently being used as the @code{?}
slot-filler.  That is, if the @var{data} input is @w{@code{[A B C D E]}} and
the @var{template} is being evaluated with @code{?} replaced by @code{B}, then
@code{?REST} would be replaced by @w{@code{[C D E]}}. If multiple parallel
slots are used, then @w{@t{(?REST 1)}} goes with @code{?1}, etc.

In a template, the symbol @code{#} represents the position in the @var{data}
input of the member currently being used as the @code{?} slot-filler.  That
is, if the data input is @w{@code{[A B C D E]}} and the template is being
evaluated with @code{?} replaced by @code{B}, then @code{#} would be replaced
by @code{2}.

@xref{WORD} .

@node MAPdSE, FILTER, MAP, TEMPLATE-BASED ITERATION
@unnumberedsubsec map.se
@cindex map.se

@example
MAP.SE template data				(library procedure)
(MAP.SE template data1 data2 ...)
@end example

outputs a list formed by evaluating the @var{template} list repeatedly and
concatenating the results using @code{SENTENCE}.  That is, the members of the
output are the members of the results of the evaluations.  The output
list might, therefore, be of a different length from that of the @var{data}
input(s).  (If the result of an evaluation is the empty list, it
contributes nothing to the final output.)  The @var{data} inputs may be words
or lists.

In a template, the symbol @code{?REST} represents the portion of the data
input to the right of the member currently being used as the @code{?}
slot-filler.  That is, if the data input is @w{@code{[A B C D E]}} and the
template is being evaluated with @code{?} replaced by @code{B}, then
@code{?REST} would be replaced by @w{@code{[C D E]}}. If multiple parallel
slots are used, then @w{@t{(?REST 1)}} goes with @code{?1}, etc.

In a template, the symbol @code{#} represents the position in the @var{data}
input of the member currently being used as the @code{?} slot-filler.  That
is, if the data input is @w{@code{[A B C D E]}} and the template is being
evaluated with @code{?} replaced by @code{B}, then @code{#} would be replaced
by @code{2}.

@xref{SENTENCE} .

@node FILTER, FIND, MAPdSE, TEMPLATE-BASED ITERATION
@unnumberedsubsec filter
@cindex filter

@example
FILTER tftemplate data				(library procedure)
@end example

outputs a word or list, depending on the type of the @var{data} input,
containing a subset of the members (for a list) or characters (for a
word) of the input.  The template is evaluated once for each member or
character of the data, and it must produce a @code{TRUE} or @code{FALSE} value.  If
the value is @code{TRUE}, then the corresponding input constituent is included
in the output.

@example
? print filter "vowelp "elephant 
eea 
?
@end example

In a template, the symbol @code{?REST} represents the portion of the
@var{data} input to the right of the member currently being used as the
@code{?} slot-filler.  That is, if the data input is @w{@code{[A B C D E]}}
and the template is being evaluated with @code{?} replaced by @code{B}, then
@code{?REST} would be replaced by @w{@code{[C D E]}}.

In a template, the symbol @code{#} represents the position in the @var{data}
input of the member currently being used as the @code{?} slot-filler.  That
is, if the data input is @w{@code{[A B C D E]}} and the template is being
evaluated with @code{?} replaced by @code{B}, then @code{#} would be replaced
by @code{2}.

@node FIND, REDUCE, FILTER, TEMPLATE-BASED ITERATION
@unnumberedsubsec find
@cindex find

@example
FIND tftemplate data				(library procedure)
@end example

outputs the first constituent of the @var{data} input (the first member of a
list, or the first character of a word) for which the value produced by
evaluating the @var{template} with that consituent in its slot is @code{TRUE}.
If there is no such constituent, the empty list is output.

In a template, the symbol @code{?REST} represents the portion of the
@var{data} input to the right of the member currently being used as the
@code{?} slot-filler.  That is, if the data input is @w{@code{[A B C D E]}}
and the template is being evaluated with @code{?} replaced by @code{B}, then
@code{?REST} would be replaced by @w{@code{[C D E]}}.

In a template, the symbol @code{#} represents the position in the @var{data}
input of the member currently being used as the @code{?} slot-filler.  That
is, if the data input is @w{@code{[A B C D E]}} and the template is being
evaluated with @code{?} replaced by @code{B}, then @code{#} would be replaced
by @code{2}.

@node REDUCE, CROSSMAP, FIND, TEMPLATE-BASED ITERATION
@unnumberedsubsec reduce
@cindex reduce

@example
REDUCE template data				(library procedure)
@end example

outputs the result of applying the @var{template} to accumulate the members of
the @var{data} input.  The template must be a two-slot function.  Typically it
is an associative function name like @code{SUM}.  If the @var{data} input has
only one constituent (member in a list or character in a word), the output is
that consituent.  Otherwise, the template is first applied with @code{?1}
filled with the next-to-last consitient and @code{?2} with the last
constituent.  Then, if there are more constituents, the template is applied
with @code{?1} filled with the next constituent to the left and @code{?2} with
the result from the previous evaluation.  This process continues until all
constituents have been used.  The data input may not be empty.

Note: If the template is, like @code{SUM}, the name of a procedure that is
capable of accepting arbitrarily many inputs, it is more efficient to
use @code{APPLY} instead of @code{REDUCE}.  The latter is good for associative
procedures that have been written to accept exactly two inputs:

@example
to max :a :b
output ifelse :a > :b [:a] [:b]
end

print reduce "max [...]
@end example

Alternatively, @code{REDUCE} can be used to write @code{MAX} as a procedure
that accepts any number of inputs, as @code{SUM} does:

@example
to max [:inputs] 2
if emptyp :inputs ~
   [(throw "error [not enough inputs to max])]
output reduce [ifelse ?1 > ?2 [?1] [?2]] :inputs
end
@end example

@xref{SUM} ,
@ref{APPLY} .

@node CROSSMAP, CASCADE, REDUCE, TEMPLATE-BASED ITERATION
@unnumberedsubsec crossmap
@cindex crossmap

@example
CROSSMAP template listlist			(library procedure)
(CROSSMAP template data1 data2 ...)
@end example

outputs a list containing the results of template evaluations.  Each
@var{data} list contributes to a slot in the template; the number of slots is
equal to the number of @var{data} list inputs.  As a special case, if only one
@var{data} list input is given, that list is taken as a list of data lists,
and each of its members contributes values to a slot.  @code{CROSSMAP} differs
from @code{MAP} in that instead of taking members from the data inputs in
parallel, it takes all possible combinations of members of data inputs,
which need not be the same length.

@example
? show (crossmap [word ?1 ?2] [a b c] [1 2 3 4])
[a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4]
?
@end example

For compatibility with the version in the first edition of CSLS
@footnote{@cite{Computer Science Logo Style}}, @code{CROSSMAP} templates may
use the notation @code{:1} instead of @code{?1} to indicate slots.

@xref{MAP} .

@node CASCADE, CASCADEd2, CROSSMAP, TEMPLATE-BASED ITERATION
@unnumberedsubsec cascade
@cindex cascade

@example
CASCADE endtest template startvalue		(library procedure)
(CASCADE endtest tmp1 sv1 tmp2 sv2 ...)
(CASCADE endtest tmp1 sv1 tmp2 sv2 ... finaltemplate)
@end example

outputs the result of applying a template (or several templates, as
explained below) repeatedly, with a given value filling the slot the
first time, and the result of each application filling the slot for the
following application.

In the simplest case, @code{CASCADE} has three inputs.  The second input is a
one-slot expression template.  That template is evaluated some number of
times (perhaps zero).  On the first evaluation, the slot is filled with
the third input; on subsequent evaluations, the slot is filled with the
result of the previous evaluation.  The number of evaluations is
determined by the first input.  This can be either a nonnegative
integer, in which case the template is evaluated that many times, or a
predicate expression template, in which case it is evaluated (with the
same slot filler that will be used for the evaluation of the second
input) repeatedly, and the @code{CASCADE} evaluation continues as long as the
predicate value is @code{FALSE}.  (In other words, the predicate template
indicates the condition for stopping.)

If the template is evaluated zero times, the output from @code{CASCADE} is the
third (@var{startvalue}) input.  Otherwise, the output is the value produced
by the last template evaluation.

@code{CASCADE} templates may include the symbol @code{#} to represent the
number of times the template has been evaluated.  This slot is filled with 1
for the first evaluation, 2 for the second, and so on.

@example
? show cascade 5 [lput # ?] []
[1 2 3 4 5]
? show cascade [vowelp first ?] [bf ?] "spring
ing
? show cascade 5 [# * ?] 1
120
?
@end example

Several cascaded results can be computed in parallel by providing additional
template-startvalue pairs as inputs to @code{CASCADE}.  In this case, all
templates (including the endtest template, if used) are multi-slot, with the
number of slots equal to the number of pairs of inputs.  In each round of
evaluations, @code{?2}, for example, represents the result of evaluating the
second template in the previous round.  If the total number of inputs
(including the first endtest input) is odd, then the output from CASCADE is
the final value of the first template.  If the total number of inputs is even,
then the last input is a template that is evaluated once, after the end test
is satisfied, to determine the output from @code{CASCADE}.

@example
to fibonacci :n
output (cascade :n [?1 + ?2] 1 [?1] 0)
end

to piglatin :word
output (cascade [vowelp first ?] ~
                [word bf ? first ?] ~
                :word ~
                [word ? "ay])
end
@end example

@node CASCADEd2, TRANSFER, CASCADE, TEMPLATE-BASED ITERATION
@unnumberedsubsec cascade.2
@cindex cascade.2

@example
CASCADE.2 endtest temp1 startval1 temp2 startval2  (library procedure)
@end example

outputs the result of invoking @code{CASCADE} with the same inputs.  The only
difference is that the default number of inputs is five instead of three.

@node TRANSFER,  , CASCADEd2, TEMPLATE-BASED ITERATION
@unnumberedsubsec transfer
@cindex transfer

@example
TRANSFER endtest template inbasket		(library procedure)
@end example

outputs the result of repeated evaluation of the @var{template}.  The template
is evaluated once for each member of the list @var{inbasket}.  @code{TRANSFER}
maintains an @dfn{outbasket} that is initially the empty list.  After each
evaluation of the template, the resulting value becomes the new
outbasket.

In the template, the symbol @code{?IN} represents the current member from the
inbasket; the symbol @code{?OUT} represents the entire current outbasket.
Other slot symbols should not be used.

If the first (@var{endtest}) input is an empty list, evaluation continues
until all inbasket members have been used.  If not, the first input must
be a predicate expression template, and evaluation continues until
either that template's value is @code{TRUE} or the inbasket is used up.



@node   MACROS, ERROR PROCESSING, CONTROL STRUCTURES, Top
@chapter Macros

@menu
* dMACRO::
* dDEFMACRO::
* MACROP::                      
* MACROEXPAND::                 
@end menu

@node dMACRO, dDEFMACRO, MACROS, MACROS
@unnumberedsec .macro
@cindex .macro
@cindex .defmacro

@example
.MACRO procname :input1 :input2 ...			(special form)
.DEFMACRO procname text
@end example

A macro is a special kind of procedure whose output is evaluated as Logo
instructions in the context of the macro's caller.  @code{.MACRO} is exactly
like @code{TO} except that the new procedure becomes a macro; @code{.DEFMACRO}
is exactly like @code{DEFINE} with the same exception.

Macros are useful for inventing new control structures comparable to
@code{REPEAT}, @code{IF}, and so on.  Such control structures can almost, but
not quite, be duplicated by ordinary Logo procedures.  For example, here is an
ordinary procedure version of @code{REPEAT}:

@example
to my.repeat :num :instructions
if :num=0 [stop]
run :instructions
my.repeat :num-1 :instructions
end
@end example

This version works fine for most purposes, e.g.,

@example
my.repeat 5 [print "hello]
@end example

But it doesn't work if the instructions to be carried out include
@code{OUTPUT}, @code{STOP}, or @code{LOCAL}.  For example, consider this
procedure:

@example
to example
print [Guess my secret word.  You get three guesses.]
repeat 3 [type "|?? | ~
          if readword = "secret [pr "Right! stop]]
print [Sorry, the word was "secret"!]
end
@end example

This procedure works as written, but if @code{MY.REPEAT} is used instead of
@code{REPEAT}, it won't work because the @code{STOP} will stop
@code{MY.REPEAT} instead of stopping @code{EXAMPLE} as desired.

The solution is to make @code{MY.REPEAT} a macro.  Instead of actually carrying
out the computation, a macro must return a list containing Logo
instructions.  The contents of that list are evaluated as if they
appeared in place of the call to the macro.  Here's a macro version of
@code{REPEAT}:

@example
.macro my.repeat :num :instructions
if :num=0 [output []]
output sentence :instructions ~
                (list "my.repeat :num-1 :instructions)
end
@end example

Every macro is an operation --- it must always output something.  Even in
the base case, @code{MY.REPEAT} outputs an empty instruction list.  To show how
@code{MY.REPEAT} works, let's take the example

@example
my.repeat 5 [print "hello]
@end example

For this example, @code{MY.REPEAT} will output the instruction list

@example
[print "hello my.repeat 4 [print "hello]]
@end example

Logo then executes these instructions in place of the original invocation of
@code{MY.REPEAT}; this prints @code{hello} once and invokes another
repetition.

The technique just shown, although fairly easy to understand, has the
defect of slowness because each repetition has to construct an
instruction list for evaluation.  Another approach is to make @code{MY.REPEAT}
a macro that works just like the non-macro version unless the
instructions to be repeated include @code{OUTPUT} or @code{STOP}:

@example
.macro my.repeat :num :instructions
catch "repeat.catchtag ~
      [op repeat.done runresult [repeat1 :num :instructions]]
op []
end

to repeat1 :num :instructions
if :num=0 [throw "repeat.catchtag]
run :instructions
.maybeoutput repeat1 :num-1 :instructions
end

to repeat.done :repeat.result
if emptyp :repeat.result [op [stop]]
op list "output quoted first :repeat.result
end
@end example

If the instructions do not include @code{STOP} or @code{OUTPUT}, then
@code{REPEAT1} will reach its base case and invoke @code{THROW}.  As a result,
@code{MY.REPEAT}'s last instruction line will output an empty list, so the
evaluation of the macro result by the caller will do nothing.  But if a
@code{STOP} or @code{OUTPUT} happens, then @code{REPEAT.DONE} will output a
@code{STOP} or @code{OUTPUT} instruction that will be executed in the
caller's context.

The macro-defining commands have names starting with a dot because
macros are an advanced feature of Logo; it's easy to get in trouble by
defining a macro that doesn't terminate, or by failing to construct the
instruction list properly.

Lisp users should note that Logo macros are @emph{not} special forms.  That is,
the inputs to the macro are evaluated normally, as they would be for any
other Logo procedure.  It's only the output from the macro that's
handled unusually.

Here's another example:

@example
.macro localmake :name :value
output (list "local          ~
             word "" :name   ~
             "apply          ~
             ""make          ~
             (list :name :value))
end
@end example

It's used this way:

@example
to try
localmake "garply "hello
print :garply
end
@end example

@code{LOCALMAKE} outputs the list

@display
[local "garply apply "make [garply hello]]
@end display

The reason for the use of @code{APPLY} is to avoid having to decide whether or
not the second input to @code{MAKE} requires a quotation mark before it.  (In
this case it would --- @code{MAKE "GARPLY "HELLO} --- but the quotation mark
would be wrong if the value were a list.)

It's often convenient to use the @t{`} function to construct the instruction
list:

@example
.macro localmake :name :value
op `[local ,[word "" :name] apply "make [,[:name] ,[:value]]]
end
@end example

On the other hand, @t{`} is pretty slow, since it's tree recursive and
written in Logo.

@xref{TO} ,
@ref{DEFINE} ,
@ref{APPLY} ,
@ref{STOP} ,
@ref{OUTPUT} .

@node dDEFMACRO, MACROP, dMACRO, MACROS
@unnumberedsubsec .defmacro

@xref{dMACRO} .

@node MACROP, MACROEXPAND, dDEFMACRO, MACROS
@unnumberedsubsec macrop
@cindex macrop
@cindex macro?

@example
MACROP name
MACRO? name
@end example

outputs @code{TRUE} if its input is the name of a macro.

@node MACROEXPAND,  , MACROP, MACROS
@unnumberedsubsec macroexpand
@cindex macroexpand

@example
MACROEXPAND expr				(library procedure)
@end example

takes as its input a Logo expression that invokes a macro (that is, one
that begins with the name of a macro) and outputs the the Logo
expression into which the macro would translate the input expression.

@example
.macro localmake :name :value
op `[local ,[word "" :name] apply "make [,[:name] ,[:value]]]
end

? show macroexpand [localmake "pi 3.14159]
[local "pi apply "make [pi 3.14159]]
@end example



@node   ERROR PROCESSING, SPECIAL VARIABLES, MACROS, Top
@chapter Error Processing

@menu
* ERROR CODES::                 
@end menu

If an error occurs, Logo takes the following steps.  First, if there is an
available variable named @code{ERRACT}, Logo takes its value as an
instructionlist and runs the instructions.  The operation @code{ERROR} may be
used within the instructions (once) to examine the error condition.  If the
instructionlist invokes @code{PAUSE}, the error message is printed before the
pause happens.  Certain errors are @dfn{recoverable}; for one of those errors,
if the instructionlist outputs a value, that value is used in place of the
expression that caused the error.  (If @code{ERRACT} invokes @code{PAUSE} and
the user then invokes @code{CONTINUE} with an input, that input becomes the
output from @code{PAUSE} and therefore the output from the @code{ERRACT}
instructionlist.)

It is possible for an @code{ERRACT} instructionlist to produce an
inappropriate value or no value where one is needed.  As a result, the same
error condition could recur forever because of this mechanism.  To avoid that
danger, if the same error condition occurs twice in a row from an
@code{ERRACT} instructionlist without user interaction, the message
@samp{Erract loop} is printed and control returns to toplevel.  "Without user
interaction" means that if @code{ERRACT} invokes @code{PAUSE} and the user
provides an incorrect value, this loop prevention mechanism does not take
effect and the user gets to try again.

During the running of the @code{ERRACT} instructionlist, @code{ERRACT} is
locally unbound, so an error in the @code{ERRACT} instructions themselves will
not cause a loop.  In particular, an error during a pause will not cause a
pause-within-a-pause unless the user reassigns the value @code{[PAUSE]} to
@code{ERRACT} during the pause.  But such an error will not return to
toplevel; it will remain within the original pause loop.

If there is no available @code{ERRACT} value, Logo handles the error by
generating an internal @w{@t{THROW "ERROR}}.  (A user program can also
generate an error condition deliberately by invoking @code{THROW}.)  If this
throw is not caught by a @w{@t{CATCH "ERROR}} in the user program, it is
eventually caught either by the toplevel instruction loop or by a pause loop,
which prints the error message. An invocation of @w{@t{CATCH "ERROR}} in a
user program locally unbinds @code{ERRACT}, so the effect is that whichever of
@code{ERRACT} and @w{@t{CATCH "ERROR}} is more local will take precedence.

If a floating point overflow occurs during an arithmetic operation, or a
two-input mathematical function (like @code{POWER}) is invoked with an illegal
combination of inputs, the @samp{doesn't like} message refers to the second
operand, but should be taken as meaning the combination.

@xref{ERRACT} ,
@ref{THROW} ,
@ref{ERROR} ,
@ref{CATCH} ,
@ref{PAUSE} ,
@ref{CONTINUE} .

@node ERROR CODES,  , ERROR PROCESSING, ERROR PROCESSING
@section Error Codes
@cindex errors

Here are the numeric codes that appear as the first member of the list
output by @code{ERROR} when an error is caught, with the corresponding messages.
Some messages may have two different codes depending on whether or not
the error is recoverable (that is, a substitute value can be provided
through the @code{ERRACT} mechanism) in the specific context.  Some messages are
warnings rather than errors; these will not be caught.  Errors 0 and 32 are
so bad that Logo exits immediately.

@example
  0	Fatal internal error@ @ @r{(can't be caught)}
  1	Out of memory
  2	Stack overflow
  3	Turtle out of bounds
  4	@var{proc} doesn't like @var{datum} as input@ @ @r{(not recoverable)}
  5	@var{proc} didn't output to @var{proc}
  6	Not enough inputs to @var{proc}
  7	@code{proc} doesn't like @code{datum} as input@ @ @r{(recoverable)}
  8	Too much inside ()'s
  9 	You don't say what to do with @var{datum}
 10	')' not found
 11	@var{var} has no value
 12	Unexpected ')'
 13	I don't know how to @var{proc}@ @ @r{(recoverable)}
 14	Can't find catch tag for @var{throwtag}
 15	@var{proc} is already defined
 16	Stopped
 17	Already dribbling
 18	File system error
 19	Assuming you mean IFELSE, not IF@ @ @r{(warning only)}
 20	@var{var} shadowed by local in procedure call@ @ @r{(warning only)}
 21	Throw "Error
 22	@var{proc} is a primitive
 23	Can't use TO inside a procedure
 24	I don't know how to @var{proc}@ @ @r{(not recoverable)}
 25	IFTRUE/IFFALSE without TEST
 26	Unexpected ']'
 27	Unexpected '@}'
 28	Couldn't initialize graphics
 29	Macro returned @var{value} instead of a list
 30	You don't say what to do with @var{value}
 31	Can only use STOP or OUTPUT inside a procedure
 32	APPLY doesn't like @var{badthing} as input
 33	END inside multi-line instruction
 34	Really out of memory@ @ @r{(can't be caught)}
 35	user-generated error message (THROW "ERROR @var{message})
 36	END inside multi-line instruction
 37	Bad default expression for optional input: @var{expr}
 38	Can't use OUTPUT or STOP inside RUNRESULT
 39 	Assuming you meant 'FD 100', not FD100@ @ @r{(or similar)}
 40	I can't open file @var{filename}
 41	File @var{filename} already open
 42	File @var{filename} not open
 43	Runlist [@var{expr} @var{expr}] has more than one expression.
@end example


@node   SPECIAL VARIABLES, INTERNATIONALIZATION, ERROR PROCESSING, Top
@chapter Special Variables

Logo takes special action if any of the following variable names exists.
They follow the normal scoping rules, so a procedure can locally set one
of them to limit the scope of its effect.  Initially, no variables exist
except for @code{ALLOWGETSET}, @code{CASEIGNOREDP}, and
@code{UNBURYONEDIT}, which are @code{TRUE} and buried.

@menu
* ALLOWGETSET::                 
* BUTTONACT::
* CASEIGNOREDP::                
* COMMANDLINE::
* ERRACT::                      
* FULLPRINTP::                  
* KEYACT::
* LOADNOISILY::                 
* PRINTDEPTHLIMIT::             
* PRINTWIDTHLIMIT::             
* REDEFP::                      
* STARTUP::                     
* UNBURYONEDIT::                
* USEALTERNATENAMES::           
* LOGOVERSION::
* LOGOPLATFORM::
@end menu

@node ALLOWGETSET, BUTTONACT, SPECIAL VARIABLES, SPECIAL VARIABLES
@comment  node-name,  next,  previous,  up
@unnumberedsec allowgetset
@cindex allowgetset

@example
ALLOWGETSET                           (variable)
@end example

if @code{TRUE}, indicates that an attempt to use a procedure that doesn't exist
should be taken as an implicit getter or setter procedure (setter if the
first three letters of the name are @code{SET}) for a variable of the same name
(without the @code{SET} if appropriate).

@node BUTTONACT, CASEIGNOREDP, ALLOWGETSET, SPECIAL VARIABLES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec buttonact
@cindex buttonact

@example
BUTTONACT                           (variable)
@end example

if nonempty, should be an instruction list that will be evaluated
whenever a mouse button is pressed.  Note that the user may have
released the button before the instructions are evaluated.  @code{BUTTON}
will still output which button was most recently pressed.  @code{CLICKPOS}
will output the position of the mouse cursor at the moment the
button was pressed; this may be different from @code{MOUSEPOS} if the
user moves the mouse after clicking.

Note that it's possible for the user to press a button during the
evaluation of the instruction list.  If this would confuse your
program, prevent it by temporarily setting @code{BUTTONACT} to the empty
list.  One easy way to do that is the following:

@example
make "buttonact [button.action]

to button.action [:buttonact []]
... ; whatever you want the button to do
end
@end example

@node CASEIGNOREDP, COMMANDLINE, BUTTONACT, SPECIAL VARIABLES
@unnumberedsubsec caseignoredp
@cindex caseignoredp

@example
CASEIGNOREDP                                (variable)
@end example

if @code{TRUE}, indicates that lower case and upper case letters should be
considered equal by @code{EQUALP}, @code{BEFOREP}, @code{MEMBERP}, etc.  Logo
initially makes this variable @code{TRUE}, and buries it.

@xref{EQUALP} ,
@ref{BEFOREP} ,
@ref{MEMBERP} .

@node COMMANDLINE, ERRACT, CASEIGNOREDP, SPECIAL VARIABLES
@unnumberedsubsec commandline
@cindex commandline

@example
COMMANDLINE                                (variable)
@end example

contains any text appearing after a hyphen on the command line used
to start Logo.

@node ERRACT, FULLPRINTP, COMMANDLINE, SPECIAL VARIABLES
@unnumberedsubsec erract
@cindex erract

@example
ERRACT                                      (variable)
@end example

an instructionlist that will be run in the event of an error.  Typically
has the value @code{[PAUSE]} to allow interactive debugging.

@xref{PAUSE} .

@node FULLPRINTP, KEYACT, ERRACT, SPECIAL VARIABLES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec fullprintp
@cindex fullprintp

@example
FULLPRINTP                               (variable)
@end example

if @code{TRUE}, then words that were created using backslash or vertical bar
(to include characters that would otherwise not be treated as part of a
word) are printed with the backslashes or vertical bars shown, so that
the printed result could be re-read by Logo to produce the same value.
If FULLPRINTP is @code{TRUE} then the empty word (however it was created)
prints as @code{||}.  (Otherwise it prints as nothing at all.)

@node KEYACT, LOADNOISILY, FULLPRINTP, SPECIAL VARIABLES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec keyact
@cindex keyact

@example
KEYACT                               (variable)
@end example

if nonempty, should be an instruction list that will be evaluated
whenever a key is pressed on the keyboard.  The instruction list
can use @code{READCHAR} to find out what key was pressed.  Note that only
keys that produce characters qualify; pressing @code{SHIFT} or @code{CONTROL}
alone will not cause @code{KEYACT} to be evaluated.

Note that it's possible for the user to press a key during the
evaluation of the instruction list.  If this would confuse your
program, prevent it by temporarily setting @code{KEYACT} to the empty
list.  One easy way to do that is the following:

@example
make "keyact [key.action]

to key.action [:keyact []]
... ; whatever you want the key to do
end
@end example

@node LOADNOISILY, PRINTDEPTHLIMIT, KEYACT, SPECIAL VARIABLES
@unnumberedsubsec loadnoisily
@cindex loadnoisily

@example
LOADNOISILY                                 (variable)
@end example

if @code{TRUE}, prints the names of procedures defined when loading from a file
(including the temporary file made by @code{EDIT}).

@xref{EDIT} .

@node PRINTDEPTHLIMIT, PRINTWIDTHLIMIT, LOADNOISILY, SPECIAL VARIABLES
@unnumberedsubsec printdepthlimit
@cindex printdepthlimit

@example
PRINTDEPTHLIMIT                             (variable)
@end example

if a nonnegative integer, indicates the maximum depth of sublist
structure that will be printed by @code{PRINT}, etc.

@xref{PRINT} .

@node PRINTWIDTHLIMIT, REDEFP, PRINTDEPTHLIMIT, SPECIAL VARIABLES
@unnumberedsubsec printwidthlimit
@cindex printwidthlimit

@example
PRINTWIDTHLIMIT                             (variable)
@end example

if a nonnegative integer, indicates the maximum number of members in any
one list that will be printed by @code{PRINT}, etc.

@xref{PRINT} .

@node REDEFP, STARTUP, PRINTWIDTHLIMIT, SPECIAL VARIABLES
@unnumberedsubsec redefp
@cindex redefp

@example
REDEFP                                      (variable)
@end example

if @code{TRUE}, allows primitives to be erased (@code{ERASE}) or redefined
(@code{COPYDEF}).

@xref{ERASE} ,
@ref{COPYDEF} .

@node STARTUP, UNBURYONEDIT, REDEFP, SPECIAL VARIABLES
@unnumberedsubsec startup
@cindex startup

@example
STARTUP                                     (variable)
@end example

if assigned a list value in a file loaded by @code{LOAD}, that value is run as
an instructionlist after the loading.

@xref{LOAD} .

@node UNBURYONEDIT, USEALTERNATENAMES, STARTUP, SPECIAL VARIABLES
@comment  node-name,  next,  previous,  up
@unnumberedsubsec unburyonedit
@cindex unburyonedit

@example
UNBURYONEDIT                            (variable)
@end example

if @code{TRUE}, causes any procedure defined during @code{EDIT} or @code{LOAD}
to be unburied, so that it will be saved by a later @code{SAVE}.  Files that
want to define and bury procedures must do it in that order.

@xref{EDIT} ,
@xref{LOAD} ,
@xref{SAVE} .

@node USEALTERNATENAMES, LOGOVERSION, UNBURYONEDIT, SPECIAL VARIABLES
@unnumberedsubsec usealternatenames
@cindex usealternatenames

@example
USEALTERNATENAMES					(variable)
@end example

if @code{TRUE}, causes Logo to generate non-English words (from the
@file{Messages} file) instead of @code{TRUE}, @code{FALSE}, @code{END}, etc.



Logo provides the following buried variables that can be used by programs:

@node LOGOVERSION, LOGOPLATFORM, USEALTERNATENAMES, SPECIAL VARIABLES
@unnumberedsubsec logoversion
@cindex logoversion

@example
LOGOVERSION                                   (variable)
@end example

a real number indicating the Logo version number, e.g., 5.5

@node LOGOPLATFORM,  , LOGOVERSION, SPECIAL VARIABLES
@unnumberedsubsec logoplatform
@cindex logoplatform

@example
LOGOPLATFORM                                   (variable)
@end example

one of the following words: @code{wxWidgets}, @code{X11}, @code{Windows},
or @code{Unix-nographics}.



@node INTERNATIONALIZATION, INDEX, SPECIAL VARIABLES, Top
@chapter Internationalization

Berkeley Logo has limited support for non-English-speaking users.
Alas, there is no Unicode support, and high-bit-on ASCII codes work in
some contexts but not others.

If you want to translate Berkeley Logo for use with another language,
there are three main things you have to do:

@example
1. Primitive names
2. Error (and other) messages
3. Documentation
@end example

For primitive names, the easiest thing is to provide a startup file that
defines aliases for the English primitive names, using @code{COPYDEF}:

@example
COPYDEF "AVANT "FORWARD
@end example

This should take care of it, unless your language's name for one primitive
is spelled like the English name of a different primitive.  In that case
you have to turn @code{REDEFP} on and be sure to copy the non-conflicting name
before overwriting the conflicting one!

"Primitives" that are actually in the Logo library, of course, can just
be replaced or augmented with native-language-named Logo procedures and
filenames.

Of course Logo programs will still not look like your native language if
the word order is dramatically different, especially if you don't put
verbs before their objects.

For error messages, there is a file named @file{Messages} in the
@file{logolib} directory with texts of messages, one per line.  You can
replace this with a file for your own language.  Do not add, delete, or
reorder lines; Logo finds messages by line number.  The sequences @code{%p},
@code{%s}, and @code{%t} in these messages represent variable parts of the
message and should not be translated.  (%p @code{PRINT}s the variable part,
while %s @code{SHOW}s it -- that is, the difference is about whether or not
brackets are shown surrounding a list.  %t means that the variable part is a C
text string rather than a Logo object.)  If you want to change the order of
two variable parts (no reorderable message has more than two), you would for
example replace the line

@example
%p doesn't like %s as input
@end example

with

@example
%+s is a lousy input to %p
@end example

The plus sign tells the message printer to reverse the order; you must
reverse the order of %p and %s, if both are used, to match.  The plus
sign goes just after the first percent sign in the message, which might
not be at the beginning of the line.  The sequence @code{\n} in a message
represents a newline; don't be fooled into thinking that the @code{n} is part
of the following word.

Some messages appear twice in the file; this isn't a mistake.  The two spaces
before @code{to} in @code{I don't know how\ \ to} aren't a mistake either.
The message containing just @code{%p} is for user-provided error messages in
@w{@code{THROW "ERROR}}.  The message "@code{\ \ in %s\n%s}" is the part of all
error messages that indicates where the error occurred if it was inside a
procedure; you might want to change the word @code{in} to your language.  
@w{@code{%s defined\n}} is what @code{LOAD} prints for each procedure defined
if the variable @code{LOADNOISILY} is @code{TRUE}.
@w{"@code{to %p\nend\n\n}"} is what @code{EDIT} puts in the temporary file if
you ask to edit a procedure that isn't already defined.

Also in the @file{Messages} file are lines containing only one word each; the
first of these is the word @code{true}.  Some of these words are recognized by
Logo in user input; some are generated by Logo; some are both.  For example,
the words @code{TRUE} and @code{FALSE} are recognized as Boolean values by
@code{IF} and @code{IFELSE}, and are also generated by Logo as outputs from
the primitive predicates such as @code{EQUALP}.  The word @code{END} is
recognized as the end of a procedure definition, and may be generated when
Logo reconstructs a procedure body for @code{PO} or @code{EDIT}.  I've used
capital letters in this paragraph for easier reading, but the words in the
@file{Messages} file should be in lower case.

If you replace these with non-English words, Logo will @emph{recognize} both the
English names and your alternate names.  For example, if you replace the
word @code{true} with @code{vrai} then Logo will understand both of these:

@example
IF "TRUE [PRINT "YES]
IF "VRAI [PRINT "YES]
@end example

The variable @code{UseAlternateNames} determines whether Logo will
@emph{generate} other-language names -- for example, whether predicate
functions return the other-language alternates for @code{TRUE} and
@code{FALSE}.  This variable is @code{FALSE} by default, meaning that the
English words will be generated.

You might wish to have English-named predicate functions generate English
@code{TRUE} and @code{FALSE}, while other-language-named predicates generate
the alternate words.  This can be done by leaving @code{UseAlternateNames}
false, and instead of defining the other-language predicates with
@code{COPYDEF}, do it this way:

@example
to french.boolean :bool
if equalp :bool "true [output "vrai]
if equalp :bool "false [output "faux]
output :bool	; shouldn't happen
end

to make.french.predicate :french :english :arity
define :french `[[[inputs] ,[:arity]]
                 [output french.boolean
			    apply ,[word "" :english] :inputs]]
end

? make.french.predicate "egal? "equal? 2
? pr egal? 3 4
faux
? pr egal? 4 4
vrai
? pr equal? 3 4
false
? pr equal? 4 4
true
@end example

The third input to @code{make.french.predicate} is the number of inputs that
the predicate expects.  This solution isn't quite perfect because the infix
predicates (@code{=}, @code{<}, @code{>}) will still output in English.  If
you want them to generate alternate-language words, set
@code{UseAlternateNames} to @code{TRUE} instead.

Some of the words in this section of the @file{Messages} file are names of
Logo primitives (@code{OUTPUT}, @code{STOP}, @code{GOTO}, @code{TAG},
@code{IF}, @code{IFELSE}, @code{TO}, @code{.MACRO}).  To translate these
names, you must use @code{COPYDEF} as described earlier, in addition to
changing the names in @file{Messages}.  You should be consistent in these two
steps.  Don't forget the period in @code{.macro}!

For documentation, there are two kinds: this manual and the help files.
The latter are generated automatically from this manual if you have a
Unix system, so in that case you need only translate this manual,
maintaining the format.  (The automatic helpfile generator notices
things like capital letters, tabs, hyphens, and equal signs at the
beginnings of lines.)  The program @code{makefile.c} may require modification
because a few of the primitive names are special cases (e.g., @code{LOG10} is
the only name with digits included).

If you don't have Unix tools, you can just translate each helpfile
individually.  A period in a primitive name is represented as a @code{D} in
the filename; there are no files for question marks because the @code{HELP}
command looks for the file named after the corresponding primitive
that ends in @code{P}.


@node   INDEX,  , INTERNATIONALIZATION, Top
@unnumbered INDEX

@printindex cp

@bye
