home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / UCB Logo 3.0 / usermanual < prev   
Encoding:
Text File  |  1993-08-14  |  101.2 KB  |  2,935 lines  |  [TEXT/JV01]

  1. Berkeley Logo User Manual
  2.  
  3.  *    Copyright (C) 1993 by the Regents of the University of California
  4.  *
  5.  *      This program is free software; you can redistribute it and/or modify
  6.  *      it under the terms of the GNU General Public License as published by
  7.  *      the Free Software Foundation; either version 2 of the License, or
  8.  *      (at your option) any later version.
  9.  *  
  10.  *      This program is distributed in the hope that it will be useful,
  11.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *      GNU General Public License for more details.
  14.  *  
  15.  *      You should have received a copy of the GNU General Public License
  16.  *      along with this program; if not, write to the Free Software
  17.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. This is a program that is still being written.  Many things are missing,
  20. including adequate documentation.  This manual assumes that you already know
  21. how to program in Logo, and merely presents the details of this new
  22. implementation.  Read _Computer_Science_Logo_Style,_Volume_1:_
  23. _Intermediate_Programming_ by Brian Harvey (MIT Press, 1985) for a tutorial
  24. on Logo programming with emphasis on symbolic computation.
  25.  
  26. Here are the special features of this dialect of Logo:
  27.  
  28.     Source file compatible among Unix, DOS, and Mac platforms.
  29.  
  30.     Random-access arrays.
  31.  
  32.     Variable number of inputs to user-defined procedures.
  33.  
  34.     Mutators for list structure (dangerous).
  35.  
  36.     Pause on error, and other improvements to error handling.
  37.  
  38.     Comments and continuation lines; formatting is preserved when
  39.     procedure definitions are saved or edited.
  40.  
  41.     Terrapin-style tokenization (e.g., [2+3] is a list with one member)
  42.     but LCSI-style syntax (no special forms except TO).  The best of
  43.     both worlds.
  44.  
  45.     First-class instruction and expression templates (see APPLY).
  46.  
  47.     Macros.
  48.  
  49.  
  50. ENTERING AND LEAVING LOGO
  51. =========================
  52.  
  53. To start Logo, just type the word "logo" to the shell.  To leave Logo, enter
  54. the command "bye".  If you include one or more filenames on the command line
  55. when starting Logo, those files will be loaded before the interpreter starts
  56. reading commands from your terminal.  If you load a file that executes some
  57. program that includes a "bye" command, Logo will run that program and exit.
  58. You can therefore write standalone programs in Logo and run them with
  59. shell/batch scripts.  To support this technique, Logo does not print its
  60. usual welcoming and parting messages if you give file arguments to the logo
  61. command.
  62.  
  63. If you type your interrupt character (see table below) Logo will stop what
  64. it's doing and return to toplevel, as if you did THROW "TOPLEVEL.  If you
  65. type your quit character Logo will pause as if you did PAUSE.
  66.  
  67.             Unix          DOS        Mac
  68.  
  69.     toplevel    usually ctrl-C    ctrl-Q      command-. (period)
  70.  
  71.     pause        usually ctrl-\    ctrl-W      command-, (comma)
  72.  
  73. If you have an environment variable called LOGOLIB whose value is the name of
  74. a directory, then Logo will use that directory instead of the default
  75. library.  If you invoke a procedure that has not been defined, Logo first
  76. looks for a file in the current directory named proc.lg where "proc" is the
  77. procedure name in lower case letters.  If such a file exists, Logo loads
  78. that file.  If the missing procedure is still undefined, or if there is no
  79. such file, Logo then looks in the library directory for a file named proc
  80. (no ".lg") and, if it exists, loads it.  If neither file contains a
  81. definition for the procedure, then Logo signals an error.  Several
  82. procedures that are primitive in most versions of Logo are included in the
  83. default library, so if you use a different library you may want to include
  84. some or all of the default library in it.
  85.  
  86.  
  87. TOKENIZATION
  88. ============
  89.  
  90. Names of procedures, variables, and property lists are case-insensitive.  So
  91. are the special words END, TRUE, and FALSE.  Case of letters is preserved
  92. in everything you type, however.
  93.  
  94. Within square brackets, words are delimited only by spaces and square
  95. brackets.  [2+3] is a list containing one word.
  96.  
  97. After a quotation mark outside square brackets, a word is delimited by
  98. a space, a square bracket, or a parenthesis.
  99.  
  100. A word not after a quotation mark or inside square brackets is delimited
  101. by a space, a bracket, a parenthesis, or an infix operator +-*/=<>.  Note
  102. that words following colons are in this category.  Note that quote and
  103. colon are not delimiters.
  104.  
  105. A word consisting of a question mark followed by a number (e.g., ?3),
  106. when runparsed (i.e., where a procedure name is expected), is treated
  107. as if it were the sequence
  108.  
  109.     ( ? 3 )
  110.  
  111. making the number an input to the ? procedure.  (See the discussion of
  112. templates, below.)  This special treatment does not apply to words read
  113. as data, to words with a non-number following the question mark, or if
  114. the question mark is backslashed.
  115.  
  116. A line (an instruction line or one read by READLIST or READWORD) can be
  117. continued onto the following line if its last character is a tilde (~).
  118. READWORD preserves the tilde and the newline; READLIST does not.
  119.  
  120. A semicolon begins a comment in an instruction line.  Logo ignores
  121. characters from the semicolon to the end of the line.  A tilde as the
  122. last character still indicates a continuation line, but not a continuation
  123. of the comment.  For example, typing the instruction
  124.  
  125.     print "abc;comment ~
  126.     def
  127.  
  128. will print the word abcdef.  Semicolon has no special meaning in data
  129. lines read by READWORD or READLIST, but such a line can later be reparsed
  130. using RUNPARSE and then comments will be recognized.  If a tilde is typed
  131. at the terminal for line continuation, Logo will issue a tilde as a prompt
  132. character for the continuation line.
  133.  
  134. To include an otherwise delimiting character (including semicolon or tilde)
  135. in a word, precede it with backslash (\).  If the last character of a line
  136. is a backslash, then the newline character following the backslash will be
  137. part of the last word on the line, and the line continues onto the following
  138. line.  To include a backslash in a word, use \\.  If the combination
  139. backslash-newline is entered at the terminal, Logo will issue a backslash as
  140. a prompt character for the continuation line.  All of this applies to data
  141. lines read with READWORD or READLIST as well as to instruction lines.  A
  142. character entered with backslash is EQUALP to the same character without the
  143. backslash, but can be distinguished by the BACKSLASHEDP predicate.  (In
  144. Europe, backslashing is effective only on characters for which it is
  145. necessary: whitespace, parentheses, brackets, infix operators, backslash,
  146. vertical bar, tilde, quote, question mark, colon, and semicolon.)
  147.  
  148. An alternative notation to include otherwise delimiting characters in words
  149. is to enclose a group of characters in vertical bars.  All characters between
  150. vertical bars are treated as if they were letters.  In data read with READWORD
  151. the vertical bars are preserved in the resulting word.  In data read with
  152. READLIST (or resulting from a PARSE or RUNPARSE of a word) the vertical bars
  153. do not appear explicitly; all potentially delimiting characters (including
  154. spaces, brackets, parentheses, and infix operators) appear as though entered
  155. with a backslash.  Within vertical bars, backslash may still be used; the only
  156. characters that must be backslashed in this context are backslash and vertical
  157. bar themselves.
  158.  
  159. Characters entered between vertical bars are forever special, even if the
  160. word or list containing them is later reparsed with PARSE or RUNPARSE.
  161. The same is true of a character typed after a backslash, except that when
  162. a quoted word containing a backslashed character is runparsed, the backslashed
  163. character loses its special quality and acts thereafter as if typed normally.
  164. This distinction is important only if you are building a Logo expression out
  165. of parts, to be RUN later, and want to use parentheses.  For example,
  166.  
  167.     PRINT RUN (SE "\( 2 "+ 3 "\))
  168.  
  169. will print 5, but
  170.  
  171.     RUN (SE "MAKE ""|(| 2)
  172.  
  173. will create a variable whose name is open-parenthesis.  (Each example would
  174. fail if vertical bars and backslashes were interchanged.)
  175.  
  176.  
  177. DATA STRUCTURE PRIMITIVES
  178. =========================
  179.  
  180. CONSTRUCTORS
  181. ------------
  182.  
  183. WORD word1 word2
  184. (WORD word1 word2 word3 ...)
  185.  
  186.     outputs a word formed by concatenating its inputs.
  187.  
  188. LIST thing1 thing2
  189. (LIST thing1 thing2 thing3 ...)
  190.  
  191.     outputs a list whose members are its inputs, which can be any
  192.     Logo object (word, list, or array).
  193.  
  194. SENTENCE thing1 thing2
  195. SE thing1 thing2
  196. (SENTENCE thing1 thing2 thing3 ...)
  197. (SE thing1 thing2 thing3 ...)
  198.  
  199.     outputs a list whose members are its inputs, if those inputs are
  200.     not lists, or the members of its inputs, if those inputs are lists.
  201.  
  202. FPUT thing list
  203.  
  204.     outputs a list equal to its second input with one extra member,
  205.     the first input, at the beginning.
  206.  
  207. LPUT thing list
  208.  
  209.     outputs a list equal to its second input with one extra member,
  210.     the first input, at the end.
  211.  
  212. ARRAY size
  213. (ARRAY size origin)
  214.  
  215.     outputs an array of "size" elements (must be a positive integer),
  216.     each of which initially is an empty list.  Array elements can be
  217.     selected with ITEM and changed with SETITEM.  The first element of
  218.     the array is element number 1 unless an "origin" input (must be an
  219.     integer) is given, in which case the first element of the array has
  220.     that number as its index.  (Typically 0 is used as the origin if
  221.     anything.)  Arrays are printed by PRINT and friends, and can be
  222.     typed in, inside curly braces; indicate an origin with {a b c}@0.
  223.  
  224. MDARRAY sizelist                    (library procedure)
  225. (MDARRAY sizelist origin)
  226.  
  227.     outputs a multi-dimensional array.  The first input must be a list
  228.     of one or more positive integers.  The second input, if present,
  229.     must be a single integer that applies to every dimension of the array.
  230.     Ex: (MDARRAY [3 5] 0) outputs a two-dimensional array whose elements
  231.     range from [0 0] to [2 4].
  232.  
  233. LISTTOARRAY list                    (library procedure)
  234. (LISTTOARRAY list origin)
  235.  
  236.     outputs an array of the same size as the input list, whose elements
  237.     are the members of the input list.
  238.  
  239. ARRAYTOLIST array                    (library procedure)
  240.  
  241.     outputs a list whose members are the elements of the input array.
  242.     The first member of the output is the first element of the array,
  243.     regardless of the array's origin.
  244.  
  245. COMBINE thing1 thing2                    (library procedure)
  246.  
  247.     if thing2 is a word, outputs WORD thing1 thing2.  If thing2 is a list,
  248.     outputs FPUT thing1 thing2.
  249.  
  250. REVERSE list                        (library procedure)
  251.  
  252.     outputs a list whose members are the members of the input list, in
  253.     reverse order.
  254.  
  255. GENSYM                            (library procedure)
  256.  
  257.     outputs a unique word each time it's invoked.  The words are of the
  258.     form G1, G2, etc.
  259.  
  260.  
  261. SELECTORS
  262. ---------
  263.  
  264. FIRST thing
  265.  
  266.     if the input is a word, outputs the first character of the word.
  267.     If the input is a list, outputs the first member of the list.
  268.     If the input is an array, outputs the origin of the array (that
  269.     is, the INDEX OF the first element of the array).
  270.  
  271. FIRSTS list
  272.  
  273.     outputs a list containing the FIRST of each member of the input
  274.     list.  It is an error if any member of the input list is empty.
  275.     (The input itself may be empty, in which case the output is also
  276.     empty.)  This could be written as
  277.  
  278.         to firsts :list
  279.         output map "first :list
  280.         end
  281.  
  282.     but is provided as a primitive in order to speed up the iteration
  283.     tools MAP, MAP.SE, and FOREACH.
  284.  
  285.         to transpose :matrix
  286.         if emptyp first :matrix [op []]
  287.         op fput firsts :matrix transpose bfs :matrix
  288.         end
  289.  
  290. LAST wordorlist
  291.  
  292.     if the input is a word, outputs the last character of the word.
  293.     If the input is a list, outputs the last member of the list.
  294.  
  295. BUTFIRST wordorlist
  296. BF wordorlist
  297.  
  298.     if the input is a word, outputs a word containing all but the first
  299.     character of the input.  If the input is a list, outputs a list
  300.     containing all but the first member of the input.
  301.  
  302. BUTFIRSTS list
  303. BFS list
  304.  
  305.     outputs a list containing the BUTFIRST of each member of the input
  306.     list.  It is an error if any member of the input list is empty or an
  307.     array.  (The input itself may be empty, in which case the output is
  308.     also empty.)  This could be written as
  309.  
  310.         to butfirsts :list
  311.         output map "butfirst :list
  312.         end
  313.  
  314.     but is provided as a primitive in order to speed up the iteration
  315.     tools MAP, MAP.SE, and FOREACH.
  316.  
  317. BUTLAST wordorlist
  318. BL wordorlist
  319.  
  320.     if the input is a word, outputs a word containing all but the last
  321.     character of the input.  If the input is a list, outputs a list
  322.     containing all but the last member of the input.
  323.  
  324. ITEM index thing
  325.  
  326.     if the "thing" is a word, outputs the "index"th character of the
  327.     word.  If the "thing" is a list, outputs the "index"th member of
  328.     the list.  If the "thing" is an array, outputs the "index"th
  329.     element of the array.  "Index" starts at 1 for words and lists;
  330.     the starting index of an array is specified when the array is
  331.     created.
  332.  
  333. MDITEM indexlist array                    (library procedure)
  334.  
  335.     outputs the element of the multidimensional "array" selected by
  336.     the list of numbers "indexlist".
  337.  
  338. PICK list                        (library procedure)
  339.  
  340.     outputs a randomly chosen member of the input list.
  341.  
  342. REMOVE thing list                    (library procedure)
  343.  
  344.     outputs a copy of "list" with every member equal to "thing" removed.
  345.  
  346. REMDUP list                        (library procedure)
  347.  
  348.     outputs a copy of "list" with duplicate members removed.  If two or
  349.     more members of the input are equal, the rightmost of those members
  350.     is the one that remains in the output.
  351.  
  352. QUOTED thing                        (library procedure)
  353.  
  354.     outputs its input, if a list; outputs its input with a quotation
  355.     mark prepended, if a word.
  356.  
  357.  
  358. MUTATORS
  359. --------
  360.  
  361. SETITEM index array value
  362.  
  363.     command.  Replaces the "index"th element of "array" with the new
  364.     "value".  Ensures that the resulting array is not circular, i.e.,
  365.     "value" may not be a list or array that contains "array".
  366.  
  367. MDSETITEM indexlist array value                (library procedure)
  368.  
  369.     command.  Replaces the element of "array" chosen by "indexlist"
  370.     with the new "value".
  371.  
  372. .SETFIRST list value
  373.  
  374.     command.  Changes the first member of "list" to be "value".
  375.     WARNING: Primitives whose names start with a period are DANGEROUS.
  376.     Their use by non-experts is not recommended.  The use of .SETFIRST
  377.     can lead to circular list structures, which will get some Logo
  378.     primitives into infinite loops; unexpected changes to other data
  379.     structures that share storage with the list being modified; and
  380.     the permanent loss of memory if a circular structure is released.
  381.  
  382. .SETBF list value
  383.  
  384.     command.  Changes the butfirst of "list" to be "value".
  385.     WARNING: Primitives whose names start with a period are DANGEROUS.
  386.     Their use by non-experts is not recommended.  The use of .SETBF
  387.     can lead to circular list structures, which will get some Logo
  388.     primitives into infinite loops; unexpected changes to other data
  389.     structures that share storage with the list being modified; Logo
  390.     crashes and coredumps if the butfirst of a list is not itself a list;
  391.     and the permanent loss of memory if a circular structure is released.
  392.  
  393. .SETITEM index array value
  394.  
  395.     command.  Changes the "index"th element of "array" to be "value",
  396.     like SETITEM, but without checking for circularity.
  397.     WARNING: Primitives whose names start with a period are DANGEROUS.
  398.     Their use by non-experts is not recommended.  The use of .SETITEM
  399.     can lead to circular arrays, which will get some Logo primitives into
  400.     infinite loops; and the permanent loss of memory if a circular
  401.     structure is released.
  402.  
  403. PUSH stackname thing                    (library procedure)
  404.  
  405.     command.  Adds the "thing" to the stack that is the value of the
  406.     variable whose name is "stackname".  This variable must have a list
  407.     as its value; the initial value should be the empty list.  New
  408.     members are added at the front of the list.
  409.  
  410. POP stackname                        (library procedure)
  411.  
  412.     outputs the most recently PUSHed member of the stack that is the
  413.     value of the variable whose name is "stackname" and removes that
  414.     member from the stack.
  415.  
  416. QUEUE queuename thing                    (library procedure)
  417.  
  418.     command.  Adds the "thing" to the queue that is the value of the
  419.     variable whose name is "queuename".  This variable must have a list
  420.     as its value; the initial value should be the empty list.  New
  421.     members are added at the back of the list.
  422.  
  423. DEQUEUE queuename                    (library procedure)
  424.  
  425.     outputs the least recently QUEUEd member of the queue that is the
  426.     value of the variable whose name is "queuename" and removes that
  427.     member from the queue.
  428.  
  429.  
  430. PREDICATES
  431. ----------
  432.  
  433. WORDP thing
  434.  
  435.     outputs TRUE if the input is a word, FALSE otherwise.
  436.  
  437. LISTP thing
  438.  
  439.     outputs TRUE if the input is a list, FALSE otherwise.
  440.  
  441. ARRAYP thing
  442.  
  443.     outputs TRUE if the input is an array, FALSE otherwise.
  444.  
  445. EMPTYP thing
  446.  
  447.     outputs TRUE if the input is the empty word or the empty list,
  448.     FALSE otherwise.
  449.  
  450. EQUALP thing1 thing2
  451.  
  452.     outputs TRUE if the inputs are equal, FALSE otherwise.  Two numbers
  453.     are equal if they have the same numeric value.  Two non-numeric words
  454.     are equal if they contain the same characters in the same order.  If
  455.     there is a variable named CASEIGNOREDP whose value is TRUE, then an
  456.     upper case letter is considered the same as the corresponding lower
  457.     case letter.  (This is the case by default.)  Two lists are equal if
  458.     their members are equal.  An array is only equal to itself; two
  459.     separately created arrays are never equal even if their elements are
  460.     equal.  (It is important to be able to know if two expressions have
  461.     the same array as their value because arrays are mutable; if, for
  462.     example, two variables have the same array as their values then
  463.     performing SETITEM on one of them will also change the other.)
  464.  
  465. BEFOREP word1 word2
  466.  
  467.     outputs TRUE if word1 comes before word2 in ASCII collating sequence
  468.     (for words of letters, in alphabetical order).  Case-sensitivity is
  469.     determined by the value of CASEIGNOREDP.  Note that if the inputs are
  470.     numbers, the result may not be the same as with LESSP; for example,
  471.     BEFOREP 3 12 is false because 3 collates before 1.
  472.  
  473. .EQ thing1 thing2
  474.  
  475.     outputs TRUE if its two inputs are the same object, so that applying a
  476.     mutator to one will change the other as well.  Outputs FALSE otherwise,
  477.     even if the inputs are equal in value.
  478.     WARNING: Primitives whose names start with a period are DANGEROUS.
  479.     Their use by non-experts is not recommended.  The use of mutators
  480.     can lead to circular data structures, infinite loops, or Logo crashes.
  481.  
  482. MEMBERP thing1 thing2
  483.  
  484.     if "thing2" is a list or an array, outputs TRUE if "thing1" is EQUALP
  485.     to a member or element of "thing2", FALSE otherwise.  If "thing2" is
  486.     a word, outputs TRUE if "thing1" is EQUALP to a substring of "thing2",
  487.     FALSE otherwise.  Note that this behavior for words is different from
  488.     other dialects, in which "thing1" must be a single character in order
  489.     to make MEMBERP true with "thing2" a word.
  490.  
  491. NUMBERP thing
  492.  
  493.     outputs TRUE if the input is a number, FALSE otherwise.
  494.  
  495. BACKSLASHEDP char
  496.  
  497.     outputs TRUE if the input character was originally entered into Logo
  498.     with a backslash (\) before it to prevent special syntactic meaning,
  499.     FALSE otherwise.  (In Europe, outputs TRUE only if the character is
  500.     a backslashed space, tab, newline, or one of ()[]+-*/=<>":;\~? )
  501.  
  502.  
  503. QUERIES
  504. -------
  505.  
  506. COUNT thing
  507.  
  508.     outputs the number of characters in the input, if the input is a word;
  509.     outputs the number of members or elements in the input, if it is a list
  510.     or an array.  (For an array, this may or may not be the index of the
  511.     last element, depending on the array's origin.)
  512.  
  513. ASCII char
  514.  
  515.     outputs the integer (in the United States, between 0 and 127) that
  516.     represents the input character in the ASCII code.
  517.  
  518. CHAR int
  519.  
  520.     outputs the character represented in the ASCII code by the input,
  521.     which must be an integer between 0 and 127.
  522.  
  523. MEMBER thing1 thing2
  524.  
  525.     if "thing2" is a word or list and if MEMBERP with these inputs would
  526.     output TRUE, outputs the portion of "thing2" from the first instance
  527.     of "thing1" to the end.  If MEMBERP would output FALSE, outputs the
  528.     empty word or list according to the type of "thing2".  It is an error
  529.     for "thing2" to be an array.
  530.  
  531. LOWERCASE word
  532.  
  533.     outputs a copy of the input word, but with all uppercase letters
  534.     changed to the corresponding lowercase letter.  (In the United
  535.     States, letters that were initially read by Logo preceded by a
  536.     backslash are immune to this conversion.)
  537.  
  538. UPPERCASE word
  539.  
  540.     outputs a copy of the input word, but with all lowercase letters
  541.     changed to the corresponding uppercase letter.  (In the United
  542.     States, letters that were initially read by Logo preceded by a
  543.     backslash are immune to this conversion.)
  544.  
  545. STANDOUT thing
  546.  
  547.     outputs a word that, when printed, will appear like the input but
  548.     displayed in standout mode (boldface, reverse video, or whatever your
  549.     terminal does for standout).  The word contains terminal-specific
  550.     magic characters at the beginning and end; in between is the printed
  551.     form (as if displayed using TYPE) of the input.  The output is always
  552.     a word, even if the input is of some other type, but it may include
  553.     spaces and other formatting characters.  Note: a word output by
  554.     STANDOUT while Logo is running on one terminal will probably not have
  555.     the desired effect if printed on another type of terminal.
  556.  
  557. PARSE word
  558.  
  559.     outputs the list that would result if the input word were entered
  560.     in response to a READLIST operation.  That is, PARSE READWORD has
  561.     the same value as READLIST for the same characters read.
  562.  
  563. RUNPARSE wordorlist
  564.  
  565.     outputs the list that would result if the input word or list were
  566.     entered as an instruction line; characters such as infix operators
  567.     and parentheses are separate members of the output.  Note that
  568.     sublists of a runparsed list are not themselves runparsed.
  569.  
  570.  
  571. COMMUNICATION
  572. =============
  573.  
  574. TRANSMITTERS
  575. ------------
  576.  
  577. Note:  If there is a variable named PRINTDEPTHLIMIT with a nonnegative
  578. integer value, then complex list and array structures will be printed
  579. only to the allowed depth.  That is, members of members of... of members
  580. will be allowed only so far.  The elements or members omitted because
  581. they are just past the depth limit are indicated by an ellipsis for each
  582. one, so a too-deep list of two elements will print as [... ...].
  583.  
  584. If there is a variable named PRINTWIDTHLIMIT with a nonnegative integer
  585. value, then only the first so many elements or members of any array or
  586. list will be printed.  A single ellipsis replaces all missing objects
  587. within the structure.  The width limit also applies to the number of
  588. characters printed in a word, except that a PRINTWIDTHLIMIT between 0 and 9
  589. will be treated as if it were 10 when applied to words.  This limit
  590. applies not only to the top-level printed object but to any substructures
  591. within it.
  592.  
  593. PRINT thing
  594. PR thing
  595. (PRINT thing1 thing2 ...)
  596. (PR thing1 thing2 ...)
  597.  
  598.     command.  Prints the input or inputs to the current write stream
  599.     (initially the terminal).  All the inputs are printed on a single
  600.     line, separated by spaces, ending with a newline.  If an input is a
  601.     list, square brackets are not printed around it, but brackets are
  602.     printed around sublists.  Braces are always printed around arrays.
  603.  
  604. TYPE thing
  605. (TYPE thing1 thing2 ...)
  606.  
  607.     command.  Prints the input or inputs like PRINT, except that no
  608.     newline character is printed at the end and multiple inputs are not
  609.     separated by spaces.  Note: printing to the terminal is ordinarily
  610.     "line buffered"; that is, the characters you print using TYPE will
  611.     not actually appear on the screen until either a newline character
  612.     is printed (for example, by PRINT or SHOW) or Logo tries to read
  613.     from the keyboard (either at the request of your program or after an
  614.     instruction prompt).  This buffering makes the program much faster
  615.     than it would be if each character appeared immediately, and in most
  616.     cases the effect is not disconcerting.  To accommodate programs that
  617.     do a lot of positioned text display using TYPE, Logo will force
  618.     printing whenever SETCURSOR is invoked.  This solves most buffering
  619.     problems.  Still, on occasion you may find it necessary to force the
  620.     buffered characters to be printed explicitly; this can be done using
  621.     the WAIT command.  WAIT 0 will force printing without actually
  622.     waiting.
  623.  
  624. SHOW thing
  625. (SHOW thing1 thing2 ...)
  626.  
  627.     command.  Prints the input or inputs like PRINT, except that
  628.     if an input is a list it is printed inside square brackets.
  629.  
  630.  
  631. RECEIVERS
  632. ---------
  633.  
  634. READLIST
  635. RL
  636.  
  637.     reads a line from the read stream (initially the terminal) and
  638.     outputs that line as a list.  The line is separated into elements as
  639.     though it were typed in square brackets in an instruction.  If the
  640.     read stream is a file, and the end of file is reached, READLIST
  641.     outputs the empty word (not the empty list).  READLIST processes
  642.     backslash, vertical bar, and tilde characters in the read stream;
  643.     the output list will not contain these characters but they will have
  644.     had their usual effect.  READLIST does not, however, treat semicolon
  645.     as a comment character.
  646.  
  647. READWORD
  648. RW
  649.  
  650.     reads a line from the read stream and outputs that line as a word.
  651.     The output is a single word even if the line contains spaces,
  652.     brackets, etc.  If the read stream is a file, and the end of file is
  653.     reached, READWORD outputs the empty list (not the empty word).
  654.     READWORD processes backslash, vertical bar, and tilde characters in
  655.     the read stream.  In the case of a tilde used for line continuation,
  656.     the output word DOES include the tilde and the newline characters, so
  657.     that the user program can tell exactly what the user entered.
  658.     Vertical bars in the line are also preserved in the output.
  659.     Backslash characters are not preserved in the output, but the
  660.     character following the backslash has 128 added to its
  661.     representation.  Programs can use BACKSLASHEDP to check for this
  662.     code.  (In Europe, backslashedness is preserved only for certain
  663.     characters.  See BACKSLASHEDP.)
  664.  
  665. READCHAR
  666. RC
  667.  
  668.     reads a single character from the read stream and outputs that
  669.     character as a word.  If the read stream is a file, and the end of
  670.     file is reached, READCHAR outputs the empty list (not the empty
  671.     word).  If the read stream is a terminal, echoing is turned off
  672.     when READCHAR is invoked, and remains off until READLIST or READWORD
  673.     is invoked or a Logo prompt is printed.  Backslash, vertical bar,
  674.     and tilde characters have no special meaning in this context.
  675.  
  676. READCHARS num
  677. RCS num
  678.  
  679.     reads "num" characters from the read stream and outputs those
  680.     characters as a word.  If the read stream is a file, and the end of
  681.     file is reached, READCHARS outputs the empty list (not the empty
  682.     word).  If the read stream is a terminal, echoing is turned off
  683.     when READCHARS is invoked, and remains off until READLIST or READWORD
  684.     is invoked or a Logo prompt is printed.  Backslash, vertical bar,
  685.     and tilde characters have no special meaning in this context.
  686.  
  687. SHELL command
  688. (SHELL command wordflag)
  689.  
  690.     Under Unix, outputs the result of running "command" as a shell
  691.     command.  (The command is sent to /bin/sh, not csh or other
  692.     alternatives.)  If the command is a literal list in the instruction
  693.     line, and if you want a backslash character sent to the shell, you
  694.     must use \\ to get the backslash through Logo's reader intact.  The
  695.     output is a list containing one member for each line generated by
  696.     the shell command.  Ordinarily each such line is represented by a
  697.     list in the output, as though the line were read using READLIST.  If
  698.     a second input is given, regardless of the value of the input, each
  699.     line is represented by a word in the output as though it were read
  700.     with READWORD.  Example:
  701.  
  702.             to dayofweek
  703.             output first first shell [date]
  704.             end
  705.  
  706.     This is "first first" to extract the first word of the first (and
  707.     only) line of the shell output.
  708.  
  709.     Under DOS, SHELL is a command, not an operation; it sends its
  710.     input to a DOS command processor but does not collect the result
  711.     of the command.
  712.  
  713.     The Macintosh, of course, is not programmable.
  714.  
  715.  
  716. FILE ACCESS
  717. -----------
  718.  
  719. OPENREAD filename
  720.  
  721.     command.  Opens the named file for reading.  The read position is
  722.     initially at the beginning of the file.
  723.  
  724. OPENWRITE filename
  725.  
  726.     command.  Opens the named file for writing.  If the file already
  727.     existed, the old version is deleted and a new, empty file created.
  728.  
  729. OPENAPPEND filename
  730.  
  731.     command.  Opens the named file for writing.  If the file already
  732.     exists, the write position is initially set to the end of the old
  733.     file, so that newly written data will be appended to it.
  734.  
  735. OPENUPDATE filename
  736.  
  737.     command.  Opens the named file for reading and writing.  The read and
  738.     write position is initially set to the end of the old file, if any.
  739.     Note: each open file has only one position, for both reading and
  740.     writing.  If a file opened for update is both READER and WRITER at
  741.     the same time, then SETREADPOS will also affect WRITEPOS and vice
  742.     versa.  Also, if you alternate reading and writing the same file,
  743.     you must SETREADPOS between a write and a read, and SETWRITEPOS
  744.     between a read and a write.
  745.  
  746. CLOSE filename
  747.  
  748.     command.  Closes the named file.
  749.  
  750. ALLOPEN
  751.  
  752.     outputs a list whose members are the names of all files currently open.
  753.     This list does not include the dribble file, if any.
  754.  
  755. CLOSEALL                        (library procedure)
  756.  
  757.     command.  Closes all open files.  Abbreviates
  758.     FOREACH ALLOPEN [CLOSE ?]
  759.  
  760. ERASEFILE filename
  761. ERF filename
  762.  
  763.     command.  Erases (deletes, removes) the named file, which should not
  764.     currently be open.
  765.  
  766. DRIBBLE filename
  767.  
  768.     command.  Creates a new file whose name is the input, like OPENWRITE,
  769.     and begins recording in that file everything that is read from the
  770.     keyboard or written to the terminal.  That is, this writing is in
  771.     addition to the writing to WRITER.  The intent is to create a
  772.     transcript of a Logo session, including things like prompt
  773.     characters and interactions.
  774.  
  775. NODRIBBLE
  776.  
  777.     command.  Stops copying information into the dribble file, and
  778.     closes the file.
  779.  
  780. SETREAD filename
  781.  
  782.     command.  Makes the named file the read stream, used for READLIST,
  783.     etc.  The file must already be open with OPENREAD or OPENUPDATE.  If
  784.     the input is the empty list, then the read stream becomes the
  785.     terminal, as usual.  Changing the read stream does not close the
  786.     file that was previously the read stream, so it is possible to
  787.     alternate between files.
  788.  
  789. SETWRITE filename
  790.  
  791.     command.  Makes the named file the write stream, used for PRINT,
  792.     etc.  The file must already be open with OPENWRITE, OPENAPPEND, or
  793.     OPENUPDATE.  If the input is the empty list, then the write stream
  794.     becomes the terminal, as usual.  Changing the write stream does not
  795.     close the file that was previously the write stream, so it is
  796.     possible to alternate between files.
  797.  
  798. READER
  799.  
  800.     outputs the name of the current read stream file, or the empty list
  801.     if the read stream is the terminal.
  802.  
  803. WRITER
  804.  
  805.     outputs the name of the current write stream file, or the empty list
  806.     if the write stream is the terminal.
  807.  
  808. SETREADPOS charpos
  809.  
  810.     command.  Sets the file pointer of the read stream file so that the
  811.     next READLIST, etc., will begin reading at the "charpos"th character
  812.     in the file, counting from 0.  (That is, SETREADPOS 0 will start
  813.     reading from the beginning of the file.)  Meaningless if the read
  814.     stream is the terminal.
  815.  
  816. SETWRITEPOS charpos
  817.  
  818.     command.  Sets the file pointer of the write stream file so that the
  819.     next PRINT, etc., will begin writing at the "charpos"th character
  820.     in the file, counting from 0.  (That is, SETWRITEPOS 0 will start
  821.     writing from the beginning of the file.)  Meaningless if the write
  822.     stream is the terminal.
  823.  
  824. READPOS
  825.  
  826.     outputs the file position of the current read stream file.
  827.  
  828. WRITEPOS
  829.  
  830.     outputs the file position of the current write stream file.
  831.  
  832. EOFP
  833.  
  834.     predicate, outputs TRUE if there are no more characters to be
  835.     read in the read stream file, FALSE otherwise.
  836.  
  837.  
  838. TERMINAL ACCESS
  839. ---------------
  840.  
  841. KEYP
  842.  
  843.     predicate, outputs TRUE if there are characters waiting to be
  844.     read from the read stream.  If the read stream is a file, this
  845.     is equivalent to NOT EOFP.  If the read stream is the terminal,
  846.     then echoing is turned off and the terminal is set to CBREAK
  847.     (character at a time instead of line at a time) mode.  It
  848.     remains in this mode until some line-mode reading is requested
  849.     (e.g., READLIST).  The Unix operating system forgets about any
  850.     pending characters when it switches modes, so the first KEYP
  851.     invocation will always output FALSE.
  852.  
  853. CLEARTEXT
  854. CT
  855.  
  856.     command.  Clears the text screen of the terminal.
  857.  
  858. SETCURSOR vector
  859.  
  860.     command.  The input is a list of two numbers, the x and y
  861.     coordinates of a screen position (origin in the upper left
  862.     corner, positive direction is southeast).  The screen cursor
  863.     is moved to the requested position.  This command also forces
  864.     the immediate printing of any buffered characters.
  865.  
  866. CURSOR
  867.  
  868.     outputs a list containing the current x and y coordinates of
  869.     the screen cursor.  Logo may get confused about the current
  870.     cursor position if, e.g., you type in a long line that wraps
  871.     around or your program prints escape codes that affect the
  872.     terminal strangely.
  873.  
  874. SETMARGINS vector
  875.  
  876.     command.  The input must be a list of two numbers, as for
  877.     SETCURSOR.  The effect is to clear the screen and then arrange for
  878.     all further printing to be shifted down and to the right according
  879.     to the indicated margins.  Specifically, every time a newline
  880.     character is printed (explicitly or implicitly) Logo will type
  881.     x_margin spaces, and on every invocation of SETCURSOR the margins
  882.     will be added to the input x and y coordinates.  (CURSOR will report
  883.     the cursor position relative to the margins, so that this shift will
  884.     be invisible to Logo programs.)  The purpose of this command is to
  885.     accommodate the display of terminal screens in lecture halls with
  886.     inadequate TV monitors that miss the top and left edges of the
  887.     screen.
  888.  
  889.  
  890. ARITHMETIC
  891. ==========
  892.  
  893. NUMERIC OPERATIONS
  894. ------------------
  895.  
  896. SUM num1 num2
  897. (SUM num1 num2 num3 ...)
  898. num1 + num2
  899.  
  900.     outputs the sum of its inputs.
  901.  
  902. DIFFERENCE num1 num2
  903. num1 - num2
  904.  
  905.     outputs the difference of its inputs.  Minus sign means infix
  906.     difference in ambiguous contexts (when preceded by a complete
  907.     expression), unless it is preceded by a space and followed
  908.     by a nonspace.
  909.  
  910. MINUS num
  911. - num
  912.  
  913.     outputs the negative of its input.  Minus sign means unary minus if
  914.     it is immediately preceded by something requiring an input, or
  915.     preceded by a space and followed by a nonspace.  There is a difference
  916.     in binding strength between the two forms:
  917.  
  918.         MINUS 3 + 4    means    -(3+4)
  919.         - 3 + 4        means    (-3)+4
  920.  
  921. PRODUCT num1 num2
  922. (PRODUCT num1 num2 num3 ...)
  923. num1 * num2
  924.  
  925.     outputs the product of its inputs.
  926.  
  927. QUOTIENT num1 num2
  928. (QUOTIENT num)
  929. num1 / num2
  930.  
  931.     outputs the quotient of its inputs.  The quotient of two integers
  932.     is an integer if and only if the dividend is a multiple of the divisor.
  933.     (In other words, QUOTIENT 5 2 is 2.5, not 2, but QUOTIENT 4 2 is
  934.     2, not 2.0 -- it does the right thing.)  With a single input,
  935.     QUOTIENT outputs the reciprocal of the input.
  936.  
  937. REMAINDER num1 num2
  938.  
  939.     outputs the remainder on dividing "num1" by "num2"; both must be
  940.     integers and the result is an integer with the same sign as num2.
  941.  
  942. INT num
  943.  
  944.     outputs its input with fractional part removed, i.e., an integer
  945.     with the same sign as the input, whose absolute value is the
  946.     largest integer less than or equal to the absolute value of
  947.     the input.
  948.  
  949.     Note:  Inside the computer numbers are represented in two different
  950.     forms, one for integers and one for numbers with fractional parts.
  951.     However, on most computers the largest number that can be represented
  952.     in integer format is smaller than the largest integer that can be
  953.     represented (even with exact precision) in floating-point (fraction)
  954.     format.  The INT operation will always output a number whose value
  955.     is mathematically an integer, but if its input is very large the output
  956.     may not be in integer format.  In that case, operations like REMAINDER
  957.     that require an integer input will not accept this number.
  958.  
  959. ROUND num
  960.  
  961.     outputs the nearest integer to the input.
  962.  
  963. SQRT num
  964.  
  965.     outputs the square root of the input, which must be nonnegative.
  966.  
  967. POWER num1 num2
  968.  
  969.     outputs "num1" to the "num2" power.  If num1 is negative, then
  970.     num2 must be an integer.
  971.  
  972. EXP num
  973.  
  974.     outputs e (2.718281828+) to the input power.
  975.  
  976. LOG10 num
  977.  
  978.     outputs the common logarithm of the input.
  979.  
  980. LN num
  981.  
  982.     outputs the natural logarithm of the input.
  983.  
  984. SIN degrees
  985.  
  986.     outputs the sine of its input, which is taken in degrees.
  987.  
  988. RADSIN radians
  989.  
  990.     outputs the sine of its input, which is taken in radians.
  991.  
  992. COS degrees
  993.  
  994.     outputs the cosine of its input, which is taken in degrees.
  995.  
  996. RADCOS radians
  997.  
  998.     outputs the cosine of its input, which is taken in radians.
  999.  
  1000. ARCTAN num
  1001. (ARCTAN x y)
  1002.  
  1003.     outputs the arctangent, in degrees, of its input.  With two
  1004.     inputs, outputs the arctangent of y/x, if x is nonzero, or
  1005.     90 or -90 depending on the sign of y, if x is zero.
  1006.  
  1007. RADARCTAN num
  1008. (RADARCTAN x y)
  1009.  
  1010.     outputs the arctangent, in radians, of its input.  With two
  1011.     inputs, outputs the arctangent of y/x, if x is nonzero, or
  1012.     pi/2 or -pi/2 depending on the sign of y, if x is zero.
  1013.  
  1014.     The expression 2*(RADARCTAN 0 1) can be used to get the
  1015.     value of pi.
  1016.  
  1017.  
  1018. PREDICATES
  1019. ----------
  1020.  
  1021. LESSP num1 num2
  1022. num1 < num2
  1023.  
  1024.     outputs TRUE if its first input is strictly less than its second.
  1025.  
  1026. GREATERP num1 num2
  1027. num1 > num2
  1028.  
  1029.     outputs TRUE if its first input is strictly greater than its second.
  1030.  
  1031.  
  1032. RANDOM NUMBERS
  1033. --------------
  1034.  
  1035. RANDOM num
  1036.  
  1037.     outputs a random nonnegative integer less than its input, which
  1038.     must be an integer.
  1039.  
  1040. RERANDOM
  1041. (RERANDOM seed)
  1042.  
  1043.     command.  Makes the results of RANDOM reproducible.  Ordinarily
  1044.     the sequence of random numbers is different each time Logo is
  1045.     used.  If you need the same sequence of pseudo-random numbers
  1046.     repeatedly, e.g. to debug a program, say RERANDOM before the
  1047.     first invocation of RANDOM.  If you need more than one repeatable
  1048.     sequence, you can give RERANDOM an integer input; each possible
  1049.     input selects a unique sequence of numbers.
  1050.  
  1051.  
  1052. PRINT FORMATTING
  1053. ----------------
  1054.  
  1055. FORM num width precision
  1056.  
  1057.     outputs a word containing a printable representation of "num",
  1058.     possibly preceded by spaces (and therefore not a number for
  1059.     purposes of performing arithmetic operations), with at least
  1060.     "width" characters, including exactly "precision" digits after
  1061.     the decimal point.  (If "precision" is 0 then there will be no
  1062.     decimal point in the output.)
  1063.  
  1064.     As a debugging feature, (FORM num -1 format) will print the
  1065.     floating point "num" according to the C printf "format", to allow
  1066.  
  1067.         to hex :num
  1068.         op form :num -1 "|%08X %08X|
  1069.         end
  1070.  
  1071.     to allow finding out the exact result of floating point operations.
  1072.     The precise format needed may be machine-dependent.
  1073.  
  1074.  
  1075. BITWISE OPERATIONS
  1076. ------------------
  1077.  
  1078. BITAND num1 num2
  1079. (BITAND num1 num2 num3 ...)
  1080.  
  1081.     outputs the bitwise AND of its inputs, which must be integers.
  1082.  
  1083. BITOR num1 num2
  1084. (BITOR num1 num2 num3 ...)
  1085.  
  1086.     outputs the bitwise OR of its inputs, which must be integers.
  1087.  
  1088. BITXOR num1 num2
  1089. (BITXOR num1 num2 num3 ...)
  1090.  
  1091.     outputs the bitwise EXCLUSIVE OR of its inputs, which must be
  1092.     integers.
  1093.  
  1094. BITNOT num
  1095.  
  1096.     outputs the bitwise NOT of its input, which must be an integer.
  1097.  
  1098. ASHIFT num1 num2
  1099.  
  1100.     outputs "num1" arithmetic-shifted to the left by "num2" bits.
  1101.     If num2 is negative, the shift is to the right with sign
  1102.     extension.  The inputs must be integers.
  1103.  
  1104. LSHIFT num1 num2
  1105.  
  1106.     outputs "num1" logical-shifted to the left by "num2" bits.
  1107.     If num2 is negative, the shift is to the right with zero fill.
  1108.     The inputs must be integers.
  1109.  
  1110.  
  1111. LOGICAL OPERATIONS
  1112. ==================
  1113.  
  1114. AND tf1 tf2
  1115. (AND tf1 tf2 tf3 ...)
  1116.  
  1117.     outputs TRUE if all inputs are TRUE, otherwise FALSE.  All inputs
  1118.     must be TRUE or FALSE.  (Comparison is case-insensitive regardless
  1119.     of the value of CASEIGNOREDP.  That is, "true" or "True" or "TRUE"
  1120.     are all the same.)
  1121.  
  1122. OR tf1 tf2
  1123. (OR tf1 tf2 tf3 ...)
  1124.  
  1125.     outputs TRUE if any input is TRUE, otherwise FALSE.  All inputs
  1126.     must be TRUE or FALSE.  (Comparison is case-insensitive regardless
  1127.     of the value of CASEIGNOREDP.  That is, "true" or "True" or "TRUE"
  1128.     are all the same.)
  1129.  
  1130. NOT tf
  1131.  
  1132.     outputs TRUE if the input is FALSE, and vice versa.
  1133.  
  1134.  
  1135. GRAPHICS
  1136. ========
  1137.  
  1138. Berkeley Logo provides traditional Logo turtle graphics with one turtle.
  1139. Multiple turtles, dynamic turtles, and collision detection are not supported.
  1140. This is the most hardware-dependent part of Logo; some features may exist
  1141. on some machines but not others.  Nevertheless, the goal has been to make
  1142. Logo programs as portable as possible, rather than to take fullest advantage
  1143. of the capabilities of each machine.  In particular, Logo attempts to scale
  1144. the screen so that turtle coordinates [-100 -100] and [100 100] fit on the
  1145. graphics window, and so that the aspect ratio is 1:1, although some PC screens
  1146. have nonstandard aspect ratios.
  1147.  
  1148. The center of the graphics window (which may or may not be the entire
  1149. screen, depending on the machine used) is turtle location [0 0].  Positive
  1150. X is to the right; positive Y is up.  Headings (angles) are measured in
  1151. degrees clockwise from the positive Y axis.  (This differs from the common
  1152. mathematical convention of measuring angles counterclockwise from the
  1153. positive X axis.)  The turtle is represented as an isoceles triangle; the
  1154. actual turtle position is at the midpoint of the base (the short side).
  1155.  
  1156. Colors are, of course, hardware-dependent.  However, Logo provides partial
  1157. hardware independence by interpreting color numbers 0 through 7 uniformly
  1158. on all computers:
  1159.  
  1160.     0  black        4  red
  1161.     1  blue            5  magenta
  1162.     2  green        6  yellow
  1163.     3  cyan            7  white
  1164.  
  1165. Color numbers greater than 7 are interpreted by sending the value color-8
  1166. to the underlying graphics system.  Logo begins with a black background
  1167. and white pen.
  1168.  
  1169.  
  1170. TURTLE MOTION
  1171. -------------
  1172.  
  1173. FORWARD dist
  1174. FD dist
  1175.  
  1176.     moves the turtle forward, in the direction that it's facing, by
  1177.     the specified distance (measured in turtle steps).
  1178.  
  1179. BACK dist
  1180. BK dist
  1181.  
  1182.     moves the turtle backward, i.e., exactly opposite to the direction
  1183.     that it's facing, by the specified distance.  (The heading of the
  1184.     turtle does not change.)
  1185.  
  1186. LEFT degrees
  1187. LT degrees
  1188.  
  1189.     turns the turtle counterclockwise by the specified angle, measured
  1190.     in degrees (1/360 of a circle).
  1191.  
  1192. RIGHT degrees
  1193. RT degrees
  1194.  
  1195.     turns the turtle clockwise by the specified angle, measured in
  1196.     degrees (1/360 of a circle).
  1197.  
  1198. SETPOS pos
  1199.  
  1200.     moves the turtle to an absolute screen position.  The argument
  1201.     is a list of two numbers, the X and Y coordinates.
  1202.  
  1203. SETXY xcor ycor
  1204.  
  1205.     moves the turtle to an absolute screen position.  The two
  1206.     arguments are numbers, the X and Y coordinates.
  1207.  
  1208. SETX xcor
  1209.  
  1210.     moves the turtle horizontally from its old position to a new
  1211.     absolute horizontal coordinate.  The argument is the new X
  1212.     coordinate.
  1213.  
  1214. SETY ycor
  1215.  
  1216.     moves the turtle vertically from its old position to a new
  1217.     absolute vertical coordinate.  The argument is the new Y
  1218.     coordinate.
  1219.  
  1220. HOME
  1221.  
  1222.     moves the turtle to the center of the screen.  Equivalent to
  1223.     SETPOS [0 0].
  1224.  
  1225. SETHEADING degrees
  1226. SETH degrees
  1227.  
  1228.     turns the turtle to a new absolute heading.  The argument is
  1229.     a number, the heading in degrees clockwise from the positive
  1230.     Y axis.
  1231.  
  1232. ARC angle radius
  1233.  
  1234.     draws an arc of a circle, with the turtle at the center, with the
  1235.     specified radius, starting at the turtle's heading and extending
  1236.     clockwise through the specified angle.  The turtle does not move.
  1237.  
  1238. TURTLE MOTION QUERIES
  1239. ---------------------
  1240.  
  1241. POS
  1242.  
  1243.     outputs the turtle's current position, as a list of two
  1244.     numbers, the X and Y coordinates.
  1245.  
  1246. XCOR                            (library procedure)
  1247.  
  1248.     outputs a number, the turtle's X coordinate.
  1249.  
  1250. YCOR                            (library procedure)
  1251.  
  1252.     outputs a number, the turtle's Y coordinate.
  1253.  
  1254. HEADING
  1255.  
  1256.     outputs a number, the turtle's heading in degrees.
  1257.  
  1258. TOWARDS pos
  1259.  
  1260.     outputs a number, the heading at which the turtle should be
  1261.     facing so that it would point from its current position to
  1262.     the position given as the argument.
  1263.  
  1264. SCRUNCH
  1265.  
  1266.     outputs a list containing two numbers, the X and Y scrunch
  1267.     factors, as used by SETSCRUNCH.  (But note that SETSCRUNCH
  1268.     takes two numbers as inputs, not one list of numbers.)
  1269.  
  1270.  
  1271. TURTLE AND WINDOW CONTROL
  1272. -------------------------
  1273.  
  1274. SHOWTURTLE
  1275. ST
  1276.  
  1277.     makes the turtle visible.
  1278.  
  1279. HIDETURTLE
  1280. HT
  1281.  
  1282.     makes the turtle invisible.  It's a good idea to do this while
  1283.     you're in the middle of a complicated drawing, because hiding
  1284.     the turtle speeds up the drawing substantially.
  1285.  
  1286. CLEAN
  1287.  
  1288.     erases all lines that the turtle has drawn on the graphics window.
  1289.     The turtle's state (position, heading, pen mode, etc.) is not
  1290.     changed.
  1291.  
  1292. CLEARSCREEN
  1293. CS
  1294.  
  1295.     erases the graphics window and sends the turtle to its initial
  1296.     position and heading.  Like HOME and CLEAN together.
  1297.  
  1298. WRAP
  1299.  
  1300.     tells the turtle to enter wrap mode:  From now on, if the turtle
  1301.     is asked to move past the boundary of the graphics window, it
  1302.     will "wrap around" and reappear at the opposite edge of the
  1303.     window.  The top edge wraps to the bottom edge, while the left
  1304.     edge wraps to the right edge.  (So the window is topologically
  1305.     equivalent to a torus.)  This is the turtle's initial mode.
  1306.     Compare WINDOW and FENCE.
  1307.  
  1308. WINDOW
  1309.  
  1310.     tells the turtle to enter window mode:  From now on, if the turtle
  1311.     is asked to move past the boundary of the graphics window, it
  1312.     will move offscreen.  The visible graphics window is considered
  1313.     as just part of an infinite graphics plane; the turtle can be
  1314.     anywhere on the plane.  (If you lose the turtle, HOME will bring
  1315.     it back to the center of the window.)  Compare WRAP and FENCE.
  1316.  
  1317. FENCE
  1318.  
  1319.     tells the turtle to enter fence mode:  From now on, if the turtle
  1320.     is asked to move past the boundary of the graphics window, it
  1321.     will move as far as it can and then stop at the edge with an
  1322.     "out of bounds" error message.  Compare WRAP and WINDOW.
  1323.  
  1324. FILL
  1325.  
  1326.     fills in a region of the graphics window containing the turtle
  1327.     and bounded by lines that have been drawn earlier.  This is not
  1328.     portable; it doesn't work for all machines, and may not work
  1329.     exactly the same way on different machines.
  1330.  
  1331. LABEL text
  1332.  
  1333.     takes a word or list as input, and prints the input on the
  1334.     graphics window, starting at the turtle's position.
  1335.  
  1336. TEXTSCREEN
  1337. TS
  1338.  
  1339.     rearranges the size and position of windows to maximize the
  1340.     space available in the text window (the window used for
  1341.     interaction with Logo).  The details differ among machines.
  1342.     Compare SPLITSCREEN and FULLSCREEN.
  1343.  
  1344. FULLSCREEN
  1345. FS
  1346.  
  1347.     rearranges the size and position of windows to maximize the space
  1348.     available in the graphics window.  The details differ among machines.
  1349.     Compare SPLITSCREEN and TEXTSCREEN.
  1350.  
  1351.     In the DOS version, switching from fullscreen to splitscreen loses
  1352.     the part of the picture that's hidden by the text window.  Also,
  1353.     since there must be a text window to allow printing (including the
  1354.     printing of the Logo prompt), Logo automatically switches from
  1355.     fullscreen to splitscreen whenever anything is printed.  [This design
  1356.     decision follows from the scarcity of memory, so that the extra memory
  1357.     to remember an invisible part of a drawing seems too expensive.]
  1358.  
  1359. SPLITSCREEN
  1360. SS
  1361.  
  1362.     rearranges the size and position of windows to allow some room for
  1363.     text interaction while also keeping most of the graphics window
  1364.     visible.  The details differ among machines.  Compare TEXTSCREEN
  1365.     and FULLSCREEN.
  1366.  
  1367. SETSCRUNCH xscale yscale
  1368.  
  1369.     adjusts the aspect ratio and scaling of the graphics display.
  1370.     After this command is used, all further turtle motion will be
  1371.     adjusted by multiplying the horizontal and vertical extent of
  1372.     the motion by the two numbers given as inputs.  For example,
  1373.     after the instruction "SETSCRUNCH 2 1" motion at a heading of
  1374.     45 degrees will move twice as far horizontally as vertically.
  1375.     If your squares don't come out square, try this.  (Alternatively,
  1376.     you can deliberately misadjust the aspect ratio to draw an ellipse.)
  1377.  
  1378.     For Unix machines and Macintoshes, both scale factors are initially 1.
  1379.     For DOS machines, the scale factors are initially set according to
  1380.     what the hardware claims the aspect ratio is, but the hardware
  1381.     sometimes lies.  In the UCBLOGO.EXE version, the values set by
  1382.     SETSCRUNCH are remembered in a file (called SCRUNCH.DAT) and are
  1383.     automatically put into effect when a Logo session begins.
  1384.  
  1385. REFRESH
  1386.  
  1387.     tells Logo to remember the turtle's motions so that they can be
  1388.     reconstructed in case the graphics window is overlayed.  The
  1389.     effectiveness of this command may depend on the machine used.
  1390.  
  1391. NOREFRESH
  1392.  
  1393.     tells Logo not to remember the turtle's motions.  This will make
  1394.     drawing faster, but prevents recovery if the window is overlayed.
  1395.  
  1396.  
  1397. TURTLE AND WINDOW QUERIES
  1398. -------------------------
  1399.  
  1400. SHOWNP
  1401.  
  1402.     outputs TRUE if the turtle is shown (visible), FALSE if the
  1403.     turtle is hidden.  See SHOWTURTLE and HIDETURTLE.
  1404.  
  1405. PEN AND BACKGROUND CONTROL
  1406. --------------------------
  1407.  
  1408. The turtle carries a pen that can draw pictures.  At any time the pen
  1409. can be UP (in which case moving the turtle does not change what's on the
  1410. graphics screen) or DOWN (in which case the turtle leaves a trace).
  1411. If the pen is down, it can operate in one of three modes: PAINT (so that it
  1412. draws lines when the turtle moves), ERASE (so that it erases any lines
  1413. that might have been drawn on or through that path earlier), or REVERSE
  1414. (so that it inverts the status of each point along the turtle's path).
  1415.  
  1416. PENDOWN
  1417. PD
  1418.  
  1419.     sets the pen's position to DOWN, without changing its mode.
  1420.  
  1421. PENUP
  1422. PU
  1423.  
  1424.     sets the pen's position to UP, without changing its mode.
  1425.  
  1426. PENPAINT
  1427. PPT
  1428.  
  1429.     sets the pen's position to DOWN and mode to PAINT.
  1430.  
  1431. PENERASE
  1432. PE
  1433.  
  1434.     sets the pen's position to DOWN and mode to ERASE.
  1435.  
  1436. PENREVERSE
  1437. PX
  1438.  
  1439.     sets the pen's position to DOWN and mode to REVERSE.
  1440.     (This may interact in hardware-dependent ways with use of color.)
  1441.  
  1442. SETPENCOLOR color
  1443. SETPC color
  1444. SETPENSIZE size
  1445. SETPENPATTERN pattern
  1446.  
  1447.     set hardware-dependent pen characteristics.  These commands are
  1448.     not guaranteed compatible between implementations on different
  1449.     machines.
  1450.  
  1451. SETPEN list                        (library procedure)
  1452.  
  1453.     sets the pen's position, mode, and hardware-dependent characteristics
  1454.     according to the information in the input list, which should be taken
  1455.     from an earlier invocation of PEN.
  1456.  
  1457. SETBACKGROUND color
  1458. SETBG color
  1459.  
  1460.     set the screen background color.
  1461.  
  1462.  
  1463. PEN QUERIES
  1464. -----------
  1465.  
  1466. PENDOWNP
  1467.  
  1468.     outputs TRUE if the pen is down, FALSE if it's up.
  1469.  
  1470. PENMODE
  1471.  
  1472.     outputs one of the words PAINT, ERASE, or REVERSE according to
  1473.     the current pen mode.
  1474.  
  1475. PENCOLOR
  1476. PENSIZE
  1477. PENPATTERN
  1478.  
  1479.     output hardware-specific pen information.
  1480.  
  1481. PEN                            (library procedure)
  1482.  
  1483.     outputs a list containing the pen's position, mode, and
  1484.     hardware-specific characteristics, for use by SETPEN.
  1485.  
  1486. BACKGROUND
  1487. BG
  1488.  
  1489.     outputs the graphics background color.
  1490.  
  1491.  
  1492.  
  1493. WORKSPACE MANAGEMENT
  1494. ====================
  1495.  
  1496. PROCEDURE DEFINITION
  1497. --------------------
  1498.  
  1499. TO procname :input1 :input2 ...                (special form)
  1500.  
  1501.     command.  Prepares Logo to accept a procedure definition.  The
  1502.     procedure will be named "procname" and there must not already
  1503.     be a procedure by that name.  The inputs will be called "input1"
  1504.     etc.  Any number of inputs are allowed, including none.  Names
  1505.     of procedures and inputs are case-insensitive.
  1506.  
  1507.     Unlike every other Logo procedure, TO takes as its inputs the
  1508.     actual words typed in the instruction line, as if they were
  1509.     all quoted, rather than the results of evaluating expressions
  1510.     to provide the inputs.  (That's what "special form" means.)
  1511.  
  1512.     This version of Logo allows variable numbers of inputs to a
  1513.     procedure.  Every procedure has a MINIMUM, DEFAULT, and MAXIMUM
  1514.     number of inputs.  (The latter can be infinite.)
  1515.  
  1516.     The MINIMUM number of inputs is the number of required inputs,
  1517.     which must come first.  A required input is indicated by the
  1518.  
  1519.             :inputname
  1520.  
  1521.     notation.
  1522.  
  1523.     After all the required inputs can be zero or more optional inputs,
  1524.     represented by the following notation:
  1525.  
  1526.             [:inputname default.value.expression]
  1527.  
  1528.     When the procedure is invoked, if actual inputs are not supplied
  1529.     for these optional inputs, the default value expressions are
  1530.     evaluated to set values for the corresponding input names.  The
  1531.     inputs are processed from left to right, so a default value
  1532.     expression can be based on earlier inputs.  Example:
  1533.  
  1534.             to proc :inlist [:startvalue first :inlist]
  1535.  
  1536.     If the procedure is invoked by saying
  1537.  
  1538.             proc [a b c]
  1539.  
  1540.     then the variable INLIST will have the value [A B C] and the
  1541.     variable STARTVALUE will have the value A.  If the procedure
  1542.     is invoked by saying
  1543.  
  1544.             (proc [a b c] "x)
  1545.  
  1546.     then INLIST will have the value [A B C] and STARTVALUE will
  1547.     have the value X.
  1548.  
  1549.     After all the required and optional input can come a single "rest"
  1550.     input, represented by the following notation:
  1551.  
  1552.             [:inputname]
  1553.  
  1554.     This is a rest input rather than an optional input because there
  1555.     is no default value expression.  There can be at most one rest
  1556.     input.  When the procedure is invoked, the value of this input
  1557.     will be a list containing all of the actual inputs provided that
  1558.     were not used for required or optional inputs.  Example:
  1559.  
  1560.             to proc :in1 [:in2 "foo] [:in3]
  1561.  
  1562.     If this procedure is invoked by saying
  1563.  
  1564.             proc "x
  1565.  
  1566.     then IN1 has the value X, IN2 has the value FOO, and IN3 has
  1567.     the value [] (the empty list).  If it's invoked by saying
  1568.  
  1569.             (proc "a "b "c "d)
  1570.  
  1571.     then IN1 has the value A, IN2 has the value B, and IN3 has the
  1572.     value [C D].
  1573.  
  1574.     The MAXIMUM number of inputs for a procedure is infinite if a
  1575.     rest input is given; otherwise, it is the number of required
  1576.     inputs plus the number of optional inputs.
  1577.  
  1578.     The DEFAULT number of inputs for a procedure, which is the number
  1579.     of inputs that it will accept if its invocation is not enclosed
  1580.     in parentheses, is ordinarily equal to the minimum number.  If
  1581.     you want a different default number you can indicate that by
  1582.     putting the desired default number as the last thing on the
  1583.     TO line.  example:
  1584.  
  1585.             to proc :in1 [:in2 "foo] [:in3] 3
  1586.  
  1587.     This procedure has a minimum of one input, a default of three
  1588.     inputs, and an infinite maximum.
  1589.  
  1590.     Logo responds to the TO command by entering procedure definition
  1591.     mode.  The prompt character changes from "?" to ">" and whatever
  1592.     instructions you type become part of the definition until you
  1593.     type a line containing only the word END.
  1594.  
  1595. DEFINE procname text
  1596.  
  1597.     command.  Defines a procedure with name "procname" and text "text".
  1598.     If there is already a procedure with the same name, the new
  1599.     definition replaces the old one.  The text input must be a list
  1600.     whose members are lists.  The first member is a list of inputs;
  1601.     it looks like a TO line but without the word TO, without the
  1602.     procedure name, and without the colons before input names.  In
  1603.     other words, the members of this first sublist are words for
  1604.     the names of required inputs and lists for the names of optional
  1605.     or rest inputs.  The remaining sublists of the text input make
  1606.     up the body of the procedure, with one sublist for each instruction
  1607.     line of the body.  (There is no END line in the text input.)
  1608.     It is an error to redefine a primitive procedure unless the variable
  1609.     REDEFP has the value TRUE.
  1610.  
  1611. TEXT procname
  1612.  
  1613.     outputs the text of the procedure named "procname" in the form
  1614.     expected by DEFINE: a list of lists, the first of which describes
  1615.     the inputs to the procedure and the rest of which are the lines of
  1616.     its body.  The text does not reflect formatting information used
  1617.     when the procedure was defined, such as continuation lines and
  1618.     extra spaces.
  1619.  
  1620. FULLTEXT procname
  1621.  
  1622.     outputs a representation of the procedure "procname" in which
  1623.     formatting information is preserved.  If the procedure was defined
  1624.     with TO, EDIT, or LOAD, then the output is a list of words.  Each
  1625.     word represents one entire line of the definition in the form
  1626.     output by READWORD, including extra spaces and continuation lines.
  1627.     The last element of the output represents the END line.  If the
  1628.     procedure was defined with DEFINE, then the output is a list of
  1629.     lists.  If these lists are printed, one per line, the result will
  1630.     look like a definition using TO.  Note: the output from FULLTEXT
  1631.     is not suitable for use as input to DEFINE!
  1632.  
  1633. COPYDEF newname oldname
  1634.  
  1635.     command.  Makes "newname" a procedure identical to "oldname".
  1636.     The latter may be a primitive.  If "newname" was already defined,
  1637.     its previous definition is lost.  If "newname" was already a
  1638.     primitive, the redefinition is not permitted unless the variable
  1639.     REDEFP has the value TRUE.  Definitions created by COPYDEF are
  1640.     not saved by SAVE; primitives are never saved, and user-defined
  1641.     procedures created by COPYDEF are buried.  (You are likely to be
  1642.     confused if you PO or POT a procedure defined with COPYDEF because
  1643.     its title line will contain the old name.  This is why it's buried.)
  1644.  
  1645.     Note: dialects of Logo differ as to the order of inputs to COPYDEF.
  1646.     This dialect uses "MAKE order," not "NAME order."
  1647.  
  1648.  
  1649. VARIABLE DEFINITION
  1650. -------------------
  1651.  
  1652. MAKE varname value
  1653.  
  1654.     command.  Assigns the value "value" to the variable named "varname",
  1655.     which must be a word.  Variable names are case-insensitive.  If a
  1656.     variable with the same name already exists, the value of that
  1657.     variable is changed.  If not, a new global variable is created.
  1658.  
  1659. NAME value varname                    (library procedure)
  1660.  
  1661.     command.  Same as MAKE but with the inputs in reverse order.
  1662.  
  1663. LOCAL varname
  1664. LOCAL varnamelist
  1665. (LOCAL varname1 varname2 ...)
  1666.  
  1667.     command.  Accepts as inputs one or more words, or a list of
  1668.     words.  A variable is created for each of these words, with
  1669.     that word as its name.  The variables are local to the
  1670.     currently running procedure.  Logo variables follow dynamic
  1671.     scope rules; a variable that is local to a procedure is
  1672.     available to any subprocedure invoked by that procedure.
  1673.     The variables created by LOCAL have no initial value; they
  1674.     must be assigned a value (e.g., with MAKE) before the procedure
  1675.     attempts to read their value.
  1676.  
  1677. THING varname
  1678. :quoted.varname
  1679.  
  1680.     outputs the value of the variable whose name is the input.
  1681.     If there is more than one such variable, the innermost local
  1682.     variable of that name is chosen.  The colon notation is an
  1683.     abbreviation not for THING but for the combination
  1684.  
  1685.                 thing "
  1686.  
  1687.     so that :FOO means THING "FOO.
  1688.  
  1689.  
  1690. PROPERTY LISTS
  1691. --------------
  1692.  
  1693. Note: Names of property lists are always case-insensitive.  Names of
  1694. individual properties are case-sensitive or case-insensitive depending
  1695. on the value of CASEIGNOREDP, which is TRUE by default.
  1696.  
  1697. PPROP plistname propname value
  1698.  
  1699.     command.  Adds a property to the "plistname" property list
  1700.     with name "propname" and value "value".
  1701.  
  1702. GPROP plistname propname
  1703.  
  1704.     outputs the value of the "propname" property in the "plistname"
  1705.     property list, or the empty list if there is no such property.
  1706.  
  1707. REMPROP plistname propname
  1708.  
  1709.     command.  Removes the property named "propname" from the
  1710.     property list named "plistname".
  1711.  
  1712. PLIST plistname
  1713.  
  1714.     outputs a list whose odd-numbered elements are the names, and
  1715.     whose even-numbered elements are the values, of the properties
  1716.     in the property list named "plistname".  The output is a copy
  1717.     of the actual property list; changing properties later will not
  1718.     magically change the list output by PLIST.
  1719.  
  1720.  
  1721. PREDICATES
  1722. ----------
  1723.  
  1724. PROCEDUREP name
  1725.  
  1726.     outputs TRUE if the input is the name of a procedure.
  1727.  
  1728. PRIMITIVEP name
  1729.  
  1730.     outputs TRUE if the input is the name of a primitive procedure
  1731.     (one built into Logo).  Note that some of the procedures
  1732.     described in this document are library procedures, not primitives.
  1733.  
  1734. DEFINEDP name
  1735.  
  1736.     outputs TRUE if the input is the name of a user-defined procedure,
  1737.     including a library procedure.  (However, Logo does not know about
  1738.     a library procedure until that procedure has been invoked.)
  1739.  
  1740. NAMEP name
  1741.  
  1742.     outputs TRUE if the input is the name of a variable.
  1743.  
  1744.  
  1745. QUERIES
  1746. -------
  1747.  
  1748. CONTENTS
  1749.  
  1750.     outputs a "contents list," i.e., a list of three lists containing
  1751.     names of defined procedures, variables, and property lists
  1752.     respectively.  This list includes all unburied named items in
  1753.     the workspace.
  1754.  
  1755. BURIED
  1756.  
  1757.     outputs a contents list including all buried named items in
  1758.     the workspace.
  1759.  
  1760. PROCEDURES
  1761.  
  1762.     outputs a list of the names of all unburied user-defined procedures
  1763.     in the workspace.  Note that this is a list of names, not a
  1764.     contents list.  (However, procedures that require a contents list
  1765.     as input will accept this list.)
  1766.  
  1767. NAMES
  1768.  
  1769.     outputs a contents list consisting of an empty list (indicating
  1770.     no procedure names) followed by a list of all unburied variable
  1771.     names in the workspace.
  1772.  
  1773. PLISTS
  1774.  
  1775.     outputs a contents list consisting of two empty lists (indicating
  1776.     no procedures or variables) followed by a list of all unburied
  1777.     property lists in the workspace.
  1778.  
  1779. NAMELIST varname                    (library procedure)
  1780. NAMELIST varnamelist
  1781.  
  1782.     outputs a contents list consisting of an empty list followed by
  1783.     a list of the name or names given as input.  This is useful in
  1784.     conjunction with workspace control procedures that require a contents
  1785.     list as input.
  1786.  
  1787. PLLIST plname                        (library procedure)
  1788. PLLIST plnamelist
  1789.  
  1790.     outputs a contents list consisting of two empty lists followed by
  1791.     a list of the name or names given as input.  This is useful in
  1792.     conjunction with workspace control procedures that require a contents
  1793.     list as input.
  1794.  
  1795.  
  1796. Note:  All procedures whose input is indicated as "contentslist" will
  1797. accept a single word (taken as a procedure name), a list of words (taken
  1798. as names of procedures), or a list of three lists as described under
  1799. CONTENTS above.
  1800.  
  1801.  
  1802. INSPECTION
  1803. ----------
  1804.  
  1805. PO contentslist
  1806.  
  1807.     command.  Prints to the write stream the definitions of all
  1808.     procedures, variables, and property lists named in the input
  1809.     contents list.
  1810.  
  1811. POALL                            (library procedure)
  1812.  
  1813.     command.  Prints all unburied definitions in the workspace.
  1814.     Abbreviates PO CONTENTS.
  1815.  
  1816. POPS                            (library procedure)
  1817.  
  1818.     command.  Prints the definitions of all unburied procedures in
  1819.     the workspace.  Abbreviates PO PROCEDURES.
  1820.  
  1821. PONS                            (library procedure)
  1822.  
  1823.     command.  Prints the definitions of all unburied variables in
  1824.     the workspace.  Abbreviates PO NAMES.
  1825.  
  1826. POPLS                            (library procedure)
  1827.  
  1828.     command.  Prints the contents of all unburied property lists in
  1829.     the workspace.  Abbreviates PO PLISTS.
  1830.  
  1831. PON varname                        (library procedure)
  1832. PON varnamelist
  1833.  
  1834.     command.  Prints the definitions of the named variable(s).
  1835.     Abbreviates PO NAMELIST varname(list).
  1836.  
  1837. POPL plname                        (library procedure)
  1838. POPL plnamelist
  1839.  
  1840.     command.  Prints the definitions of the named property list(s).
  1841.     Abbreviates PO PLLIST plname(list).
  1842.  
  1843. POT contentslist
  1844.  
  1845.     command.  Prints the title lines of the named procedures and
  1846.     the definitions of the named variables and property lists.
  1847.     For property lists, the entire list is shown on one line
  1848.     instead of as a series of PPROP instructions as in PO.
  1849.  
  1850. POTS                            (library procedure)
  1851.  
  1852.     command.  Prints the title lines of all unburied procedures
  1853.     in the workspace.  Abbreviates POT PROCEDURES.
  1854.  
  1855.  
  1856. WORKSPACE CONTROL
  1857. -----------------
  1858.  
  1859. ERASE contentslist
  1860. ER contentslist
  1861.  
  1862.     command.  Erases from the workspace the procedures, variables,
  1863.     and property lists named in the input.  Primitive procedures may
  1864.     not be erased unless the variable REDEFP has the value TRUE.
  1865.  
  1866. ERALL                            (library procedure)
  1867.  
  1868.     command.  Erases all unburied procedures, variables, and property
  1869.     lists from the workspace.  Abbreviates ERASE CONTENTS.
  1870.  
  1871. ERPS                            (library procedure)
  1872.  
  1873.     command.  Erases all unburied procedures from the workspace.
  1874.     Abbreviates ERASE PROCEDURES.
  1875.  
  1876. ERNS                            (library procedure)
  1877.  
  1878.     command.  Erases all unburied variables from the workspace.
  1879.     Abbreviates ERASE NAMES.
  1880.  
  1881. ERPLS                            (library procedure)
  1882.  
  1883.     command.  Erases all unburied property lists from the workspace.
  1884.     Abbreviates ERASE PLISTS.
  1885.  
  1886. ERN varname                        (library procedure)
  1887. ERN varnamelist
  1888.  
  1889.     command.  Erases from the workspace the variable(s) named in the
  1890.     input.  Abbreviates ERASE NAMELIST varname(list).
  1891.  
  1892. ERPL plname                        (library procedure)
  1893. ERPL plnamelist
  1894.  
  1895.     command.  Erases from the workspace the property list(s) named in the
  1896.     input.  Abbreviates ERASE PLLIST plname(list).
  1897.  
  1898. BURY contentslist
  1899.  
  1900.     command.  Buries the procedures, variables, and property lists
  1901.     named in the input.  A buried item is not included in the lists
  1902.     output by CONTENTS, PROCEDURES, VARIABLES, and PLISTS, but is
  1903.     included in the list output by BURIED.  By implication, buried
  1904.     things are not printed by POALL or saved by SAVE.
  1905.  
  1906. BURYALL                            (library procedure)
  1907.  
  1908.     command.  Abbreviates BURY CONTENTS.
  1909.  
  1910. BURYNAME varname                    (library procedure)
  1911. BURYNAME varnamelist
  1912.  
  1913.     command.  Abbreviates BURY NAMELIST varname(list).
  1914.  
  1915. UNBURY contentslist
  1916.  
  1917.     command.  Unburies the procedures, variables, and property lists
  1918.     named in the input.  That is, the named items will be returned to
  1919.     view in CONTENTS, etc.
  1920.  
  1921. UNBURYALL                        (library procedure)
  1922.  
  1923.     command.  Abbreviates UNBURY BURIED.
  1924.  
  1925. UNBURYNAME varname                    (library procedure)
  1926. UNBURYNAME varnamelist
  1927.  
  1928.     command.  Abbreviates UNBURY NAMELIST varname(list).
  1929.  
  1930. TRACE contentslist
  1931.  
  1932.     command.  Marks the named items for tracing.  A message is printed
  1933.     whenever a traced procedure is invoked, giving the actual input
  1934.     values, and whenever a traced procedure STOPs or OUTPUTs.  A
  1935.     message is printed whenever a new value is assigned to a traced
  1936.     variable using MAKE.  A message is printed whenever a new property
  1937.     is given to a traced property list using PPROP.
  1938.  
  1939. UNTRACE contentslist
  1940.  
  1941.     command.  Turns off tracing for the named items.
  1942.  
  1943. STEP contentslist
  1944.  
  1945.     command.  Marks the named items for stepping.  Whenever a stepped
  1946.     procedure is invoked, each instruction line in the procedure body
  1947.     is printed before being executed, and Logo waits for the user to
  1948.     type a newline at the terminal.  A message is printed whenever a
  1949.     stepped variable name is "shadowed" because a local variable of
  1950.     the same name is created either as a procedure input or by the
  1951.     LOCAL command.
  1952.  
  1953. UNSTEP contentslist
  1954.  
  1955.     command.  Turns off stepping for the named items.
  1956.  
  1957. EDIT contentslist
  1958. ED contentslist
  1959. (EDIT)
  1960. (ED)
  1961.  
  1962.     command.  Edits the definitions of the named items, using your
  1963.     favorite editor as determined by the EDITOR environment variable.
  1964.     If you don't have an EDITOR variable, edits the definitions using
  1965.     jove.  If invoked without an argument, EDIT edits the same
  1966.     temporary file left over from a previous EDIT instruction.
  1967.     When you leave the editor, Logo reads the revised definitions
  1968.     and modifies the workspace accordingly.
  1969.  
  1970.     Exceptionally, the EDIT command can be used without its default
  1971.     input and without parentheses provided that nothing follows it on
  1972.     the instruction line.
  1973.  
  1974. EDALL                            (library procedure)
  1975.  
  1976.     command.  Abbreviates EDIT CONTENTS.
  1977.  
  1978. EDPS                            (library procedure)
  1979.  
  1980.     command.  Abbreviates EDIT PROCEDURES.
  1981.  
  1982. EDNS                            (library procedure)
  1983.  
  1984.     command.  Abbreviates EDIT NAMES.
  1985.  
  1986. EDPLS                            (library procedure)
  1987.  
  1988.     command.  Abbreviates EDIT PLISTS.
  1989.  
  1990. EDN varname                        (library procedure)
  1991. EDN varnamelist
  1992.  
  1993.     command.  Abbreviates EDIT NAMELIST varname(list).
  1994.  
  1995. EDPL plname                        (library procedure)
  1996. EDPL plnamelist
  1997.  
  1998.     command.  Abbreviates EDIT PLLIST plname(list).
  1999.  
  2000. SAVE filename
  2001.  
  2002.     command.  Saves the definitions of all unburied procedures,
  2003.     variables, and property lists in the named file.  Equivalent to
  2004.  
  2005.             to save :filename
  2006.             local "oldwriter
  2007.             make "oldwriter writer
  2008.             openwrite :filename
  2009.             setwrite :filename
  2010.             poall
  2011.             setwrite :oldwriter
  2012.             close :filename
  2013.             end
  2014.  
  2015. SAVEL contentslist filename                (library procedure)
  2016.  
  2017.     command.  Saves the definitions of the procedures, variables, and
  2018.     property lists specified by "contentslist" to the file named
  2019.     "filename".
  2020.  
  2021. LOAD filename
  2022.  
  2023.     command.  Reads instructions from the named file and executes
  2024.     them.  The file can include procedure definitions with TO, and
  2025.     these are accepted even if a procedure by the same name already
  2026.     exists.  If the file assigns a list value to a variable named
  2027.     STARTUP, then that list is run as an instructionlist after the
  2028.     file is loaded.
  2029.  
  2030.  
  2031. CONTROL STRUCTURES
  2032. ==================
  2033.  
  2034. Note: in the following descriptions, an "instructionlist" can be a list
  2035. or a word.  In the latter case, the word is parsed into list form before
  2036. it is run.  Thus, RUN READWORD or RUN READLIST will work.  The former is
  2037. slightly preferable because it allows for a continued line (with ~) that
  2038. includes a comment (with ;) on the first line.
  2039.  
  2040. RUN instructionlist
  2041.  
  2042.     command or operation.  Runs the Logo instructions in the input
  2043.     list; outputs if the list contains an expression that outputs.
  2044.  
  2045. RUNRESULT instructionlist
  2046.  
  2047.     runs the instructions in the input; outputs an empty list if
  2048.     those instructions produce no output, or a list whose only
  2049.     member is the output from running the input instructionlist.
  2050.     Useful for inventing command-or-operation control structures:
  2051.  
  2052.         local "result
  2053.         make "result runresult [something]
  2054.         if emptyp :result [stop]
  2055.         output first :result
  2056.  
  2057. REPEAT num instructionlist
  2058.  
  2059.     command.  Runs the "instructionlist" repeatedly, "num" times.
  2060.  
  2061. IF tf instructionlist
  2062. (IF tf instructionlist1 instructionlist2)
  2063.  
  2064.     command.  If the first input has the value TRUE, then IF runs
  2065.     the second input.  If the first input has the value FALSE, then
  2066.     IF does nothing.  (If given a third input, IF acts like IFELSE,
  2067.     as described below.)  It is an error if the first input is not
  2068.     either TRUE or FALSE.
  2069.  
  2070.     For compatibility with earlier versions of Logo, if an IF
  2071.     instruction is not enclosed in parentheses, but the first thing
  2072.     on the instruction line after the second input expression is a
  2073.     literal list (i.e., a list in square brackets), the IF is
  2074.     treated as if it were IFELSE, but a warning message is given.
  2075.     If this aberrant IF appears in a procedure body, the warning is
  2076.     given only the first time the procedure is invoked in each Logo
  2077.     session.
  2078.  
  2079. IFELSE tf instructionlist1 instructionlist2
  2080.  
  2081.     command or operation.  If the first input has the value TRUE, then
  2082.     IFELSE runs the second input.  If the first input has the value FALSE,
  2083.     then IFELSE runs the third input.  IFELSE outputs a value if the
  2084.     instructionlist contains an expression that outputs a value.
  2085.  
  2086. TEST tf
  2087.  
  2088.     command.  Remembers its input, which must be TRUE or FALSE, for use
  2089.     by later IFTRUE or IFFALSE instructions.  The effect of TEST is local
  2090.     to the procedure in which it is used; any corresponding IFTRUE or
  2091.     IFFALSE must be in the same procedure or a subprocedure.
  2092.  
  2093. IFTRUE instructionlist
  2094. IFT instructionlist
  2095.  
  2096.     command.  Runs its input if the most recent TEST instruction had
  2097.     a TRUE input.  The TEST must have been in the same procedure or a
  2098.     superprocedure.
  2099.  
  2100. IFFALSE instructionlist
  2101. IFF instructionlist
  2102.  
  2103.     command.  Runs its input if the most recent TEST instruction had
  2104.     a FALSE input.  The TEST must have been in the same procedure or a
  2105.     superprocedure.
  2106.  
  2107. STOP
  2108.  
  2109.     command.  Ends the running of the procedure in which it appears.
  2110.     Control is returned to the context in which that procedure was
  2111.     invoked.  The stopped procedure does not output a value.
  2112.  
  2113. OUTPUT value
  2114.  
  2115.     command.  Ends the running of the procedure in which it appears.
  2116.     That procedure outputs the value "value" to the context in which
  2117.     it was invoked.  Don't be confused: OUTPUT itself is a command,
  2118.     but the procedure that invokes OUTPUT is an operation.
  2119.  
  2120. CATCH tag instructionlist
  2121.  
  2122.     command or operation.  Runs its second input.  Outputs if that
  2123.     instructionlist outputs.  If, while running the instructionlist,
  2124.     a THROW instruction is executed with a tag equal to the first
  2125.     input (case-insensitive comparison), then the running of the
  2126.     instructionlist is terminated immediately.  In this case the CATCH
  2127.     outputs if a value input is given to THROW.  The tag must be a word.
  2128.  
  2129.     If the tag is the word ERROR, then any error condition that arises
  2130.     during the running of the instructionlist has the effect of THROW
  2131.     "ERROR instead of printing an error message and returning to
  2132.     toplevel.  The CATCH does not output if an error is caught.  Also,
  2133.     during the running of the instructionlist, the variable ERRACT is
  2134.     temporarily unbound.  (If there is an error while ERRACT has a
  2135.     value, that value is taken as an instructionlist to be run after
  2136.     printing the error message.  Typically the value of ERRACT, if any,
  2137.     is the list [PAUSE].)
  2138.  
  2139. THROW tag
  2140. (THROW tag value)
  2141.  
  2142.     command.  Must be used within the scope of a CATCH with an equal
  2143.     tag.  Ends the running of the instructionlist of the CATCH.  If
  2144.     THROW is used with only one input, the corresponding CATCH does
  2145.     not output a value.  If THROW is used with two inputs, the second
  2146.     provides an output for the CATCH.
  2147.  
  2148.     THROW "TOPLEVEL can be used to terminate all running procedures
  2149.     and interactive pauses, and return to the toplevel instruction
  2150.     prompt.  Typing the system interrupt character (normally ^C)
  2151.     has the same effect.
  2152.  
  2153.     THROW "ERROR can be used to generate an error condition.  If the
  2154.     error is not caught, it prints a message (THROW "ERROR) with the
  2155.     usual indication of where the error (in this case the THROW)
  2156.     occurred.  If a second input is used along with a tag of ERROR,
  2157.     that second input is used as the text of the error message
  2158.     instead of the standard message.  Also, in this case, the location
  2159.     indicated for the error will be, not the location of the THROW,
  2160.     but the location where the procedure containing the THROW was
  2161.     invoked.  This allows user-defined procedures to generate error
  2162.     messages as if they were primitives.  Note: in this case the
  2163.     corresponding CATCH "ERROR, if any, does not output, since the second
  2164.     input to THROW is not considered a return value.
  2165.  
  2166.     THROW "SYSTEM immediately leaves Logo, returning to the operating
  2167.     system, without printing the usual parting message and without
  2168.     deleting any editor temporary file written by EDIT.
  2169.  
  2170. ERROR
  2171.  
  2172.     outputs a list describing the error just caught, if any.  If there
  2173.     was not an error caught since the last use of ERROR, the empty list
  2174.     will be output.  The error list contains four members: an integer
  2175.     code corresponding to the type of error, the text of the error
  2176.     message, the name of the procedure in which the error occurred, and
  2177.     the instruction line on which the error occurred.
  2178.  
  2179. PAUSE
  2180.  
  2181.     command or operation.  Enters an interactive pause.  The user is
  2182.     prompted for instructions, as at toplevel, but with a prompt that
  2183.     includes the name of the procedure in which PAUSE was invoked.
  2184.     Local variables of that procedure are available during the pause.
  2185.     PAUSE outputs if the pause is ended by a CONTINUE with an input.
  2186.  
  2187.     If the variable ERRACT exists, and an error condition occurs, the
  2188.     contents of that variable are run as an instructionlist.  Typically
  2189.     ERRACT is given the value [PAUSE] so that an interactive pause will
  2190.     be entered on the event of an error.  This allows the user to check
  2191.     values of local variables at the time of the error.
  2192.  
  2193.     Typing the system quit character (normally ^\) will also enter
  2194.     a pause.
  2195.  
  2196. CONTINUE value
  2197. CO value
  2198. (CONTINUE)
  2199. (CO)
  2200.  
  2201.     command.  Ends the current interactive pause, returning to the
  2202.     context of the PAUSE invocation that began it.  If CONTINUE is
  2203.     given an input, that value is used as the output from the PAUSE.
  2204.     If not, the PAUSE does not output.
  2205.  
  2206.     Exceptionally, the CONTINUE command can be used without its default
  2207.     input and without parentheses provided that nothing follows it on
  2208.     the instruction line.
  2209.  
  2210. WAIT time
  2211.  
  2212.     command.  Delays further execution for "time" 60ths of a second.
  2213.     Also causes any buffered characters destined for the terminal to
  2214.     be printed immediately.  WAIT 0 can be used to achieve this
  2215.     buffer flushing without actually waiting.
  2216.  
  2217. BYE
  2218.  
  2219.     command.  Exits from Logo; returns to the operating system.
  2220.  
  2221. .MAYBEOUTPUT value                    (special form)
  2222.  
  2223.     works like OUTPUT except that the expression that provides the
  2224.     input value might not, in fact, output a value, in which case
  2225.     the effect is like STOP.  This is intended for use in control
  2226.     structure definitions, for cases in which you don't know whether
  2227.     or not some expression produces a value.  Example:
  2228.  
  2229.         to invoke :function [:inputs] 2
  2230.         .maybeoutput apply :function :inputs
  2231.         end
  2232.  
  2233.         ? (invoke "print "a "b "c)
  2234.         a b c
  2235.         ? print (invoke "word "a "b "c)
  2236.         abc
  2237.  
  2238.     This is an alternative to RUNRESULT.  It's fast and easy to use,
  2239.     at the cost of being an exception to Logo's evaluation rules.
  2240.     (Ordinarily, it should be an error if the expression that's
  2241.     supposed to provide an input to something doesn't have a value.)
  2242.  
  2243. IGNORE value                        (library procedure)
  2244.  
  2245.     command.  Does nothing.  Used when an expression is evaluated for
  2246.     a side effect and its actual value is unimportant.
  2247.  
  2248. ` list                            (library procedure)
  2249.  
  2250.     outputs a list equal to its input but with certain substitutions.
  2251.     If a member of the input list is the word "," (comma) then the
  2252.     following member should be an instructionlist that produces an
  2253.     output when run.  That output value replaces the comma and the
  2254.     instructionlist.  If a member of the input list is the word ",@"
  2255.     (comma atsign) then the following member should be an instructionlist
  2256.     that outputs a list when run.  The members of that list replace the
  2257.     ,@ and the instructionlist.  Example:
  2258.  
  2259.         show `[foo baz ,[bf [a b c]] garply ,@[bf [a b c]]]
  2260.  
  2261.     will print
  2262.  
  2263.         [foo baz [b c] garply b c]
  2264.  
  2265. FOR forcontrol instructionlist                (library procedure)
  2266.  
  2267.     command.  The first input must be a list containing three or four
  2268.     members: (1) a word, which will be used as the name of a local
  2269.     variable; (2) a word or list that will be evaluated as by RUN to
  2270.     determine a number, the starting value of the variable; (3) a word
  2271.     or list that will be evaluated to determine a number, the limit value
  2272.     of the variable; (4) an optional word or list that will be evaluated
  2273.     to determine the step size.  If the fourth element is missing, the
  2274.     step size will be 1 or -1 depending on whether the limit value is
  2275.     greater than or less than the starting value, respectively.
  2276.  
  2277.     The second input is an instructionlist.  The effect of FOR is to run
  2278.     that instructionlist repeatedly, assigning a new value to the control
  2279.     variable (the one named by the first element of the forcontrol list)
  2280.     each time.  First the starting value is assigned to the control
  2281.     variable.  Then the value is compared to the limit value.  FOR is
  2282.     complete when the sign of (current - limit) is the same as the sign
  2283.     of the step size.  (If no explicit step size is provided, the
  2284.     instructionlist is always run at least once.  An explicit step size
  2285.     can lead to a zero-trip FOR, e.g., FOR [I 1 0 1] ...)  Otherwise, the
  2286.     instructionlist is run, then the step is added to the current value
  2287.     of the control variable and FOR returns to the comparison step.
  2288.  
  2289.         ? for [i 2 7 1.5] [print :i]
  2290.         2
  2291.         3.5
  2292.         5
  2293.         6.5
  2294.         ?
  2295.  
  2296. DO.WHILE instructionlist tfexpression            (library procedure)
  2297.  
  2298.     command.  Repeatedly evaluates the "instructionlist" as long as the
  2299.     evaluated "tfexpression" remains TRUE.  Evaluates the first input
  2300.     first, so the "instructionlist" is always run at least once.  The
  2301.     "tfexpression" must be an expressionlist whose value when evaluated
  2302.     is TRUE or FALSE.
  2303.  
  2304. WHILE tfexpression instructionlist            (library procedure)
  2305.  
  2306.     command.  Repeatedly evaluates the "instructionlist" as long as the
  2307.     evaluated "tfexpression" remains TRUE.  Evaluates the first input
  2308.     first, so the "instructionlist" may never be run at all.  The
  2309.     "tfexpression" must be an expressionlist whose value when evaluated
  2310.     is TRUE or FALSE.
  2311.  
  2312. DO.UNTIL instructionlist tfexpression            (library procedure)
  2313.  
  2314.     command.  Repeatedly evaluates the "instructionlist" as long as the
  2315.     evaluated "tfexpression" remains FALSE.  Evaluates the first input
  2316.     first, so the "instructionlist" is always run at least once.  The
  2317.     "tfexpression" must be an expressionlist whose value when evaluated
  2318.     is TRUE or FALSE.
  2319.  
  2320. UNTIL tfexpression instructionlist            (library procedure)
  2321.  
  2322.     command.  Repeatedly evaluates the "instructionlist" as long as the
  2323.     evaluated "tfexpression" remains FALSE.  Evaluates the first input
  2324.     first, so the "instructionlist" may never be run at all.  The
  2325.     "tfexpression" must be an expressionlist whose value when evaluated
  2326.     is TRUE or FALSE.
  2327.  
  2328.  
  2329. TEMPLATE-BASED ITERATION
  2330. ------------------------
  2331.  
  2332. The procedures in this section are iteration tools based on the idea of a
  2333. "template."  This is a generalization of an instruction list or an
  2334. expression list in which "slots" are provided for the tool to insert varying
  2335. data.  Three different forms of template can be used.
  2336.  
  2337. The most commonly used form for a template is "explicit-slot" form, or
  2338. "question mark" form.  Example:
  2339.  
  2340.     ? show map [? * ?] [2 3 4 5]
  2341.     [4 9 16 25]
  2342.     ?
  2343.  
  2344. In this example, the MAP tool evaluated the template [? * ?] repeatedly,
  2345. with each of the members of the data list [2 3 4 5] substituted in turn
  2346. for the question marks.  The same value was used for every question mark
  2347. in a given evaluation.  Some tools allow for more than one datum to be
  2348. substituted in parallel; in these cases the slots are indicated by ?1 for
  2349. the first datum, ?2 for the second, and so on:
  2350.  
  2351.     ? show (map [word ?1 ?2 ?1] [a b c] [d e f])
  2352.     [ada beb cfc]
  2353.     ?
  2354.  
  2355. If the template wishes to compute the datum number, the form (? 1) is
  2356. equivalent to ?1, so (? ?1) means the datum whose number is given in
  2357. datum number 1.  Some tools allow additional slot designations, as shown
  2358. in the individual descriptions.
  2359.  
  2360. The second form of template is the "named-procedure" form.  If the template
  2361. is a word rather than a list, it is taken as the name of a procedure.  That
  2362. procedure must accept a number of inputs equal to the number of parallel
  2363. data slots provided by the tool; the procedure is applied to all of the
  2364. available data in order.  That is, if data ?1 through ?3 are available,
  2365. the template "PROC is equivalent to [PROC ?1 ?2 ?3].
  2366.  
  2367.     ? show (map "word [a b c] [d e f])
  2368.     [ad be cf]
  2369.     ?
  2370.  
  2371.     to dotprod :a :b    ; vector dot product
  2372.     op apply "sum (map "product :a :b)
  2373.     end
  2374.  
  2375. The third form of template is "named-slot" or "lambda" form.  This form is
  2376. indicated by a template list containing more than one element, whose first
  2377. element is itself a list.  The first element is taken as a list of names;
  2378. local variables are created with those names and given the available data
  2379. in order as their values.  The number of names must equal the number of
  2380. available data.  This form is needed primarily when one iteration tool must
  2381. be used within the template list of another, and the ? notation would be
  2382. ambiguous in the inner template.  Example:
  2383.  
  2384.     to matmul :m1 :m2 [:tm2 transpose :m2]    ; multiply two matrices
  2385.     output map [[row] map [[col] dotprod :row :col] :tm2] :m1
  2386.     end
  2387.  
  2388. These iteration tools are extended versions of the ones in Appendix B of the
  2389. book _Computer_Science_Logo_Style,_Volume_3:_Advanced_Topics_ by Brian
  2390. Harvey [MIT Press, 1987].  The extensions are primarily to allow for variable
  2391. numbers of inputs.
  2392.  
  2393.  
  2394. APPLY template inputlist
  2395.  
  2396.     command or operation.  Runs the "template," filling its slots with
  2397.     the members of "inputlist."  The number of members in "inputlist"
  2398.     must be an acceptable number of slots for "template."  It is
  2399.     illegal to apply the primitive TO as a template, but anything else
  2400.     is okay.  APPLY outputs what "template" outputs, if anything.
  2401.  
  2402. INVOKE template input                    (library procedure)
  2403. (INVOKE template input1 input2 ...)
  2404.  
  2405.     command or operation.  Exactly like APPLY except that the inputs
  2406.     are provided as separate expressions rather than in a list.
  2407.  
  2408. FOREACH data template                    (library procedure)
  2409. (FOREACH data1 data2 ... template)
  2410.  
  2411.     command.  Evaluates the template list repeatedly, once for each
  2412.     element of the data list.  If more than one data list are given,
  2413.     each of them must be the same length.  (The data inputs can be
  2414.     words, in which case the template is evaluated once for each
  2415.     character.
  2416.  
  2417.     In a template, the symbol ?REST represents the portion of the
  2418.     data input to the right of the member currently being used as
  2419.     the ? slot-filler.  That is, if the data input is [A B C D E]
  2420.     and the template is being evaluated with ? replaced by B, then
  2421.     ?REST would be replaced by [C D E].  If multiple parallel slots
  2422.     are used, then (?REST 1) goes with ?1, etc.
  2423.  
  2424.     In a template, the symbol # represents the position in the data
  2425.     input of the member currently being used as the ? slot-filler.
  2426.     That is, if the data input is [A B C D E] and the template is
  2427.     being evaluated with ? replaced by B, then # would be replaced
  2428.     by 2.
  2429.  
  2430. MAP template data                    (library procedure)
  2431. (MAP template data1 data2 ...)
  2432.  
  2433.     outputs a word or list, depending on the type of the data input,
  2434.     of the same length as that data input.  (If more than one data
  2435.     input are given, the output is of the same type as data1.)  Each
  2436.     element of the output is the result of evaluating the template
  2437.     list, filling the slots with the corresponding element(s) of the
  2438.     data input(s).  (All data inputs must be the same length.)  In the
  2439.     case of a word output, the results of the template evaluation must
  2440.     be words, and they are concatenated with WORD.
  2441.  
  2442.     In a template, the symbol ?REST represents the portion of the
  2443.     data input to the right of the member currently being used as
  2444.     the ? slot-filler.  That is, if the data input is [A B C D E]
  2445.     and the template is being evaluated with ? replaced by B, then
  2446.     ?REST would be replaced by [C D E].  If multiple parallel slots
  2447.     are used, then (?REST 1) goes with ?1, etc.
  2448.  
  2449.     In a template, the symbol # represents the position in the data
  2450.     input of the member currently being used as the ? slot-filler.
  2451.     That is, if the data input is [A B C D E] and the template is
  2452.     being evaluated with ? replaced by B, then # would be replaced
  2453.     by 2.
  2454.  
  2455. MAP.SE template data                    (library procedure)
  2456. (MAP.SE template data1 data2 ...)
  2457.  
  2458.     outputs a list formed by evaluating the template list repeatedly
  2459.     and concatenating the results using SENTENCE.  That is, the
  2460.     members of the output are the members of the results of the
  2461.     evaluations.  The output list might, therefore, be of a different
  2462.     length from that of the data input(s).  (If the result of an
  2463.     evaluation is the empty list, it contributes nothing to the final
  2464.     output.)  The data inputs may be words or lists.
  2465.  
  2466.     In a template, the symbol ?REST represents the portion of the
  2467.     data input to the right of the member currently being used as
  2468.     the ? slot-filler.  That is, if the data input is [A B C D E]
  2469.     and the template is being evaluated with ? replaced by B, then
  2470.     ?REST would be replaced by [C D E].  If multiple parallel slots
  2471.     are used, then (?REST 1) goes with ?1, etc.
  2472.  
  2473.     In a template, the symbol # represents the position in the data
  2474.     input of the member currently being used as the ? slot-filler.
  2475.     That is, if the data input is [A B C D E] and the template is
  2476.     being evaluated with ? replaced by B, then # would be replaced
  2477.     by 2.
  2478.  
  2479. FILTER tftemplate data                    (library procedure)
  2480.  
  2481.     outputs a word or list, depending on the type of the data input,
  2482.     containing a subset of the members (for a list) or characters (for
  2483.     a word) of the input.  The template is evaluated once for each
  2484.     member or character of the data, and it must produce a TRUE or
  2485.     FALSE value.  If the value is TRUE, then the corresponding input
  2486.     constituent is included in the output.
  2487.  
  2488.         ? print filter "vowelp "elephant
  2489.         eea
  2490.         ?
  2491.  
  2492.     In a template, the symbol ?REST represents the portion of the
  2493.     data input to the right of the member currently being used as
  2494.     the ? slot-filler.  That is, if the data input is [A B C D E]
  2495.     and the template is being evaluated with ? replaced by B, then
  2496.     ?REST would be replaced by [C D E].
  2497.  
  2498.     In a template, the symbol # represents the position in the data
  2499.     input of the member currently being used as the ? slot-filler.
  2500.     That is, if the data input is [A B C D E] and the template is
  2501.     being evaluated with ? replaced by B, then # would be replaced
  2502.     by 2.
  2503.  
  2504. FIND tftemplate data                    (library procedure)
  2505.  
  2506.     outputs the first constituent of the data input (the first member
  2507.     of a list, or the first character of a word) for which the value
  2508.     produced by evaluating the template with that consituent in its
  2509.     slot is TRUE.  If there is no such constituent, the empty list
  2510.     is output.
  2511.  
  2512.     In a template, the symbol ?REST represents the portion of the
  2513.     data input to the right of the member currently being used as
  2514.     the ? slot-filler.  That is, if the data input is [A B C D E]
  2515.     and the template is being evaluated with ? replaced by B, then
  2516.     ?REST would be replaced by [C D E].
  2517.  
  2518.     In a template, the symbol # represents the position in the data
  2519.     input of the member currently being used as the ? slot-filler.
  2520.     That is, if the data input is [A B C D E] and the template is
  2521.     being evaluated with ? replaced by B, then # would be replaced
  2522.     by 2.
  2523.  
  2524. REDUCE template data                    (library procedure)
  2525.  
  2526.     outputs the result of applying the template to accumulate the
  2527.     elements of the data input.  The template must be a two-slot
  2528.     function.  Typically it is an associative function name like "SUM.
  2529.     If the data input has only one constituent (member in a list or
  2530.     character in a word), the output is that consituent.  Otherwise,
  2531.     the template is first applied with ?1 filled with the next-to-last
  2532.     consitient and ?2 with the last constituent.  Then, if there are
  2533.     more constituents, the template is applied with ?1 filled with the
  2534.     next constituent to the left and ?2 with the result from the
  2535.     previous evaluation.  This process continues until all constituents
  2536.     have been used.  The data input may not be empty.
  2537.  
  2538.     Note: If the template is, like SUM, the name of a procedure that is
  2539.     capable of accepting arbitrarily many inputs, it is more efficient
  2540.     to use APPLY instead of REDUCE.  The latter is good for associative
  2541.     procedures that have been written to accept exactly two inputs:
  2542.  
  2543.         to max :a :b
  2544.         output ifelse :a > :b [:a] [:b]
  2545.         end
  2546.  
  2547.         print reduce "max [...]
  2548.  
  2549.     Alternatively, REDUCE can be used to write MAX as a procedure
  2550.     that accepts any number of inputs, as SUM does:
  2551.  
  2552.         to max [:inputs] 2
  2553.         if emptyp :inputs ~
  2554.            [(throw "error [not enough inputs to max])]
  2555.         output reduce [ifelse ?1 > ?2 [?1] [?2]] :inputs
  2556.         end
  2557.  
  2558. CROSSMAP template listlist                (library procedure)
  2559. (CROSSMAP template data1 data2 ...)
  2560.  
  2561.     outputs a list containing the results of template evaluations.
  2562.     Each data list contributes to a slot in the template; the number
  2563.     of slots is equal to the number of data list inputs.  As a special
  2564.     case, if only one data list input is given, that list is taken as
  2565.     a list of data lists, and each of its members contributes values
  2566.     to a slot.  CROSSMAP differs from MAP in that instead of taking
  2567.     members from the data inputs in parallel, it takes all possible
  2568.     combinations of members of data inputs, which need not be the same
  2569.     length.
  2570.  
  2571.         ? show (crossmap [word ?1 ?2] [a b c] [1 2 3 4])
  2572.         [a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4]
  2573.         ?
  2574.  
  2575.     For compatibility with the version in CSLS, CROSSMAP templates
  2576.     may use the notation :1 instead of ?1 to indicate slots.
  2577.  
  2578. CASCADE endtest template startvalue            (library procedure)
  2579. (CASCADE endtest tmp1 sv1 tmp2 sv2 ...)
  2580. (CASCADE endtest tmp1 sv1 tmp2 sv2 ... finaltemplate)
  2581.  
  2582.     outputs the result of applying a template (or several templates,
  2583.     as explained below) repeatedly, with a given value filling the
  2584.     slot the first time, and the result of each application filling
  2585.     the slot for the following application.
  2586.  
  2587.     In the simplest case, CASCADE has three inputs.  The second input
  2588.     is a one-slot expression template.  That template is evaluated
  2589.     some number of times (perhaps zero).  On the first evaluation,
  2590.     the slot is filled with the third input; on subsequent evaluations,
  2591.     the slot is filled with the result of the previous evaluation.
  2592.     The number of evaluations is determined by the first input.  This
  2593.     can be either a nonnegative integer, in which case the template is
  2594.     evaluated that many times, or a predicate expression template, in
  2595.     which case it is evaluated (with the same slot filler that will be
  2596.     used for the evaluation of the second input) repeatedly, and the
  2597.     CASCADE evaluation continues as long as the predicate value is
  2598.     FALSE.  (In other words, the predicate template indicates the
  2599.     condition for stopping.)
  2600.  
  2601.     If the template is evaluated zero times, the output from CASCADE
  2602.     is the third (startvalue) input.  Otherwise, the output is the
  2603.     value produced by the last template evaluation.
  2604.  
  2605.     CASCADE templates may include the symbol # to represent the number
  2606.     of times the template has been evaluated.  This slot is filled with
  2607.     1 for the first evaluation, 2 for the second, and so on.
  2608.  
  2609.         ? show cascade 5 [lput # ?] []
  2610.         [1 2 3 4 5]
  2611.         ? show cascade [vowelp first ?] [bf ?] "spring
  2612.         ing
  2613.         ? show cascade 5 [# * ?] 1
  2614.         120
  2615.         ?
  2616.  
  2617.     Several cascaded results can be computed in parallel by providing
  2618.     additional template-startvalue pairs as inputs to CASCADE.  In this
  2619.     case, all templates (including the endtest template, if used) are
  2620.     multi-slot, with the number of slots equal to the number of pairs of
  2621.     inputs.  In each round of evaluations, ?2 represents the result of
  2622.     evaluating the second template in the previous round.  If the total
  2623.     number of inputs (including the first endtest input) is odd, then
  2624.     the output from CASCADE is the final value of the first template.
  2625.     If the total number of inputs is even, then the last input is a
  2626.     template that is evaluated once, after the end test is satisfied,
  2627.     to determine the output from CASCADE.
  2628.  
  2629.         to fibonacci :n
  2630.         output (cascade :n [?1 + ?2] 1 [?1] 0)
  2631.         end
  2632.  
  2633.         to piglatin :word
  2634.         output (cascade [vowelp first ?] ~
  2635.                 [word bf ? first ?] ~
  2636.                 :word ~
  2637.                 [word ? "ay])
  2638.         end
  2639.  
  2640. CASCADE.2 endtest temp1 startval1 temp2 startval2    (library procedure)
  2641.  
  2642.     outputs the result of invoking CASCADE with the same inputs.
  2643.     The only difference is that the default number of inputs is
  2644.     five instead of three.
  2645.  
  2646. TRANSFER endtest template inbasket            (library procedure)
  2647.  
  2648.     outputs the result of repeated evaluation of the template.
  2649.     The template is evaluated once for each member of the list
  2650.     "inbasket."  TRANSFER maintains an "outbasket" that is
  2651.     initially the empty list.  After each evaluation of the
  2652.     template, the resulting value becomes the new outbasket.
  2653.  
  2654.     In the template, the symbol ?IN represents the current element
  2655.     from the inbasket; the symbol ?OUT represents the entire
  2656.     current outbasket.  Other slot symbols should not be used.
  2657.  
  2658.     If the first (endtest) input is an empty list, evaluation
  2659.     continues until all inbasket members have been used.  If not,
  2660.     the first input must be a predicate expression template, and
  2661.     evaluation continues until either that template's value is TRUE
  2662.     or the inbasket is used up.
  2663.  
  2664.  
  2665. MACROS
  2666. ======
  2667.  
  2668. .MACRO procname :input1 :input2 ...                (special form)
  2669. .DEFMACRO procname text
  2670. MACROP name
  2671.  
  2672.     A macro is a special kind of procedure whose output is evaluated
  2673.     as Logo instructions in the context of the macro's caller.
  2674.     .MACRO is exactly like TO except that the new procedure becomes
  2675.     a macro; .DEFMACRO is exactly like DEFINE with the same exception.
  2676.     MACROP returns TRUE if its input is the name of a macro.
  2677.  
  2678.     Macros are useful for inventing new control structures comparable
  2679.     to REPEAT, IF, and so on.  Such control structures can almost, but
  2680.     not quite, be duplicated by ordinary Logo procedures.  For example,
  2681.     here is an ordinary procedure version of REPEAT:
  2682.  
  2683.         to my.repeat :num :instructions
  2684.         if :num=0 [stop]
  2685.         run :instructions
  2686.         my.repeat :num-1 :instructions
  2687.         end
  2688.  
  2689.     This version works fine for most purposes, e.g.,
  2690.  
  2691.         my.repeat 5 [print "hello]
  2692.  
  2693.     But it doesn't work if the instructions to be carried out include
  2694.     OUTPUT, STOP, or LOCAL.  For example, consider this procedure:
  2695.  
  2696.         to example
  2697.         print [Guess my secret word.  You get three guesses.]
  2698.         repeat 3 [type "|?? | ~
  2699.               if readword = "secret [pr "Right! stop]]
  2700.         print [Sorry, the word was "secret"!]
  2701.         end
  2702.  
  2703.     This procedure works as written, but if MY.REPEAT is used instead
  2704.     of REPEAT, it won't work because the STOP will stop MY.REPEAT
  2705.     instead of stopping EXAMPLE as desired.
  2706.  
  2707.     The solution is to make MY.REPEAT a macro.  Instead of actually
  2708.     carrying out the computation, a macro must return a list containing
  2709.     Logo instructions.  The contents of that list are evaluated as if
  2710.     they appeared in place of the call to the macro.  Here's a macro
  2711.     version of REPEAT:
  2712.  
  2713.         .macro my.repeat :num :instructions
  2714.         if :num=0 [output []]
  2715.         output sentence :instructions ~
  2716.                 (list "my.repeat :num-1 :instructions)
  2717.         end
  2718.  
  2719.     Every macro is an operation -- it must always output something.
  2720.     Even in the base case, MY.REPEAT outputs an empty instruction
  2721.     list.  To show how MY.REPEAT works, let's take the example
  2722.  
  2723.         my.repeat 5 [print "hello]
  2724.  
  2725.     For this example, MY.REPEAT will output the instruction list
  2726.  
  2727.         [print "hello my.repeat 4 [print "hello]]
  2728.  
  2729.     Logo then executes these instructions in place of the original
  2730.     invocation of MY.REPEAT; this prints "hello" once and invokes
  2731.     another repetition.
  2732.  
  2733.     The technique just shown, although fairly easy to understand,
  2734.     has the defect of slowness because each repetition has to
  2735.     construct an instruction list for evaluation.  Another approach
  2736.     is to make my.repeat a macro that works just like the non-macro
  2737.     version unless the instructions to be repeated include OUTPUT
  2738.     or STOP:
  2739.  
  2740.         .macro my.repeat :num :instructions
  2741.         catch "repeat.catchtag ~
  2742.               [op repeat.done runresult [repeat1 :num :instructions]]
  2743.         op []
  2744.         end
  2745.  
  2746.         to repeat1 :num :instructions
  2747.         if :num=0 [throw "repeat.catchtag]
  2748.         run :instructions
  2749.         .maybeoutput repeat1 :num-1 :instructions
  2750.         end
  2751.  
  2752.         to repeat.done :repeat.result
  2753.         if emptyp :repeat.result [op [stop]]
  2754.         op list "output quoted first :repeat.result
  2755.         end
  2756.  
  2757.     If the instructions do not include STOP or OUTPUT, then REPEAT1 will
  2758.     reach its base case and invoke THROW.  As a result, my.repeat's last
  2759.     instruction line will output an empty list, so the second evaluation
  2760.     of the macro result will do nothing.  But if a STOP or OUTPUT happens,
  2761.     then REPEAT.DONE will output a STOP or OUTPUT instruction that will
  2762.     be re-executed in the caller's context.
  2763.  
  2764.     The macro-defining commands have names starting with a dot because
  2765.     macros are an advanced feature of Logo; it's easy to get in trouble
  2766.     by defining a macro that doesn't terminate, or by failing to
  2767.     construct the instruction list properly.
  2768.  
  2769.     Lisp users should note that Logo macros are NOT special forms.
  2770.     That is, the inputs to the macro are evaluated normally, as they
  2771.     would be for any other Logo procedure.  It's only the output from
  2772.     the macro that's handled unusually.
  2773.  
  2774.     Here's another example:
  2775.  
  2776.         .macro localmake :name :value
  2777.         output (list "local        ~
  2778.                  word "" :name    ~
  2779.                  "apply        ~
  2780.                  ""make        ~
  2781.                  (list :name :value))
  2782.         end
  2783.  
  2784.     It's used this way:
  2785.  
  2786.         to try
  2787.         localmake "garply "hello
  2788.         print :garply
  2789.         end
  2790.  
  2791.     LOCALMAKE outputs the list
  2792.  
  2793.         [local "garply apply "make [garply hello]]
  2794.  
  2795.     The reason for the use of APPLY is to avoid having to decide
  2796.     whether or not the second input to MAKE requires a quotation
  2797.     mark before it.  (In this case it would -- MAKE "GARPLY "HELLO --
  2798.     but the quotation mark would be wrong if the value were a list.)
  2799.  
  2800.     It's often convenient to use the ` function to construct the
  2801.     instruction list:
  2802.  
  2803.         .macro localmake :name :value
  2804.         op `[local ,[word "" :name] apply "make [,[:name] ,[:value]]]
  2805.         end
  2806.  
  2807.     On the other hand, ` is pretty slow, since it's tree recursive and
  2808.     written in Logo.
  2809.  
  2810.  
  2811. ERROR PROCESSING
  2812. ================
  2813.  
  2814. If an error occurs, Logo takes the following steps.  First, if there is
  2815. an available variable named ERRACT, Logo takes its value as an instructionlist
  2816. and runs the instructions.  The operation ERROR may be used within the
  2817. instructions (once) to examine the error condition.  If the instructionlist
  2818. invokes PAUSE, the error message is printed before the pause happens.
  2819. Certain errors are "recoverable"; for one of those errors, if the
  2820. instructionlist outputs a value, that value is used in place of the
  2821. expression that caused the error.  (If ERRACT invokes PAUSE and the user then
  2822. invokes CONTINUE with an input, that input becomes the output from PAUSE and
  2823. therefore the output from the ERRACT instructionlist.)
  2824.  
  2825. It is possible for an ERRACT instructionlist to produce an inappropriate value
  2826. or no value where one is needed.  As a result, the same error condition could
  2827. recur forever because of this mechanism.  To avoid that danger, if the same
  2828. error condition occurs twice in a row from an ERRACT instructionlist without
  2829. user interaction, the message "Erract loop" is printed and control returns
  2830. to toplevel.  "Without user interaction" means that if ERRACT invokes PAUSE and
  2831. the user provides an incorrect value, this loop prevention mechanism does not
  2832. take effect and the user gets to try again.
  2833.  
  2834. During the running of the ERRACT instructionlist, ERRACT is locally unbound,
  2835. so an error in the ERRACT instructions themselves will not cause a loop.  In
  2836. particular, an error during a pause will not cause a pause-within-a-pause
  2837. unless the user reassigns the value [PAUSE] to ERRACT during the pause.  But
  2838. such an error will not return to toplevel; it will remain within the original
  2839. pause loop.
  2840.  
  2841. If there is no available ERRACT value, Logo handles the error by generating
  2842. an internal THROW "ERROR.  (A user program can also generate an error
  2843. condition deliberately by invoking THROW.)  If this throw is not caught by
  2844. a CATCH "ERROR in the user program, it is eventually caught either by the
  2845. toplevel instruction loop or by a pause loop, which prints the error message.
  2846. An invocation of CATCH "ERROR in a user program locally unbinds ERRACT, so
  2847. the effect is that whichever of ERRACT and CATCH "ERROR is more local will
  2848. take precedence.
  2849.  
  2850. If a floating point overflow occurs during an arithmetic operation, or a
  2851. two-input mathematical function (like POWER) is invoked with an illegal
  2852. combination of inputs, the "doesn't like" message refers to the second
  2853. operand, but should be taken as meaning the combination.
  2854.  
  2855.  
  2856. ERROR CODES
  2857. -----------
  2858.  
  2859. Here are the numeric codes that appear as the first element of the list
  2860. output by ERROR when an error is caught, with the corresponding messages.
  2861. Some messages may have two different codes depending on whether or not
  2862. the error is recoverable (that is, a substitute value can be provided
  2863. through the ERRACT mechanism) in the specific context.  Some messages are
  2864. warnings rather than errors; these will not be caught.  The first two are
  2865. so bad that Logo exits immediately.
  2866.  
  2867.   0    Fatal internal error (can't be caught)
  2868.   1    Out of memory (can't be caught)
  2869.   2    PROC doesn't like DATUM as input (not recoverable)
  2870.   3    PROC didn't output to PROC
  2871.   4    Not enough inputs to PROC
  2872.   5    PROC doesn't like DATUM as input (recoverable)
  2873.   6    Too much inside ()'s
  2874.   7    I don't know what to do with DATUM
  2875.   8    ')' not found
  2876.   9    VAR has no value
  2877.  10    Unexpected ')'
  2878.  11    I don't know how to PROC (recoverable)
  2879.  12    Can't find catch tag for THROWTAG
  2880.  13    PROC is already defined
  2881.  14    Stopped
  2882.  15    Already dribbling
  2883.  16    File system error
  2884.  17    Assuming you mean IFELSE, not IF (warning only)
  2885.  18    VAR shadowed by local in procedure call (warning only)
  2886.  19    Throw "Error
  2887.  20    PROC is a primitive
  2888.  21    Can't use TO inside a procedure
  2889.  22    I don't know how to PROC (not recoverable)
  2890.  23    IFTRUE/IFFALSE without TEST
  2891.  24    Unexpected ']'
  2892.  25    Unexpected '}'
  2893.  26    Couldn't initialize graphics
  2894.  27    Macro returned VALUE instead of a list
  2895.  28    I don't know what to do with VALUE
  2896.  29    Can only use STOP or OUTPUT inside a procedure
  2897.  
  2898. SPECIAL VARIABLES
  2899. =================
  2900.  
  2901. Logo takes special action if any of the following variable names exists.
  2902. They follow the normal scoping rules, so a procedure can locally set one
  2903. of them to limit the scope of its effect.  Initially, no variables exist
  2904. except CASEIGNOREDP, which is TRUE and buried.
  2905.  
  2906. CASEIGNOREDP
  2907.  
  2908.     if TRUE, indicates that lower case and upper case letters should be
  2909.     considered equal by EQUALP, BEFOREP, MEMBERP, etc.  Logo initially
  2910.     makes this variable TRUE, and buries it.
  2911.  
  2912. ERRACT
  2913.  
  2914.     an instructionlist that will be run in the event of an error.
  2915.     Typically has the value [PAUSE] to allow interactive debugging.
  2916.  
  2917. PRINTDEPTHLIMIT
  2918.  
  2919.     if a nonnegative integer, indicates the maximum depth of sublist
  2920.     structure that will be printed by PRINT, etc.
  2921.  
  2922. PRINTWIDTHLIMIT
  2923.  
  2924.     if a nonnegative integer, indicates the maximum number of elements
  2925.     in any one list that will be printed by PRINT, etc.
  2926.  
  2927. REDEFP
  2928.  
  2929.     if TRUE, allows primitives to be erased (ERASE) or redefined (COPYDEF).
  2930.  
  2931. STARTUP
  2932.  
  2933.     if assigned a list value in a file loaded by LOAD, that value is
  2934.     run as an instructionlist after the loading.
  2935.