home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / win3 / util / mswlog12 / logoman.mem < prev   
Text File  |  1992-07-30  |  76KB  |  1,586 lines

  1. ***** THIS MANUAL IS NOT UPDATED TO REFLECT THE PORT TO WINDOWS *****
  2.  
  3.  
  4.                                LSRHS Logo Manual
  5.  
  6.  
  7.        Introduction.  Logo is  a  computer  programming  language  which  was
  8.   designed  to be both simple to use and extremely powerful.  It was designed
  9.   by a group of computer scientists at MIT and at Bolt, Beranek, and  Newman.
  10.   Its  structure  is based largely on the LISP language, which is widely used
  11.   in Artificial Intelligence research, but the notation has been  changed  to
  12.   make  Logo  far  easier  for a beginner than LISP.  This manual describes a
  13.   version of Logo for the PDP-11, originally  written  in  C  at  the  Boston
  14.   Children's  Museum and extensively modified at the Lincoln-Sudbury Regional
  15.   High School.
  16.  
  17.        The power of Logo comes primarily from the idea of the  procedure.   A
  18.   procedure  is  simply  something  the computer "knows" how to do; some pro-
  19.   cedures are built into Logo itself (these are called primitive procedures),
  20.   while  others  are  defined by the programmer in terms of these simple pro-
  21.   cedures.  Defined procedures can be used as part of the definition of other
  22.   procedures,  so that a complicated program can be built in "layers" of com-
  23.   plexity.  This layered structure is analogous to the description of a  com-
  24.   plex  machine  in  terms  of  building  blocks:  an automobile is made of a
  25.   chassis, a drive train, an electrical system, and so on.  The  drive  train
  26.   contains  an  engine,  a  transmission,  a clutch, an axle, and so on.  The
  27.   transmission contains a housing, gears, and levers.  A  lever  may  include
  28.   connecting  joints  at  the  ends  and  at  a  pivot point.  Eventually the
  29.   description of the automobile reaches the level of bolts and washers; these
  30.   correspond to the primitive procedures in Logo.
  31.  
  32.        Starting_Logo.  Use the shell command logo to start  the  Logo  inter-
  33.   preter.   When  Logo is running it will print an asterisk (*) at the begin-
  34.   ning of a line to indicate that it is ready for you to type in a  Logo  in-
  35.   struction.   The instruction may print something on the terminal, or draw a
  36.   line on a graphics display screen, or move a turtle around the floor.  Then
  37.   another  asterisk  is typed and you may give another instruction.  (If Logo
  38.   prints a "greater than" sign (>) instead of an asterisk, it is in procedure
  39.   definition  mode,  which  will  be  described later.  Type your system quit
  40.   character (control-G at Lincoln-Sudbury) to return to normal mode.)
  41.  
  42.        If an argument is used with the shell command logo,  the  argument  is
  43.   taken  as  the  name  of a procedure, which Logo runs before doing anything
  44.   else.  You can therefore create a shell script which will start Logo, run a
  45.   procedure  automatically,  and (if you say "goodbye" at the end of the pro-
  46.   cedure) exit.
  47.  
  48.        Syntax.  Unlike most computer languages, Logo has an  almost  entirely
  49.   uniform  syntax.   That  is, all of the different commands Logo understands
  50.   are represented using the same notation: the name of a  procedure  is  fol-
  51.   lowed  by  its inputs, which may be constants (like numbers) or else may be
  52.   the results of using other procedures.  Here is a simple example:
  53.  
  54.        print "hello
  55.  
  56.   In this Logo instruction, the primitive procedure print is used with a con-
  57.   stant  input,  the  word hello.  The quotation mark indicates that hello is
  58.   being used to represent the word itself;  without  the  quotation  mark  it
  59.   would  have  been  interpreted as the name of a procedure, just as print is
  60.   the name of a procedure.  In Logo, the print procedure always requires  ex-
  61.   actly  one input, which is the thing to print.  The input can be a word, as
  62.  
  63.                                        1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.   in this example, or a list, which will be explained later.  (A number is  a
  71.   special  case of a word, and a sentence is a special case of a list.)  Here
  72.   is another example:
  73.  
  74.        print first "hello
  75.  
  76.   In this instruction, the primitive procedure first is used.  This procedure
  77.   takes one input, a word, and has an output which is the first letter of the
  78.   word.  The output from first is used as the input  to  print,  so  what  is
  79.   printed  is the letter h rather than the word hello as in the earlier exam-
  80.   ple.
  81.  
  82.        Don't confuse the output from a procedure with what is printed by  the
  83.   print  command.  In Logo, the word "output" is not used to refer to what is
  84.   printed by a program, just as the word "input" does not mean something  you
  85.   type  into  the  program.   Instead, these words refer to objects (words or
  86.   lists) which are given to a procedure (inputs) or produced by  a  procedure
  87.   (outputs).   A  particular  procedure has a fixed number of inputs and out-
  88.   puts.  The number of inputs may be anything, including  zero,  whereas  the
  89.   number  of outputs is either zero or one.  A procedure with an output (like
  90.   first) is called an operation; one without an output (like print) is called
  91.   a command.
  92.  
  93.        Some operations only have two possible outputs: the word true and  the
  94.   word  false.   Such a procedure is called a predicate.  Predicates are used
  95.   to allow a program to carry out some instruction only if a particular  con-
  96.   dition  is met.  By convention, predicates generally have names ending with
  97.   the letter "p".
  98.  
  99.        Multiple_inputs_to_operations.  Several Logo primitive procedures  are
  100.   operations with two inputs.  The arithmetic operations, like sum, are exam-
  101.   ples of this.  A special extension to Logo syntax allows such an  operation
  102.   to  have  more than two inputs by enclosing the operation and its inputs in
  103.   parentheses or braces:
  104.  
  105.        (sum 2 5 13 8.5)
  106.  
  107.   Association is right to left.  At least two inputs must  be  given,  except
  108.   for the list operation, which can take one input if parenthesized.
  109.  
  110.        Multi-instruction_lines.  It is possible to put more than one instruc-
  111.   tion  on  the  same  line  when you are typing to Logo.  To do this, type a
  112.   semicolon (;) between the instructions:
  113.  
  114.        print "hello; print "goodbye
  115.  
  116.   Later in this manual, the phrase "instruction line" will mean one  or  more
  117.   instructions on a line.
  118.  
  119.        Multi-line_instructions.  It is possible to continue an instruction on
  120.   a  second  line.   To do this, end the first line with a backslash (\), im-
  121.   mediately followed by the RETURN key.  If you are typing a quoted word, you
  122.   must  end  the word (with a space, for example) before using the backslash-
  123.   RETURN combination.  Inside a quoted word, backslash-RETURN means to put an
  124.   actual RETURN as part of the word.
  125.  
  126.        Comments.  It is possible to include in an instruction  line  comments
  127.   which are meant for human readers of your program (including yourself, next
  128.  
  129.                                        2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.   week), and which are not Logo instructions.  To do this, begin the  comment
  137.   with  an  exclamation point (!).  Everything after the exclamation point on
  138.   the line will be ignored by Logo.  For example:
  139.  
  140.        print [Hi, there.] ! A friendly greeting.
  141.  
  142.   However, the exclamation point does not begin a comment if it is part of  a
  143.   word  or  list (see below).  You should type a space before the exclamation
  144.   point, as in the example above, to make sure it will be interpreted as  the
  145.   beginning of a comment.
  146.  
  147.        Words.  Every computer language deals with  particular  kinds  of  ob-
  148.   jects.   Most languages, like FORTRAN or BASIC or Pascal, are best at deal-
  149.   ing with numbers.  Logo is a list processing language, which is at its best
  150.   with  more  complicated data structures.  The two main categories of object
  151.   are the word and the list.
  152.  
  153.        A word is a string of characters.  (A character is  a  letter,  digit,
  154.   space,  or  punctuation  mark.   Things like TAB and RETURN on the terminal
  155.   keyboard are also characters, although they are not usually used as part of
  156.   Logo  words.)   A word can be any length, including zero.  The way to indi-
  157.   cate a word as part of a Logo program is to use the quotation mark (")  be-
  158.   fore the word.  The word begins with the character after the quotation mark
  159.   and continues until a space, a tab, the end of the line, or  one  of  these
  160.   characters:
  161.  
  162.        ( ) [ ] { } " ;
  163.  
  164.   A quotation mark immediately followed by a space or one of the other  word-
  165.   terminating  characters indicates the empty word, which is a word of length
  166.   zero.
  167.  
  168.        Please notice that, unlike most programming languages, Logo  does  not
  169.   use quotation marks in pairs to delimit strings of characters.  The follow-
  170.   ing instruction is an error:
  171.  
  172.        print "aardvark"
  173.  
  174.   This is an error because the print command is followed by  two  words,  the
  175.   word  aardvark and an empty word which is indicated by the second quotation
  176.   mark.  Since print only uses one input, the second word has no purpose, and
  177.   Logo gives the error message
  178.  
  179.        There's something extra on the line.
  180.        print takes only one input.
  181.  
  182.        In order to include one of the word-terminating characters in a  word,
  183.   you  must  precede  it with a backslash (\).  Do not confuse backslash with
  184.   the regular slash (/) character.  For example, this instruction:
  185.  
  186.        print "\(boo\)
  187.  
  188.   will print the five characters (boo) as its result.   The  space  character
  189.   may  be  included  in  a  word by using a percent (%) instead of the space.
  190.   Therefore, the following are equivalent:
  191.  
  192.        print "Hello%there.
  193.        print "Hello\ there.
  194.  
  195.                                        3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.   To include a percent character or a backslash character in a word, you must
  204.   precede it with a backslash.
  205.  
  206.        Numbers.  A number is a special case of a word, in which  the  charac-
  207.   ters  are  all  digits.  (That definition isn't quite complete, and will be
  208.   expanded in the next paragraph.)  A number need not be preceded with a quo-
  209.   tation mark.  (This rule is possible because normally Logo interprets words
  210.   without quotation marks as the names of procedures, but there are  no  pro-
  211.   cedures  whose  names begin with digits.)  If a quotation mark is not used,
  212.   then any nondigit terminates the word.
  213.  
  214.        Actually, numbers may be written in  scientific  notation.   That  is,
  215.   they  can  include  signs,  decimal  points, and a power of 10 by which the
  216.   number is multiplied.  This exponent is indicated by the letter e  followed
  217.   by the integer power of 10.  The following numbers have the same value:
  218.  
  219.        1000
  220.        "1000
  221.        1000.00
  222.        1e3
  223.        10.0e+2
  224.        "+1.0e3
  225.        10000e-1
  226.  
  227.   Notice that if the number begins with a sign it must be quoted.   A  quoted
  228.   number still must begin with a digit or a sign, not with a decimal point or
  229.   a letter e.  (The letter may be a capital E, by the way.)  If a  number  is
  230.   quoted,  it must end with one of the normal word-terminating characters.  A
  231.   number which contains only digits (no decimal point or exponent) is  called
  232.   an  integer.   Note that a number with a decimal point is not considered an
  233.   integer even if the digits after the decimal point are all zero.
  234.  
  235.        Since a number is a word, the usual character-manipulating  procedures
  236.   may be applied to it.  For example,
  237.  
  238.        print first 1024
  239.  
  240.   prints the digit 1 which is the first character of the  number.   In  addi-
  241.   tion, there are arithmetic procedures which apply specifically to numbers:
  242.  
  243.        print sum 3 2
  244.  
  245.   prints the number 5.  These procedures will be listed later.
  246.  
  247.        Lists.  A word can be thought of as a list of characters; for example,
  248.   the  word hello is a list of five letters.  In Logo it is possible to mani-
  249.   pulate not only lists of characters but also lists of words, lists of lists
  250.   of  words, and so on.  This is a very powerful capability which allows very
  251.   complicated data structures to be manipulated easily.  To indicate  a  list
  252.   in  a  program,  you  put  square  brackets  ([ and ]) around the list, and
  253.   separate the list elements with spaces.  For example:
  254.  
  255.        print [This is a list of seven words.]
  256.  
  257.   A list all of whose elements are words is called a sentence.   Here  is  an
  258.   example of a list which is not a sentence:
  259.  
  260.  
  261.                                        4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.        print [[This is a list][of two sentences.]]
  269.  
  270.        Within a bracketed list,  square  brackets  delimit  sub-lists  (lists
  271.   which are elements of the main list).  The quotation mark, parentheses, and
  272.   braces are not considered special within a bracketed list, unlike the rules
  273.   for  quoted  words.  A list may extend over more than one line; that is, if
  274.   you have typed an open square bracket ([) and have not yet typed the match-
  275.   ing  close  square bracket, the Logo instruction is not ended by typing the
  276.   RETURN key.
  277.  
  278.        Variables.  A variable is an entity which has a name, which is a word,
  279.   and a thing (also called a value), which can be any Logo object.  Variables
  280.   are used to "remember" a computed object for repeated or delayed use  in  a
  281.   program.   In Logo, the most common way that a variable acquires a value is
  282.   that it is associated with an input to a user-written  procedure.   In  the
  283.   following  example, don't worry about the details of the format of the pro-
  284.   cedure, which will be explained later:
  285.  
  286.        to pff :sentence
  287.        print first first :sentence
  288.        end
  289.  
  290.   This is the definition of a command with one input.  The name of  the  com-
  291.   mand  is pff.  It has one input because in the "title line" (the one start-
  292.   ing to pff) there is one variable name after the command name.   The  vari-
  293.   able whose name is sentence is associated with the first (and only, in this
  294.   case) input to pff.  In the line starting with the word print, the notation
  295.   :sentence  means  "the  thing of the variable whose name is sentence".  (To
  296.   refer to the name itself, quote it as you would any word.)   If  this  pro-
  297.   cedure is used in a Logo instruction like this:
  298.  
  299.        pff [This is the poop.]
  300.  
  301.   then the variable sentence has the value [This is the poop.].
  302.  
  303.        It is also possible to assign a value to a  variable  by  an  explicit
  304.   Logo instruction.  There is a primitive procedure to do this:
  305.  
  306.   make - Command, two inputs.
  307.        The first input is the name of a variable  (that  is,  it  must  be  a
  308.        word); the second is any Logo object.  The effect of the command is to
  309.        assign the second input as the value of  the  variable  named  by  the
  310.        first input.
  311.  
  312.   If you are accustomed to programming  in  a  non-procedural  language  like
  313.   BASIC,  you should strenuously avoid the temptation to overuse make; expli-
  314.   cit assignment is almost always the wrong  thing  to  do  in  Logo.   Total
  315.   abstention is the best policy for a Logo beginner.
  316.  
  317.        In Logo, variables are dynamically scoped.  That means that a variable
  318.   can "belong to" a particular procedure; such a variable can be used by that
  319.   procedure and by any procedure which is used by an instruction  within  the
  320.   procedure,  but  is not available to the procedure which invoked the owning
  321.   procedure.  In other words, such a local variable comes into being when the
  322.   owning procedure starts running, and disappears when that procedure is fin-
  323.   ished.  It is possible for a procedure with a local variable to use another
  324.   procedure  with a local variable of the same name.  In that case, the vari-
  325.   able belonging to the "inner" procedure is the one which is associated with
  326.  
  327.                                        5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.   the  name  as  long as it exists; when the inner procedure is finished, the
  335.   "hidden" variable belonging to the outer procedure is again available.
  336.  
  337.        A variable which is associated with the input to a  procedure  is  au-
  338.   tomatically  local to that procedure.  Other variables are normally global:
  339.   they are "permanent" and do not disappear when the procedure in which  they
  340.   get  their  values  finish.  It is both possible and desirable to make such
  341.   variables local, by an explicit instruction to that effect:
  342.  
  343.   local - Command, one input.
  344.        The input must be a word.  A variable with that word as  its  name  is
  345.        created,  local  to the currently running procedure (that is, local to
  346.        the procedure in which the local command is used).
  347.  
  348.   The virtue of local variables is that they make procedures more independent
  349.   of  one another than they would be if global variables were used.  In other
  350.   words, if you use local variables consistently, then nothing  that  happens
  351.   in  one  procedure will change the values of variables used in another pro-
  352.   cedure.  This makes it very much easier to find program errors.
  353.  
  354.        Primitive_procedures_to_define_user_procedures.  There are two ways to
  355.   define  your own procedure.  The first way, using the to command, is simple
  356.   to learn but limited in flexibility.  The second way, using the  edit  com-
  357.   mand,  is  more  complicated to learn, but makes it easy to make changes in
  358.   your procedures.  The edit command uses the text editing program edt,  just
  359.   as  you  might use it outside of Logo to edit a document you want to print.
  360.   Once you've learned the special editing commands in edt, it's easy to  use.
  361.   The  to command makes it possible to begin programming in Logo without hav-
  362.   ing learned how to use edt.  It just lets you type in your procedure defin-
  363.   ition,  without any provision for correcting errors or changing the defini-
  364.   tion of the procedure.  It is fast and convenient for short procedures, but
  365.   limited.
  366.  
  367.   The to command is unique, in Logo, in that its inputs are interpreted in  a
  368.   special  way.  The inputs aren't evaluated: Logo doesn't run any procedures
  369.   you name, or look up the values of any variables, before carrying  out  the
  370.   to command.  The example below should make this clearer.
  371.  
  372.   to - Command, special form, see below.
  373.        This command takes a variable number of inputs.  The first is the name
  374.        of  a  procedure to be defined.  The rest, if any, must be preceded by
  375.        colons, and are the names of variables to be used  as  inputs  to  the
  376.        procedure.   Logo  responds  to  the to command by printing a "greater
  377.        than" sign (>) prompt, to show you that you are defining  a  procedure
  378.        rather  than  entering  commands to be executed immediately.  You type
  379.        the instruction lines which make up the definition.  When you are done
  380.        with  the  definition,  type the special word end on a line by itself.
  381.        For example:
  382.  
  383.        *to twoprint :thing
  384.        >print :thing
  385.        >print :thing
  386.        >end
  387.        *
  388.  
  389.        This example shows the definition of a procedure named twoprint, which
  390.        has  one  input, named thing.  The procedure you are defining with the
  391.        to command must not already be defined.
  392.  
  393.                                        6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.   edit - Command, zero or one input.  Abbreviation: ed
  401.        The input to this command must be a word, which is the name of a  pro-
  402.        cedure,  or a list of words, each of which is the name of a procedure.
  403.        (Unlike the to command, but like all other Logo procedures,  the  edit
  404.        command  evaluates  its input, so you must use a quotation mark before
  405.        the procedure name, if only one is given, to indicate that it  is  the
  406.        name  itself which is the input to edit; otherwise Logo would actually
  407.        run the procedure to calculate the input to edit.)  The procedure  you
  408.        name  may  or  may  not already be defined.  Logo responds to the edit
  409.        command by running the text editor edt, editing the definition of  the
  410.        procedure(s)  named  in its input.  (If a procedure was not previously
  411.        defined, Logo creates an initial definition for it which contains only
  412.        a  title  line and the end line.) You then edit the definition(s) with
  413.        edt.  When you write the file and leave edt, Logo will use the  edited
  414.        file  as the definition(s) of the procedure(s).  You must not put any-
  415.        thing in the file except procedure definitions; in other words,  every
  416.        nonempty  line  in  the  file must be between a "to" line and an "end"
  417.        line.
  418.  
  419.        If the edit command is given with no input, edt is given the same file
  420.        as  from  the last time you used the edit command.  This is a conveni-
  421.        ence for editing the same procedure(s) repeatedly.
  422.  
  423.        If, while editing, you change your mind and want to leave edt  without
  424.        redefining  anything, use the command ESC ^Z instead of the normal ^Z.
  425.        This special way of leaving edt tells Logo not to redefine  your  pro-
  426.        cedures.   You  have the choice, before exiting edt, of writing or not
  427.        writing the temporary file which contains  the  definitions.   If  you
  428.        don't  write the file, another edit command with no input will re-read
  429.        the previous contents of the temporary file; if you do,  another  edit
  430.        will re-read the new version.
  431.  
  432.        If your Unix environment contains a variable named  EDITOR,  the  con-
  433.        tents  of that variable is used as the name of the text editor program
  434.        instead of the standard edt.  The variable can contain  a  full  path-
  435.        name,  or  just  a program name if the program can be found in /bin or
  436.        /usr/bin.  Your favorite editor may not have a facility like edt's ESC
  437.        ^Z to abort redefinition.
  438.  
  439.   show - Command, one input.  Abbreviation: po
  440.        The input to this command is a word or a list  of  words.   Each  word
  441.        must  be  the  name  of  a  procedure.   The  command  prints  out the
  442.        definition(s) of the procedure(s) on your terminal.  (The abbreviation
  443.        po  stands  for  printout,  which is the name used for this command in
  444.        some other versions of Logo.)
  445.  
  446.   pots - Command, no inputs.
  447.        This command types at your terminal the title lines of all  procedures
  448.        you've defined.  The name is an abbreviation for "print out titles".
  449.  
  450.   erase - Command, one input.  Abbreviation: er
  451.        As for the show command, the input is either a word, naming  one  pro-
  452.        cedure,  or  a  list  of  words, naming more than one.  The named pro-
  453.        cedures are erased, so that they are no longer defined.
  454.  
  455.        Primitive_procedures_to_manipulate_words_and_lists.  There are  primi-
  456.   tive  procedures  to  print text objects on the terminal, to read them from
  457.   the terminal, to combine them into  larger  objects,  to  split  them  into
  458.  
  459.                                        7
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.   smaller objects, and to determine their size and nature:
  467.  
  468.   print - Command, one input.  Abbreviation: pr
  469.        The input, which may be a word or a list, is printed on the  terminal,
  470.        followed  by  a  new  line character.  (That is, the terminal is posi-
  471.        tioned at the beginning of a new line after printing the object.)   If
  472.        the  object is a list, any sub-lists are delimited by square brackets,
  473.        but the entire object is not delimited by brackets.
  474.  
  475.   type - Command, one input.
  476.        The input, which may be a word or a list, is printed on the  terminal,
  477.        without  a  new  line character.  (That is, the terminal remains posi-
  478.        tioned at the end of the object after printing it.)  Brackets are used
  479.        as with the print command.
  480.  
  481.   fprint - Command, one input.  Abbreviation: fp
  482.        The input is printed as by the print command, except that if it  is  a
  483.        list  (as  opposed  to a word) it is enclosed in square brackets.  The
  484.        name of the command is short for "full print".
  485.  
  486.   ftype - Command, one input.  Abbreviation: fty
  487.        The input is printed as by the type command, except that if  it  is  a
  488.        list, it is enclosed in square brackets.
  489.  
  490.   readlist - Operation, no inputs.  Abbreviation: rl
  491.        Logo waits for a line to be typed by the user.  The  contents  of  the
  492.        line  are  made into a list, as though typed within square brackets as
  493.        part of a Logo instruction.  (The user should not actually type brack-
  494.        ets  around the line, unless s/he desires a list of one element, which
  495.        is a list itself.)  That list is the output from the operation.
  496.  
  497.   request - Operation, no inputs.
  498.        A question mark is printed on the terminal as  a  prompt.   Then  Logo
  499.        waits for a line to be typed by the user, as for readlist.
  500.  
  501.   word - Operation, two inputs.
  502.        The two inputs must be words.  The output is a word which is the  con-
  503.        catenation  of  the two inputs.  There is no space or other separation
  504.        of the two inputs in the output.
  505.  
  506.   sentence - Operation, two inputs.  Abbreviation: se
  507.        The two inputs may be words or lists.  The output  is  a  list  formed
  508.        from  the two inputs in this way: if either input is a word, that word
  509.        becomes a member of the output list; if either input is  a  list,  the
  510.        members of that input become members of the output.  Here are some ex-
  511.        amples:
  512.  
  513.             first input         second input        output
  514.             "hello              "test               [hello test]
  515.             "goodbye            [cruel world]       [goodbye cruel world]
  516.             [a b]               [c d]               [a b c d]
  517.             []                  "garply             [garply]
  518.  
  519.        If an input is the empty list, as in the last example above,  it  con-
  520.        tributes nothing to the output.
  521.  
  522.   list - Operation, two inputs.
  523.        The output is a list of two elements, namely, the two inputs.  The in-
  524.  
  525.                                        8
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.        puts may be words or lists.
  533.  
  534.   fput - Operation, two inputs.
  535.        The first input may be any Logo object; the second  must  be  a  list.
  536.        The  output  is a list which is identical with the second input except
  537.        that it has an extra first member, namely, the first input.
  538.  
  539.   lput - Operation, two inputs.
  540.        The first input may be any Logo object; the second  must  be  a  list.
  541.        The  output  is a list which is identical with the second input except
  542.        that it has an extra last member, namely, the first input.
  543.  
  544.   first - Operation, one input.  Abbreviation: f
  545.        The input may be any non-empty Logo object.  If the input is  a  list,
  546.        the output is its first member.  If the input is a word, the output is
  547.        a single-letter word, namely the first letter of the  input.   If  the
  548.        input is empty (a word or list of length zero) an error results.
  549.  
  550.   last - Operation, one input.  Abbreviation: l
  551.        The input may be any non-empty Logo object.  If the input is  a  list,
  552.        the  output is its last member.  If the input is a word, the output is
  553.        a single-letter word, namely the last letter of the input.  If the in-
  554.        put is empty (a word or list of length zero) an error results.
  555.  
  556.   butfirst - Operation, one input.  Abbreviation: bf
  557.        The input may be any non-empty Logo object.  If the input is  a  list,
  558.        the output is a list equal to the input list with the first member re-
  559.        moved.  (If the input list has only one member, the output is the emp-
  560.        ty  list, a list of zero members.)  If the input is a word, the output
  561.        is a word equal to the input word with the first letter removed.   (If
  562.        the  input is a single-letter word, the output is the empty word.)  If
  563.        the input is empty, an error results.
  564.  
  565.   butlast - Operation, one input.  Abbreviation: bl
  566.        The input may be any non-empty Logo object.  If the input is  a  list,
  567.        the  output is a list equal to the input list with the last member re-
  568.        moved.  (If the input list has only one member, the output is the emp-
  569.        ty  list, a list of zero members.)  If the input is a word, the output
  570.        is a word equal to the input word with the last letter  removed.   (If
  571.        the  input is a single-letter word, the output is the empty word.)  If
  572.        the input is empty, an error results.
  573.  
  574.   count - Operation, one input.
  575.        The input may be any Logo object.  If the input is a list, the  output
  576.        is a number indicating the number of members in the list.  (Note: only
  577.        top-level members are counted, not members of members.  The  count  of
  578.        the list
  579.  
  580.             [[This is] [a list]]
  581.  
  582.        is 2, not 4.)  If the input is a word, the output  is  the  number  of
  583.        letters  (or  other  characters) in the word.  Remember that in Logo a
  584.        number is just a particular kind of word, so the output from count can
  585.        be manipulated like any other Logo word.
  586.  
  587.   emptyp - Operation (predicate), one input.
  588.        The input can be any Logo object.  The output is the word true if  the
  589.        input  is  of  length  zero  (i.e.,  it is the empty word or the empty
  590.  
  591.                                        9
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.        list).  The output is the word false otherwise.
  599.  
  600.   wordp - Operation (predicate), one input.
  601.        The input can be any Logo object.  The output is the word true if  the
  602.        input is a word.  The output is the word false if the input is a list.
  603.  
  604.   sentencep - Operation (predicate), one input.
  605.        The input can be any Logo object.  The output is the word true if  the
  606.        input  is  a  sentence, i.e., a list of words.  The output is the word
  607.        false if the input is a word, or if any member of the input is a list.
  608.  
  609.   is - Operation (predicate), two inputs.
  610.        The inputs can be any Logo objects.  The output is the  word  true  if
  611.        the  two inputs are identical.  That is, they must be of the same type
  612.        (both words or both lists), they must have the same count,  and  their
  613.        members  (if  lists) or their characters (if words) must be identical.
  614.        The output is the word false otherwise.  (Note: this is  an  exception
  615.        to the convention that names of predicates end with the letter "p".)
  616.  
  617.   memberp - Operation (predicate), two inputs.
  618.        If the second input is a word, the first  input  must  be  a  word  of
  619.        length one (a single character), and the output is true if and only if
  620.        the first input is contained in the second as  a  character.   If  the
  621.        second  input  is  a list, the first input can be any Logo object, and
  622.        the output is true if and only if the first input is a member  of  the
  623.        second input.  (Note that this is member, not subset.)
  624.  
  625.   item - Operation, two inputs.  Abbreviation: nth
  626.        The first input must be a positive integer less than or equal  to  the
  627.        count  of the second input.  If the second input is a word, the output
  628.        is a word of length one containing the  selected  character  from  the
  629.        word.   (Items  are numbered from 1, not 0.)  If the second input is a
  630.        list, the output is the selected member of the list.
  631.  
  632.        Primitive_procedures_for_turtles_and_graphics.  An important  part  of
  633.   the  Logo  environment  is a rich set of applications to which the computer
  634.   can be directed.  The most important of these is turtle geometry, a way  of
  635.   describing paths of motion in a plane which is well-suited to computer pro-
  636.   gramming.  There are two ways to use the turtle procedures.  First, you can
  637.   control  a floor turtle, a small robot which can move one the floor or on a
  638.   table under computer control.  Second, you can use a display turtle to draw
  639.   pictures on the TV screen of a graphics terminal.
  640.  
  641.        Each computer center has a  different  variety  of  graphics  hardware
  642.   available.  Floor turtles are very different from display turtles, but also
  643.   each kind of display terminal has different characteristics.  For  example,
  644.   some  terminals  can  draw  in several colors; others can't.  The following
  645.   descriptions of graphics primitives explain the "best" case  for  each  one
  646.   and mention restrictions on some graphics devices.
  647.  
  648.        The floor turtle can draw pictures on paper, because it has a pen  at-
  649.   tached to its "belly": the underside of the turtle.  Since it is a mechani-
  650.   cal device, however, it is not very precise; the pictures you get  may  not
  651.   be exactly like what your program specifies.  A more interesting way to use
  652.   the floor turtle is to take advantage of its touch sensors.  Switches under
  653.   the  turtle's dome allow the computer to know when the turtle bumps into an
  654.   obstacle.  You can use this information to write  programs  to  get  around
  655.   obstacles or to follow a maze.
  656.  
  657.                                       10
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.        The display turtle lives on the surface of a TV screen.  It  can  draw
  665.   pictures  more  precisely  than the floor turtle, since it does not measure
  666.   distances and angles mechanically.  It is also faster than the  floor  tur-
  667.   tle.   When  using the display turtle, remember that it interprets commands
  668.   relative to its own position and direction, just as the floor turtle  does.
  669.   The  command left, for example, turns the turtle to its own left, which may
  670.   or may not be toward the left side of the TV screen.
  671.  
  672.   turtle - Command, one input.  Abbreviation: tur
  673.        The input is the name of a turtle.  You can only control one turtle at
  674.        a time, so using this command a second time releases the turtle previ-
  675.        ously selected.  The names of floor turtles are numbers like 0 and  1.
  676.        If  you are using a graphics display terminal (not just a text display
  677.        trminal), you can control the display turtle by using the word display
  678.        (or  the  abbreviation  dpy)  as the turtle name.  (As usual, the word
  679.        must be preceded by a quotation mark.)  If you use a  graphics  primi-
  680.        tive without selecting a turtle, Logo assumes that you want to use the
  681.        display turtle.  But once you select a floor turtle, you must say tur-
  682.        tle "display explicitly to switch to the display.
  683.  
  684.        The word off as input to the turtle command releases a  floor  turtle,
  685.        if  you  have  one, or turns off the graphics display if you have been
  686.        using the display turtle.  This also happens when you leave Logo.
  687.  
  688.   forward - Command, one input.  Abbreviation: fd
  689.        The input is a number, the distance you would like the turtle to move.
  690.        For a floor turtle, the unit of distance is however far the turtle can
  691.        travel in 1/30 second.  For a display turtle, the unit is one  dot  on
  692.        the  TV screen.  (Note: on some displays, one dot horizontally may not
  693.        be the same length as one dot vertically.  The setscrunch command  al-
  694.        lows  you  to  control  the  relative  sizes  so that squares come out
  695.        square.)  The turtle moves in whatever direction it is  pointing  when
  696.        you use the command.
  697.  
  698.   back - Command, one input.  Abbreviation: bk
  699.        The input is a number, a distance to move, as in the forward  command.
  700.        The  difference is that the turtle moves backward, i.e., in the direc-
  701.        tion exactly opposite to the way it's pointing.
  702.  
  703.   left - Command, one input.  Abbreviation: lt
  704.        The input is a number, the number of degrees of  angle  through  which
  705.        the turtle should turn counterclockwise.  This command does not change
  706.        the position of the turtle, but merely its heading (the  direction  in
  707.        which it points).  The turn will be only approximately correct for the
  708.        floor turtle, because of mechanical errors.  For the  display  turtle,
  709.        the  angle  will  be  perfectly reproducible, although it may not look
  710.        quite right on the screen because of the difference  in  size  between
  711.        horizontal  and vertical dots.  Nevertheless, a display turtle program
  712.        will work in the sense that when the turtle is supposed to  return  to
  713.        its starting point, it will do so.
  714.  
  715.   right - Command, one input.  Abbreviation: rt
  716.        The input is a number; the turtle turns through the  specified  number
  717.        of degrees clockwise.
  718.  
  719.   penup - Command, no inputs.  Abbreviation: pu
  720.        This command tells the turtle to raise its pen from the paper, so that
  721.        it  does  not leave a trace when it moves.  In the case of the display
  722.  
  723.                                       11
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.        turtle, there is no physical pen to move mechanically, but the  effect
  731.        is the same: any forward or back commands after this point do not draw
  732.        a line.  The floor turtle starts with its pen up; the  display  turtle
  733.        starts with its pen down.  Note: the floor turtle will not move on the
  734.        carpet correctly with its pen down; put it on a smooth surface if  you
  735.        want to draw pictures.
  736.  
  737.   pendown - Command, no inputs.  Abbreviation: pd
  738.        This command tells the turtle to lower its pen, so that later commands
  739.        will draw lines when the turtle moves.
  740.  
  741.   penerase - Command, no inputs.  Abbreviation: pe
  742.        This command tells the turtle to "lower its  eraser",  so  that  lines
  743.        previously  drawn will be erased when retraced by the turtle.  It only
  744.        works with the display turtle.  The commands penup, pendown, penerase,
  745.        and  penreverse  are  mutually  exclusive; whichever was most recently
  746.        used is the one which affects the turtle.  (Graphics  terminals  which
  747.        cannot selectively erase lines, such as Tektronix displays, will treat
  748.        penerase as pendown.)
  749.  
  750.   penreverse - Command, no inputs.  Abbreviation: px
  751.        This command tells the display turtle to lower  its  "reversing  pen";
  752.        thereafter,  when  the turtle moves, it turns on any points which were
  753.        off, and turns off any points which were on.  The commands penup, pen-
  754.        down,  penerase,  and penreverse are mutually exclusive; whichever was
  755.        most recently used is  the  one  which  affects  the  turtle.   (Note:
  756.        Graphics  terminals which cannot penreverse will treat this command as
  757.        pendown.)
  758.  
  759.   penmode - Operation, no inputs.
  760.        This operation applies to the floor or the display turtle.  It outputs
  761.        one of the words penup, pendown, penerase, or penreverse, depending on
  762.        the current state of the turtle's pen.
  763.  
  764.   lampon - Command, no inputs.  Abbreviation: lon
  765.        This command applies only to the floor turtle; it turns on  the  head-
  766.        lamps on the front of the turtle.
  767.  
  768.   lampoff - Command, no inputs.  Abbreviation: loff
  769.        This command turns off the floor turtle's headlamps.
  770.  
  771.   hitoot - Command, one input.  Abbreviation: hit
  772.        This command applies only to the floor turtle.  It sounds the turtle's
  773.        horn  at  the  higher of its two pitches.  The input is a number which
  774.        indicates the number of quarter-seconds to toot the horn.  Note: large
  775.        numbers  are  likely  to lead to violent behavior on the part of other
  776.        computer users.
  777.  
  778.   lotoot - Command, one input.  Abbreviation: lot
  779.        This command sounds the floor turtle's horn at the lower  of  its  two
  780.        pitches.  The input is the duration of the toot.
  781.  
  782.   ftouch - Operation (predicate), no inputs.  Abbreviation: fto
  783.        This operation can be used only with the floor turtle.  It has as  its
  784.        output  the word true if the front of the turtle is touching an obsta-
  785.        cle; otherwise it has the word false as its output.
  786.  
  787.   btouch - Operation (predicate), no inputs.  Abbreviation: bto
  788.  
  789.                                       12
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.        This operation can be used only with the floor turtle.  It has as  its
  797.        output  the  word true if the back of the turtle is touching an obsta-
  798.        cle; otherwise it has the word false as its output.
  799.  
  800.   ltouch - Operation (predicate), no inputs.  Abbreviation: lto
  801.        This operation can be used only with the floor turtle.  It has as  its
  802.        output  the  word  true  if the left side of the turtle is touching an
  803.        obstacle; otherwise it has the word false as its output.
  804.  
  805.   rtouch - Operation (predicate), no inputs.  Abbreviation: rto
  806.        This operation can be used only with the floor turtle.  It has as  its
  807.        output  the  word  true if the right side of the turtle is touching an
  808.        obstacle; otherwise it has the word false as its output.
  809.  
  810.   clearscreen - Command, no inputs.  Abbreviation: cs
  811.        This command applies only to the display turtle.  It erases everything
  812.        on  the TV screen, and restores the turtle to its initial position and
  813.        heading (center of the screen, facing toward the top edge).
  814.  
  815.   wipeclean - Command, no inputs.  Abbreviation: clean
  816.        This command applies only to the display turtle.  It erases everything
  817.        on  the  TV screen, but does not change the turtle's position or head-
  818.        ing.
  819.  
  820.   fullscreen - Command, no inputs.  Abbreviation: full
  821.        This command applies only to the Atari display turtle.  It  eliminates
  822.        the use of the bottom four lines of the screen to display the commands
  823.        you type; instead, the entire screen is available to show the  picture
  824.        drawn  by the turtle.  However, you can no longer see what you're typ-
  825.        ing.  The command may be used after the picture is already drawn;  the
  826.        part  "hidden"  by  the  text  at the bottom of the screen will become
  827.        visible.   On  other  displays,   fullscreen   and   splitscreen   are
  828.        equivalent;  they  make  the entire screen available for graphics, and
  829.        text appears on the bottom line (Gigis)  or  superimposed  (ADMs),  or
  830.        somewhere.
  831.  
  832.   splitscreen - Command, no inputs.  Abbreviation: split
  833.        This command applies only to the Atari display  turtle.   It  restores
  834.        the  normal  text display at the bottom of the screen, undoing the ef-
  835.        fect  of  the  full  command.   On  other  displays,  fullscreen   and
  836.        splitscreen  are equivalent; they make the entire screen available for
  837.        graphics, with text superimposed in a display-dependent area.
  838.  
  839.   textscreen - Command, no inputs.  Abbreviation: text
  840.        This command applies only to the display turtle.  It  temporarily  re-
  841.        moves  the  turtle  display  from the screen, making the entire screen
  842.        available for text display.  The commands fullscreen  and  splitscreen
  843.        will  restore  the graphics display.  Note:  On the Atari display, the
  844.        picture on the screen is  remembered,  so  that  when  you  return  to
  845.        fullscreen or splitscreen mode, the picture returns to the screen.  On
  846.        other displays, the picture is forgotten, and you return to  an  empty
  847.        graphics screen.
  848.  
  849.   hideturtle - Command, no inputs.  Abbreviation: ht
  850.        This command applies only  to  the  display  turtle.   It  erases  the
  851.        display  of  the turtle itself from the screen, so that only the lines
  852.        drawn when the turtle moves are visible.  The display is  faster  when
  853.        the turtle is hidden (only slightly faster on the Atari, but much fas-
  854.  
  855.                                       13
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.        ter on other terminals).  Also, once a graphics program  is  debugged,
  863.        it  may  be  prettier to watch without the turtle visible.  (Note:  On
  864.        the Tektronix display, the turtle is never visible, because the termi-
  865.        nal cannot erase selectively.)
  866.  
  867.   showturtle - Command, no inputs.  Abbreviation: st
  868.        This command applies only to the  display  turtle.   It  restores  the
  869.        display  of  the  turtle,  after the hideturtle command has been used.
  870.        (Note:  On the Tektronix display, the turtle is never visible.)
  871.  
  872.   shownp - Operation (predicate), no inputs.
  873.        This predicate applies only to the display  turtle.   It  outputs  the
  874.        word true if the turtle is visible on the TV screen, false otherwise.
  875.  
  876.   pencolor - Command, one input.  Abbreviation: penc
  877.        This command applies only to the display turtle.  Its effect  is  dif-
  878.        ferent depending on how each type of terminal supports color.  For the
  879.        Atari, the input must be an integer between 0 and 6.  An  input  of  0
  880.        enters  black-and-white  display  mode  (which is the turtle's initial
  881.        mode), in which lines are as thin as possible but there is no  control
  882.        of  color.   Any  other  input  selects color mode, in which lines are
  883.        twice as thick, so the effective size of the screen  is  smaller,  but
  884.        colors  can  be  used.   There  are, in color mode, three possible pen
  885.        colors, numbered 1 to 3.  There are  256  possible  colors,  but  only
  886.        three  can be on the screen at a time; the setcolor command is used to
  887.        decide which pen draws in which actual color.  If the input is  4,  5,
  888.        or 6, the color is that of pen 1, 2, or 3, respectively, but lines are
  889.        drawn in "fill mode": for each point inked, all points  to  its  right
  890.        are  also  inked until a point is reached which was already inked.  On
  891.        the Gigi, there is only one mode, and there is no loss  of  resolution
  892.        in  using  color.  The input must be between 0 and 7; 0 means black, 7
  893.        means white.  The ADM, Tektronix, and Sun displays do not have  multi-
  894.        color drawing.
  895.  
  896.   setcolor - Command, two inputs.  Abbreviation: setc
  897.        This command applies only to the Atari display turtle.  The first  in-
  898.        put  must be an integer between 0 and 3.  If the input is nonzero, the
  899.        second input specifies the color for the pen selected by the first in-
  900.        put.  If the first input is zero, the second input specifies the back-
  901.        ground color for the color graphics display.  The second input is  ei-
  902.        ther  an  integer between 0 and 15, which is a color number, or a list
  903.        of two integers, in which case the first is a  color  number  and  the
  904.        second is an intensity number, an integer between 0 and 7.
  905.  
  906.   setxy - Command, two inputs.
  907.        The two inputs must be numbers.  The turtle is moved to the  point  on
  908.        the  screen  whose  x  (horizontal) coordinate is the first input, and
  909.        whose y (vertical) coordinate is the second input.  The center of  the
  910.        screen,  where  the  turtle starts, has both coordinates zero.  If the
  911.        pen is down, this command draws a line.  This command applies only  to
  912.        the display turtle.
  913.  
  914.   setheading - Command, one input.  Abbreviation: seth
  915.        The input must be a number.  The turtle's heading is set to the input,
  916.        taken  in degrees.  Zero points straight up, as the turtle starts out;
  917.        positive headings are clockwise from zero.  This command applies  only
  918.        to the display turtle.
  919.  
  920.  
  921.                                       14
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.   towardsxy - Operation, two inputs.
  929.        This operation applies only to the display  turtle.   The  two  inputs
  930.        must  be  numbers, which are the x and y coordinates of a point on the
  931.        TV screen.  The output is a number which is the heading to  which  the
  932.        turtle  must  be  set,  in  order to point towards that point from its
  933.        current position.  Note: this operation does not actually move or turn
  934.        the  turtle.   You  must  use it as the input to setheading if that is
  935.        what you want.
  936.  
  937.   xcor - Operation, no inputs.
  938.        The output is the turtle's current  x  (horizontal)  coordinate.   The
  939.        operation works only with the display turtle.
  940.  
  941.   ycor - Operation, no inputs.
  942.        The output is the turtle's  current  y  (vertical)  coordinate.   This
  943.        operation works only with the display turtle.
  944.  
  945.   heading - Operation, no inputs.
  946.        The output is the turtle's current heading in degrees.  This operation
  947.        works only with the display turtle.
  948.  
  949.   getpen - Operation, no inputs.
  950.        The output is the turtle's current pen color, or (on the  Atari)  zero
  951.        if  in  black-and-white  mode.   This  operation  works  only with the
  952.        display turtle.
  953.  
  954.   setscrunch - Command, one input.  Abbreviation: setscrun
  955.        This command is used only for display turtles.  The input  must  be  a
  956.        number.  The vertical component of turtle motion is multiplied by this
  957.        number before each motion is taken.  If squares come out too  wide  on
  958.        your  screen,  you should increase the number; if too tall, you should
  959.        decrease it.  (You can also use setscrunch to deform the turtle's  mo-
  960.        tion  on purpose, so for example a circle program will draw an ellipse
  961.        instead.)  The initial scrunch value depends on the terminal  you  are
  962.        using:  for  the Atari and the Gigi, it is around 0.8 (your particular
  963.        computer center will adjust this for the particular  TV  monitors  you
  964.        use),  but  for  the  ADM, Tektronix, and Sun, it is 1.0 because these
  965.        terminals display the same size steps horizontally and vertically.
  966.  
  967.   scrunch - Operation, no inputs.
  968.        This operation is used only for display turtles.  It outputs a number,
  969.        which is the scrunch factor (or aspect ratio) by which vertical motion
  970.        is multiplied before it is displayed.  This number  is  changed  using
  971.        the setscrunch command.
  972.  
  973.        Primitive_procedures_for_arithmetic.  Several procedures are available
  974.   for  arithmetic  operations  on numbers.  In all cases, the inputs to these
  975.   procedures must be numbers, except as otherwise indicated in the individual
  976.   descriptions.
  977.  
  978.        In general, procedures are used in Logo by typing first  the  name  of
  979.   the  procedure,  then  its  inputs.   This is true of arithmetic procedures
  980.   also, e.g.
  981.  
  982.        sum 3 2
  983.  
  984.   However, for some arithmetic operations,  Logo  also  recognizes  the  more
  985.   traditional infix notation, with the operation between the two inputs:
  986.  
  987.                                       15
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.        3 + 2
  996.  
  997.   Be warned, though, that the use of infix forms makes it difficult for  Logo
  998.   to know how to group operations, unless parentheses are used.  If you stick
  999.   to the standard (in Logo) prefix notation, the grouping is always unambigu-
  1000.   ous.    For  example,  the  first  two  of  these  three  instructions  are
  1001.   equivalent, but the third is not:
  1002.  
  1003.        if equalp count "hello 5 [print "Yes.]
  1004.        if (count "hello) = 5 [print "Yes.]
  1005.        if count "hello = 5 [print "Yes.]
  1006.  
  1007.   The reason for the error message produced by the last of  those  three  in-
  1008.   structions is that Logo interprets it as
  1009.  
  1010.        if count equalp "hello 5 [print "Yes.]
  1011.  
  1012.   That is, the equality test is done first, on the word hello itself,  rather
  1013.   than first taking the count of hello as was intended.
  1014.  
  1015.   sum - Operation, two inputs.  Infix: +
  1016.        The output of this procedure is the sum of the two inputs.
  1017.  
  1018.   difference - Operation, two inputs.  Abbreviation: diff  Infix: -
  1019.        The output of this procedure is the difference of the two inputs.
  1020.  
  1021.   product - Operation, two inputs.  Infix: *
  1022.        The output of this procedure is the product of the two inputs.
  1023.  
  1024.   quotient - Operation, two inputs.  Infix: /
  1025.        The output of this procedure is the quotient of the  two  inputs.   If
  1026.        both inputs are integers, the output is also an integer; the remainder
  1027.        of the division is lost.  If either input is not an integer, the  quo-
  1028.        tient can include a fractional part.  Therefore, these two are not the
  1029.        same:
  1030.  
  1031.             quotient 2 3
  1032.             quotient 2.0 3
  1033.  
  1034.   remainder - Operation, two inputs.  Abbreviation: mod  Infix: \
  1035.        The inputs to this procedure must be integers.  The output is also  an
  1036.        integer,  and  is  the  remainder  of  dividing the first input by the
  1037.        second.
  1038.  
  1039.   maximum - Operation, two inputs.  Abbreviation: max
  1040.        The output of this procedure is equal to whichever of the  two  inputs
  1041.        is numerically greater.
  1042.  
  1043.   minimum - Operation, two inputs.  Abbreviation: min
  1044.        The output of this procedure is equal to whichever of the  two  inputs
  1045.        is numerically smaller.
  1046.  
  1047.   greaterp - Operation (predicate), two inputs.  Infix: >
  1048.        The output of this procedure is the word true if the  first  input  is
  1049.        numerically  strictly  greater  than  the second input.  Otherwise the
  1050.        output is the word false.
  1051.  
  1052.  
  1053.                                       16
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.   lessp - Operation (predicate), two inputs.  Infix: <
  1061.        The output of this procedure is the word true if the  first  input  is
  1062.        numerically strictly less than the second input.  Otherwise the output
  1063.        is the word false.
  1064.  
  1065.   equalp - Operation (predicate), two inputs.  Infix: =
  1066.        The two inputs to this procedure may be any Logo objects.  If they are
  1067.        numbers,  then  the  output  is  the word true if they are numerically
  1068.        equal, false if they are numerically unequal.  If either input is  not
  1069.        a  number,  then the output is the same as for the procedure is: it is
  1070.        true if the two inputs are identical, false if not.  For example,  the
  1071.        numbers 2 and 2.0 are numerically equal, but not identical.
  1072.  
  1073.   numberp - Operation (predicate), one input.
  1074.        The input may be any Logo object.  The output is the word true if  the
  1075.        input is a number, false if not.
  1076.  
  1077.   zerop - Operation (predicate), one input.
  1078.        The input must be a number.  The output is the word true if the  input
  1079.        is numerically equal to zero, false otherwise.
  1080.  
  1081.   random - Operation, no inputs.
  1082.        The output from this procedure is an integer between 0 and 9, i.e.,  a
  1083.        single  digit.   It is chosen randomly, so the output may be different
  1084.        each time the procedure is used.
  1085.  
  1086.   rnd - Operation, one input.
  1087.        The input must be a  positive  integer.   The  output  is  a  randomly
  1088.        selected integer between 0 and one less than the input.
  1089.  
  1090.   sqrt - Operation, one input.
  1091.        The input must be a nonnegative number.   The  output  is  its  square
  1092.        root.
  1093.  
  1094.   pow - Operation, two inputs.
  1095.        The inputs must be numbers.  If the first is negative, the second must
  1096.        be  an integer.  The output is the first number raised to the power of
  1097.        the second input.
  1098.  
  1099.   sin - Operation, one input.
  1100.        The input must be numeric.  The output is the sine of the input, taken
  1101.        in degrees, not radians.
  1102.  
  1103.   cos - Operation, one input.
  1104.        The input must be numeric.  The output is the  cosine  of  the  input,
  1105.        taken in degrees, not radians.
  1106.  
  1107.   arctan - Operation, one input.  Abbreviation: atan
  1108.        The input must be numeric.  The output is the arctangent, in  degrees,
  1109.        of the input.
  1110.  
  1111.        Primitive_procedures_for_conditional_execution.  The predicates  (like
  1112.   wordp)  which  we've  mentioned above can be used to carry out some command
  1113.   only if a condition is met.  The basic command for the purpose is if:
  1114.  
  1115.   if - Command or operation, two or three inputs.
  1116.        The first input to the if procedure must be either the  word  true  or
  1117.        the  word  false.   Typically, it is the output from a predicate.  The
  1118.  
  1119.                                       17
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.        second and (optional) third inputs are  lists  containing  instruction
  1127.        lines.   The second input is executed if the first input is true.  The
  1128.        third input, if any, is executed if the first input is false:
  1129.  
  1130.        to greet :person
  1131.        if equalp :person [Ronald Reagan] [print [Hi, turkey!]] \
  1132.                            [print sentence "Hi, :person]
  1133.        end
  1134.  
  1135.        In that example, the first input to if is the output from the  expres-
  1136.        sion
  1137.        equalp :person [Ronald Reagan].
  1138.  
  1139.        The if procedure can be used as an operation, producing a  value.   In
  1140.        this case, the third input is required:
  1141.  
  1142.        print if equalp :person "Reagan ["Loser] ["Winner]
  1143.  
  1144.   test - Command, one input.
  1145.        The input must be the word  true  or  the  word  false.   The  command
  1146.        remembers  its  input  for  use  in a later iftrue or iffalse command.
  1147.        This is an alternative to if which is useful if  several  instructions
  1148.        are  to  be  made  conditional  on the same condition.  The remembered
  1149.        truth value is local to the current procedure, if any.
  1150.  
  1151.   iftrue - Command, one input.  Abbreviation: ift
  1152.        The input must be an instruction list.  It is run if the  most  recent
  1153.        test command saved a true value.
  1154.  
  1155.   iffalse - Command, one input.  Abbreviation: iff
  1156.        The input must be an instruction list.  It is run if the  most  recent
  1157.        test command saved a false value.
  1158.  
  1159.   both - Operation (predicate), two inputs.  Abbreviation: and
  1160.        The two inputs must both be either true or false.  The output is  true
  1161.        if both inputs are true; otherwise the output is false.
  1162.  
  1163.   either - Operation (predicate), two inputs.  Abbreviation: or
  1164.        The two inputs must be either true or false.  The output is true if at
  1165.        least one of the inputs is true; otherwise the output is false.
  1166.  
  1167.   not - Operation (predicate), one input.
  1168.        The input must be either true or false.  The output is true if the in-
  1169.        put is false, and vice versa.
  1170.  
  1171.        Primitive_procedures_for_file_input_and_output.  In the Unix operating
  1172.   system,  there  are  two steps in reading or writing files: first, the file
  1173.   must be opened, thereby associating a "file descriptor" (an  integer)  with
  1174.   the  file name; second, the file descriptor is used to specify the file for
  1175.   each read or write operation.  Logo has primitive procedures  for  each  of
  1176.   these steps.
  1177.  
  1178.   openread - Operation, one input.  Abbreviation: openr
  1179.        The input to this procedure is a word, which must be a Unix  filename.
  1180.        It  can  contain slashes to indicate directory names.  If the file can
  1181.        be opened for reading,  the  output  from  the  procedure  is  a  file
  1182.        descriptor,  which  should  be stored in a variable for use in reading
  1183.        the file.  If the file cannot be opened, an error results.
  1184.  
  1185.                                       18
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.   fileread - Operation, one input.  Abbreviation: fird
  1193.        The input must be a file descriptor, previously  output  by  openread.
  1194.        The  procedure  reads one line from the file.  The output is the line,
  1195.        in the form of a list.  (That is, the output is the file  line  as  if
  1196.        enclosed in square brackets in a program.)  If the end of the file has
  1197.        been reached, the output is the empty word.  If the file line contains
  1198.        mismatched brackets, trouble may result.
  1199.  
  1200.   fileword - Operation, one input.  Abbreviation: fiwd
  1201.        The input must be a file descriptor, open for reading.  The  procedure
  1202.        reads one line from the file.  The output is that line, in the form of
  1203.        a single word, including spaces and punctuation  characters.   If  the
  1204.        end of the file has been reached, the output is the empty list.
  1205.  
  1206.   openwrite - Operation, one input.  Abbreviation: openw
  1207.        The input must be a Unix filename.  The file  is  opened  for  writing
  1208.        (replacing any previous version), if allowed, and the output is a file
  1209.        descriptor, for use by file printing commands below.  If the file can-
  1210.        not be opened, an error results.
  1211.  
  1212.   fileprint - Command, two inputs.  Abbreviation: fip
  1213.   filetype - Command, two inputs.  Abbreviation: fity
  1214.   filefprint - Command, two inputs.  Abbreviation: fifp
  1215.   fileftype - Command, two inputs.  Abbreviation: fifty
  1216.        The first input  must  be  a  file  descriptor  previously  output  by
  1217.        openwrite.   The  second  input  is  any  object.  The second input is
  1218.        printed (typed, fprinted, ftyped) into the file.
  1219.  
  1220.   close - Command, one input.
  1221.        The input must be a file descriptor.  The file is closed.   This  must
  1222.        be done when you've finished reading or writing the file.
  1223.  
  1224.        Sample program:
  1225.  
  1226.        make "fd openwrite "outfile
  1227.        fileprint :fd "Hello.
  1228.        close :fd
  1229.  
  1230.        This will create a file named outfile containing the word Hello.
  1231.  
  1232.        Primitive_procedures_for_procedure_exit.  A  procedure  written  by  a
  1233.   user,  in  Logo,  can be a command or an operation.  If it is an operation,
  1234.   you must, in the procedure, say what its output should be.  If it is a com-
  1235.   mand, it can simply stop at the end of the procedure, or you can explicitly
  1236.   make it stop before the end.
  1237.  
  1238.   output - Command, one input.  Abbreviation: op
  1239.        This command is used in a user procedure  which  is  meant  to  be  an
  1240.        operation.  The input to this command becomes the output from the user
  1241.        procedure.  Please don't be confused by the fact that  the  user  pro-
  1242.        cedure is an operation, while the output primitive procedure is a com-
  1243.        mand used in that procedure.  Example:
  1244.  
  1245.        to nickname :person
  1246.        if equalp :person [Peter Parker] [output "Spiderman]
  1247.        if equalp :person [Lamont Cranston] [output "Shadow]
  1248.        output first :person
  1249.        end
  1250.  
  1251.                                       19
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.   stop - Command, no inputs.
  1260.        This command is used in user procedures which are  meant  to  be  com-
  1261.        mands.   It stops the user procedure.  (Note that it does not stop all
  1262.        running procedures.  If user procedure A runs user procedure B, a stop
  1263.        command  in  procedure B returns to procedure A, which continues after
  1264.        the point where procedure B was invoked.)
  1265.  
  1266.   toplevel - Command, no inputs.  Abbreviation: top
  1267.        This command stops all running procedures.  The user at  the  terminal
  1268.        is  prompted  to  type  another command.  This can be used when a user
  1269.        procedure discovers some error condition and wants to abort the entire
  1270.        program, for example.
  1271.  
  1272.        Property_lists.  It is possible to associate with any name a  list  of
  1273.   "properties".  A property list contains property names and property values.
  1274.   For example:
  1275.  
  1276.        pprop "bh "firstname "Brian
  1277.        pprop "bh "lastname "Harvey
  1278.  
  1279.   The form of a property list is
  1280.  
  1281.        [name1 val1 name2 val2 name3 val3]
  1282.  
  1283.   Although this data structure could be created using other Logo  primitives,
  1284.   special property list primitives are provided because they are faster.  The
  1285.   property lists do not share storage with Logo variables, so you can  change
  1286.   the value of any property without having to recopy the entire property list
  1287.   as you would ordinarily.   The  following  primitives  manipulate  property
  1288.   lists.
  1289.  
  1290.   pprop - Command, three inputs.
  1291.        The first input, which must be a word, is a name with which a property
  1292.        list  is  associated.   The second input, which must be a word, is the
  1293.        name of a property.  The third input can be any Logo object.   It  be-
  1294.        comes the value of the specified property of the specified name.
  1295.  
  1296.   gprop - Operation, two inputs.
  1297.        Both inputs must be words.  The first is a name, and the second  is  a
  1298.        property  name.   The output is the value of the indicated property of
  1299.        the indicated object.  It is not an error if there is no such  proper-
  1300.        ty; the output in that case is the empty list.
  1301.  
  1302.   remprop - Command, two inputs.
  1303.        The inputs must be words, as for gprop.  The specified property is re-
  1304.        moved from the specified name.
  1305.  
  1306.   plist - Operation, one input.
  1307.        The input must be a word, which is a name.  The output is the property
  1308.        list  of  the  specified name.  Note: the output is actually a copy of
  1309.        the property list.  The real property list is not a  Logo  list.   Any
  1310.        later  changes to the properties of the specified name will not change
  1311.        the list which was output by an earlier plist.
  1312.  
  1313.   pps - Command, no inputs.
  1314.        All properties of all names are listed on your terminal.
  1315.  
  1316.  
  1317.                                       20
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.        Pausing.  When you are debugging a complicated  Logo  program,  it  is
  1325.   very  helpful  to be able to stop in the middle of a procedure, so that you
  1326.   can give interactive commands to examine its inputs and other  local  vari-
  1327.   ables.  This is different from stopping a procedure, which destroys its lo-
  1328.   cal environment.  There are three ways a procedure can pause:  (1) You  can
  1329.   include  the  command  pause  in the procedure definition, to make the pro-
  1330.   cedure pause at a particular place you choose in advance; (2) you  can  de-
  1331.   cide  to pause a procedure while it is running by typing the system "inter-
  1332.   rupt" character (this is control-C at Lincoln-Sudbury but is  different  on
  1333.   other  systems);  or  (3) you can arrange for an error in the processing of
  1334.   the procedure to pause instead of stopping as it usually does.
  1335.  
  1336.        Note that when you type the  system  "quit"  character  (control-G  at
  1337.   Lincoln-Sudbury)  Logo does not pause, but returns to toplevel.  All infor-
  1338.   mation about the local state of your active procedures is lost.
  1339.  
  1340.        When you are paused, Logo accepts instructions from your  terminal  as
  1341.   it  does  at toplevel, but local variables can be examined or modified.  To
  1342.   let you know that you are paused, Logo prompts with the characters "-*" in-
  1343.   stead  of  just  "*"  as usual.  It is possible to pause within a procedure
  1344.   within a pause; in this case your prompt is "--*" to indicate two levels of
  1345.   pause.  This can be continued to higher levels.
  1346.  
  1347.        To get out of a pause, there are three things you  can  do.   You  can
  1348.   give  the  command toplevel, which stops all pending procedures and returns
  1349.   to interactive top level.  You can give the command  stop  or  the  command
  1350.   output  with  an input, which will terminate the current procedure (without
  1351.   or with an output respectively) and return to its  calling  procedure.   Or
  1352.   you  can  give the command continue, which will resume the procedure at the
  1353.   point where you paused.
  1354.  
  1355.   pause - Command, no inputs.
  1356.        This command is meaningful only  within  a  procedure.   It  causes  a
  1357.        pause.
  1358.  
  1359.   continue - Command, no inputs.  Abbreviation: co
  1360.        This command is meaningful  only  when  typed  during  an  interactive
  1361.        pause.  It continues the current procedure from where it was paused.
  1362.  
  1363.   errpause - Command, no inputs.
  1364.        This command tells Logo that any errors which happen during  procedure
  1365.        execution  from  now  on should cause a pause, rather than a return to
  1366.        toplevel.
  1367.  
  1368.   errquit - Command, no inputs.
  1369.        This command tells Logo that any errors which happen during  procedure
  1370.        execution  from now on should return to toplevel, rather than pausing.
  1371.        This is the initial state of affairs when you start Logo.
  1372.  
  1373.   setqpause - Command, no inputs.
  1374.        This command tells Logo that from now on, the  system  quit  character
  1375.        should  pause, and the system interrupt character should return to to-
  1376.        plevel.  This is the reverse of the usual interpretation.   This  com-
  1377.        mand  is  provided  for  people whose systems or keyboards make one of
  1378.        these characters easier to type than the other.  In particular,  under
  1379.        Eunice there is only an interrupt character, not a quit character.
  1380.  
  1381.   setipause - Command, no inputs.
  1382.  
  1383.                                       21
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.        This command tells Logo that from now on, the system interrupt charac-
  1391.        ter  should  pause, and the system quit character should return to to-
  1392.        plevel.  This is the initial state of affairs when you start Logo.
  1393.  
  1394.        Miscellaneous_primitives.  The remaining primitives are one of a kind,
  1395.   or very obscure, or both.
  1396.  
  1397.   goodbye - Command, no inputs.  Abbreviation: bye
  1398.        This command is used to leave Logo.  It is the only  way  out,  unless
  1399.        there is a bug somewhere.
  1400.  
  1401.   thing - Operation, one input.
  1402.        The input must be a word, and must be the name  of  a  variable.   The
  1403.        output is the value of the variable.  These are equivalent:
  1404.  
  1405.        :foo
  1406.        thing "foo
  1407.  
  1408.   namep - Operation (predicate), one input.
  1409.        The input must be a word.  The output is true if that word is the name
  1410.        of a variable which has a value assigned to it, false otherwise.
  1411.  
  1412.   wait - Command, one input.
  1413.        The input must be a positive integer.  Logo waits  that  many  seconds
  1414.        before continuing.
  1415.  
  1416.   trace - Command, no inputs.
  1417.        This command is used for debugging your Logo programs.  After you  use
  1418.        this  command,  every time a user-defined procedure starts or stops, a
  1419.        message is typed at your terminal naming the procedure and its  inputs
  1420.        or its output, if any.  The message is indented according to the depth
  1421.        in procedure calls.
  1422.  
  1423.   untrace - Command, no inputs.
  1424.        This command turns off the trace messages started by  the  trace  com-
  1425.        mand.
  1426.  
  1427.   unix - Command, one input.
  1428.        The input must be a Unix shell command, which  is  carried  out  in  a
  1429.        forked shell.  (/bin/sh is used, not csh.)  Example:
  1430.  
  1431.        to whois :user
  1432.        unix (sentence "grep (word "'^ :user ":') "/etc/inquir)
  1433.        end
  1434.  
  1435.   run - Command or operation, one input.
  1436.        The input must be a list, containing a  Logo  instruction  line.   The
  1437.        list is run as if you typed it directly to Logo.  Example:
  1438.  
  1439.        to while :condition :cmd
  1440.        if not run :condition [stop]
  1441.        run :cmd
  1442.        while :condition :cmd
  1443.        end
  1444.  
  1445.        make "number 1
  1446.        while [:number < 5] [print :number; make "number :number+1]
  1447.  
  1448.  
  1449.                                       22
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.        The run procedure can be used as an operation, if its input is a  Logo
  1457.        expression which produces a value, instead of a complete instruction:
  1458.  
  1459.        print run [sum 2 3]
  1460.  
  1461.   repeat - Command, two inputs.
  1462.        The first input must be a positive number.  The second is an  instruc-
  1463.        tion  list,  as  for the run command.  The list is run repeatedly, the
  1464.        number of times specified by the first input:
  1465.  
  1466.        repeat 5 [print "hello]
  1467.  
  1468.   repcount - Operation, no inputs.
  1469.        This operation may be used only within the range of a repeat  command.
  1470.        It  outputs  the number of repetitions which have been done, including
  1471.        the current one.  That is, it outputs 1 the first time through, 2  the
  1472.        second time, and so on.
  1473.  
  1474.   break - Command, no inputs.
  1475.        This command is only meaningful within the  range  of  an  if  command
  1476.        within  the  range  of a repeat command.  It terminates the repeat im-
  1477.        mediately.  If used in other contexts, the results may be strange.
  1478.  
  1479.   cbreak - Command, one input.
  1480.        The input must be either the word on or the word off.  If the input is
  1481.        on,  your terminal is placed in cbreak mode, which means that what you
  1482.        type is made available to your program every  character,  rather  than
  1483.        every  line.   This must be done before the readchar procedure, below,
  1484.        will work.  This facility is good for writing video game  programs  or
  1485.        text editors.  While in cbreak mode, echo is turned off also.
  1486.  
  1487.   readchar - Operation, no inputs.  Abbreviation: rc
  1488.        This operation waits for you to type a single character at your termi-
  1489.        nal.  The output is a word containing only that character.  This works
  1490.        only if you have turned on cbreak mode; see above.
  1491.  
  1492.   keyp - Operation (predicate), no inputs.
  1493.        This procedure outputs true if there is a character waiting to be read
  1494.        from the terminal, if you are in cbreak mode.  If not, it outputs true
  1495.        if there is an entire line waiting to be read.
  1496.  
  1497.   oflush - Command, no inputs.
  1498.        Normally, when you tell Logo to print something, the printing  is  not
  1499.        done  right  away.   Instead, Logo remembers everything you tell it to
  1500.        print, and the printing is done all at once  the  next  time  Logo  is
  1501.        waiting  for  you to type something.  This arrangement makes Logo much
  1502.        faster than it would be if everything were printed  immediately.   The
  1503.        oflush  command  tells  Logo to print whatever you've previously asked
  1504.        for right away, without waiting.
  1505.  
  1506.   help - Command, no inputs.
  1507.        This command types at your terminal a brief message about Logo and how
  1508.        to use it.
  1509.  
  1510.   describe - Command, one input.
  1511.        The input must be the name of a Logo primitive procedure.  A brief ex-
  1512.        planation of that primitive is typed at your terminal.
  1513.  
  1514.  
  1515.                                       23
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.   go - Command, one input.
  1523.        This command can be used only inside a procedure.  The input must be a
  1524.        number.   The same number must appear at the beginning of some line in
  1525.        the same procedure.  (This line number is otherwise ignored.) The next
  1526.        command  executed will be the one on the indicated line in the defini-
  1527.        tion.  Note: there is always a better way to do it.  If you have  pre-
  1528.        viously  programmed  in  BASIC, your only hope of ever really learning
  1529.        how to program computers is NEVER EVER to use the go command!
  1530.  
  1531.   debquit - Command, no inputs.
  1532.        This command is meant to be used only for debugging Logo  itself.   It
  1533.        is  explained here only for completeness.  After this command is used,
  1534.        the QUIT signal is not caught by Logo, so it will cause a core dump.
  1535.  
  1536.   memtrace - Command, no inputs.
  1537.        This command is meant to be used only for debugging Logo  itself.   It
  1538.        is  explained here only for completeness.  After this command is used,
  1539.        every allocation or deallocation of memory, and every character parsed
  1540.        by  the  interpreter, types an incomprehensible message at your termi-
  1541.        nal.
  1542.  
  1543.   yaccdebug - Command, no inputs.
  1544.        This command is meant to be used only for debugging Logo  itself.   It
  1545.        is  explained here only for completeness.  After this command is used,
  1546.        every state transition in the yacc parser  types  an  incomprehensible
  1547.        message at your terminal.
  1548.  
  1549.        The_Logo_library.  The  directory  /usr/lib/logo  contains  Logo  pro-
  1550.   cedures which are available to all users.  They are not listed by pots, but
  1551.   can be thought of as pseudo-primitives which happen to be written in  Logo.
  1552.   Some  of  these procedures are only useful in conjunction with the teaching
  1553.   units used in Introduction to Computers, but others are  generally  useful.
  1554.   This  manual  does  not fully document the Logo library, because it changes
  1555.   too often.  Look through the /usr/lib/logo directory yourself if you  want.
  1556.   The procedures listp, home, pos, setpos, towards, setx, and sety in the li-
  1557.   brary are provided for partial compatibility with Apple Logo.
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.                                       24
  1582.  
  1583.  
  1584.  
  1585.  
  1586.