home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / aa_m68k_Only / NXLogo / NXLogoLibrary / help / foo < prev    next >
Encoding:
Text File  |  1992-07-09  |  70.5 KB  |  1,388 lines

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