home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / logo / part05 / logoman.1
Encoding:
Text File  |  1987-06-23  |  34.8 KB  |  799 lines

  1. .ll 7.5i
  2. .lt 7.5i
  3. .po .2i
  4. .pn 1
  5. .de TL
  6. .sp 2
  7. .ft 3
  8. .ce
  9. \\$1
  10. .sp 1
  11. .ft 1
  12. ..
  13. .de PP
  14. .sp 1
  15. .ti 5
  16. .fi
  17. .ft 1
  18. ..
  19. .de NB
  20. .de NP
  21. 'sp 1
  22. .tl ''%''
  23. 'bp +1
  24. 'sp 2
  25. \\..
  26. .ch NP -1i
  27. ..
  28. .de NP
  29. 'bp +1
  30. 'sp 2
  31. ..
  32. .wh -1.0i NP
  33. .TL "LSRHS Logo Manual"
  34. .NB
  35. .de EX
  36. .ft 3
  37. .in +5
  38. .sp 1
  39. .nf
  40. ..
  41. .de EE
  42. .ft 1
  43. .in -5
  44. .fi
  45. .PP
  46. ..
  47. .de EC
  48. .ft 1
  49. .in -5
  50. .sp 1
  51. .fi
  52. ..
  53. .de IN
  54. .br
  55. .in +5
  56. ..
  57. .de OU
  58. .sp 1
  59. .in -5
  60. ..
  61. .de UB
  62. .uf 3
  63. .cu 1
  64. \\$1
  65. .ft 1
  66. .uf 2
  67. ..
  68. .PP
  69. .UB "Introduction."
  70. Logo is a computer programming language which was
  71. designed to be both simple to use and extremely powerful.  It was
  72. designed by a group of computer scientists at MIT and at Bolt, Beranek, and
  73. Newman.  Its structure is based largely on the LISP language, which is
  74. widely used in Artificial Intelligence research, but the notation has been
  75. changed to make Logo far easier for a beginner than LISP.  This manual
  76. describes a version of Logo for the PDP-11, originally written in C at the
  77. Boston Children's Museum and extensively modified at the Lincoln-Sudbury
  78. Regional High School.
  79. .PP
  80. The power of Logo comes primarily from the idea of the \f2procedure\f1.  A
  81. procedure is simply something the computer "knows" how to do; some
  82. procedures are built into Logo itself (these are called \f2primitive\f1
  83. procedures), while others are \f2defined\f1 by the programmer in terms of
  84. these simple procedures.  Defined procedures can be used as part of the
  85. definition of other procedures, so that a complicated program can be built
  86. in "layers" of complexity.  This layered structure is analogous to the
  87. description of a complex machine in terms of building blocks: an automobile
  88. is made of a chassis, a drive train, an electrical system, and so on.  The
  89. drive train contains an engine, a transmission, a clutch, an axle, and so
  90. on.  The transmission contains a housing, gears, and levers.  A lever may
  91. include connecting joints at the ends and at a pivot point.  Eventually the
  92. description of the automobile reaches the level of bolts and washers; these
  93. correspond to the primitive procedures in Logo.
  94. .PP
  95. .UB "Starting Logo."
  96. Use the shell command \f3logo\f1 to start the Logo
  97. interpreter.  When Logo is running it will print a question mark (?) at the
  98. beginning of a line to indicate that it is ready for you to type in a Logo
  99. instruction.  The instruction may print something on the terminal, or draw a
  100. line on a graphics display screen, or move a turtle around the floor.  Then
  101. another question mark is typed and you may give another instruction.  (If Logo
  102. prints a "greater than" sign (>) instead of a question mark, it is
  103. in \f2procedure definition mode\f1,
  104. which will be described later.  Type your system quit character
  105. (control-G at Lincoln-Sudbury) to return to normal mode.)
  106. .PP
  107. If an argument is used with the shell command \f3logo\f1, the argument is
  108. taken as the name of a procedure, which Logo runs before doing anything
  109. else.  You can therefore create a shell script which will start Logo, run
  110. a procedure automatically, and (if you say "goodbye" at the end of the
  111. procedure) exit.
  112. .PP
  113. .UB "Syntax."
  114. Unlike most computer languages, Logo has an almost
  115. entirely uniform
  116. syntax.  That is, all of the different commands Logo understands are
  117. represented using the same notation: the name of a procedure is followed by
  118. its \f2inputs\f1, which may be \f2constants\f1 (like numbers) or else may
  119. be the results of using other procedures.  Here is a simple example:
  120. .EX
  121. print "hello
  122. .EC
  123. In this Logo instruction, the primitive procedure \f3print\f1 is used with
  124. a constant input, the word \f3hello\f1.  The quotation mark indicates that
  125. \f3hello\f1 is being used to represent the word itself; without the
  126. quotation mark it would have been interpreted as the name of a procedure,
  127. just as \f3print\f1 is the name of a procedure.  In Logo, the \f3print\f1
  128. procedure always requires exactly one input, which is the thing to print.  The
  129. input can be a \f2word\f1, as in this example, or a \f2list\f1, which will
  130. be explained later.  (A \f2number\f1 is a special case of a word, and a
  131. \f2sentence\f1 is a special case of a list.)  Here is another example:
  132. .EX
  133. print first "hello
  134. .EC
  135. In this instruction, the primitive procedure \f3first\f1 is used.  This
  136. procedure takes one input, a word, and has an \f2output\f1 which is the
  137. first letter of the word.  The output from \f3first\f1 is used as the input
  138. to \f3print\f1, so what is printed is the letter \f3h\f1 rather than the
  139. word \f3hello\f1 as in the earlier example.
  140. .PP
  141. Don't confuse the \f2output\f1 from a procedure with what is \f2printed\f1
  142. by the \f3print\f1 command.  In Logo, the word "output" is not used to
  143. refer to what is printed by a program, just as the word "input" does not
  144. mean something you type into the program.  Instead, these words refer to
  145. objects (words or lists) which are given to a procedure (inputs) or
  146. produced by a procedure (outputs).  A particular procedure has a fixed
  147. number of inputs and outputs.  The number of inputs may be anything,
  148. including zero, whereas the number of outputs is either zero or one.  A
  149. procedure with an output (like \f3first\f1) is called an \f2operation\f1; one
  150. without an output (like \f3print\f1) is called a \f2command\f1.
  151. .PP
  152. Some operations only have two possible outputs: the word \f3true\f1 and
  153. the word \f3false\f1.  Such a procedure is called a \f2predicate\f1.  Predicates
  154. are used to allow a program to carry out some instruction only if a
  155. particular condition is met.  By convention, predicates generally have
  156. names ending with the letter "p".
  157. .PP
  158. .UB "Multiple inputs to operations."
  159. Several Logo primitive procedures are
  160. operations with two inputs.  The arithmetic operations, like \f3sum\f1, are
  161. examples of this.  A special extension to Logo syntax allows such an operation
  162. to have more than two inputs by enclosing the operation and its inputs in
  163. parentheses or braces:
  164. .EX
  165. (sum 2 5 13 8.5)
  166. .EC
  167. Association is right to left.  At least two inputs must be given, except for
  168. the \f3list\f1 operation, which can take one input if parenthesized.
  169. .PP
  170. .UB "Multi-instruction lines."
  171. It is possible to put more than one instruction on the same line when you
  172. are typing to Logo.  If you do this, it is recommended that you type a
  173. semicolon (;) between the instructions for improved readability:
  174. .EX
  175. print "hello; print "goodbye
  176. .EC
  177. For compatibility with other versions of Logo, it is permitted to leave out
  178. the semicolon.  Later in this manual, the phrase "instruction line" will
  179. mean one or more instructions on a line.
  180. .PP
  181. .UB "Multi-line instructions."
  182. It is possible to continue an instruction on
  183. a second line.  To do this, end the first line with a backslash (\\),
  184. immediately followed by the RETURN key.  If you are typing a quoted word,
  185. you must end the word (with a space, for example) before using the
  186. backslash-RETURN combination.  Inside a quoted word, backslash-RETURN
  187. means to put an actual RETURN as part of the word.
  188. .PP
  189. .UB "Comments."
  190. It is possible to include in an instruction line comments
  191. which are meant for human readers of your program (including yourself, next
  192. week), and which are not Logo instructions.  To do this, begin the comment
  193. with an exclamation point (!).  Everything after the exclamation point on the
  194. line will be ignored by Logo.  For example:
  195. .EX
  196. print [Hi, there.] ! A friendly greeting.
  197. .EC
  198. However, the exclamation point does not begin a comment if it is part of a
  199. word or list (see below).  You should type a space before the exclamation
  200. point, as in the example above, to make sure it will be interpreted as the
  201. beginning of a comment.
  202. .PP
  203. .UB "Words."
  204. Every computer language deals with particular kinds
  205. of objects.  Most languages, like FORTRAN or BASIC or Pascal, are best at
  206. dealing with numbers.  Logo is a \f2list processing\f1 language, which is
  207. at its best with more complicated data structures.  The two main categories
  208. of object are the \f2word\f1 and the \f2list\f1.
  209. .PP
  210. A \f2word\f1 is a string of characters.  (A \f2character\f1 is a letter,
  211. digit, space, or punctuation mark.  Things like TAB and RETURN on the
  212. terminal keyboard are also characters, although they are not usually used
  213. as part of Logo words.)  A word can be any length, including zero.  The way
  214. to indicate a word as part of a Logo program is to use the quotation mark
  215. (") before the word.  The word begins with the character after the
  216. quotation mark and continues until a space, a tab, the end of the
  217. line, or one of these characters:
  218. .EX
  219. ( ) [ ] { } " ;
  220. .EC
  221. A quotation mark immediately followed by a space or one of the other
  222. word-terminating characters indicates the \f2empty word\f1, which is a word
  223. of length zero.
  224. .PP
  225. Please notice that, unlike most programming languages, Logo does not use
  226. quotation marks in pairs to delimit strings of characters.  The following
  227. instruction is an error:
  228. .EX
  229. print "aardvark"
  230. .EC
  231. This is an error because the \f3print\f1 command is followed by \f2two\f1
  232. words, the word \f3aardvark\f1 and an empty word which is indicated by the
  233. second quotation mark.  Since \f3print\f1 only uses one input, the second
  234. word has no purpose, and Logo gives the error message
  235. .EX
  236. You don't say what to do with "
  237. .EE
  238. In order to include one of the word-terminating characters in a word, you
  239. must precede it with a backslash (\\).  Do not confuse backslash with the
  240. regular slash (/) character.  For example, this instruction:
  241. .EX
  242. print "\\(boo\\)
  243. .EC
  244. will print the five characters \f3(boo)\f1 as its result.  The space
  245. character may be included in a word by using a percent (%) instead of the
  246. space.  Therefore, the following are equivalent:
  247. .EX
  248. print "Hello%there.
  249. print "Hello\\ there.
  250. .EC
  251. To include a percent character or a backslash character in a word, you must
  252. precede it with a backslash.
  253. .PP
  254. .UB "Numbers."
  255. A number is a special case of a word, in which the
  256. characters are all digits.  (That definition isn't quite complete, and will
  257. be expanded in the next paragraph.)  A number need not be preceded with a
  258. quotation mark.  (This rule is possible because normally Logo interprets
  259. words without quotation marks as the names of procedures, but there are no
  260. procedures whose names begin with digits.)  If a quotation mark is not
  261. used, then any nondigit terminates the word.
  262. .PP
  263. Actually, numbers may be written in scientific notation.  That is, they can
  264. include signs, decimal points, and a power of 10 by which the number is
  265. multiplied.  This \f2exponent\f1 is indicated by the letter \f3e\f1
  266. followed by the integer power of 10.  The following numbers have the
  267. same value:
  268. .EX
  269. 1000
  270. "1000
  271. 1000.00
  272. 1e3
  273. 10.0e+2
  274. "+1.0e3
  275. 10000e-1
  276. .EC
  277. Notice that if the number begins with a sign it must be quoted.  A quoted
  278. number still must begin with a digit or a sign, not with a
  279. decimal point or a letter \f3e\f1.  (The
  280. letter may be a capital \f3E\f1, by the way.)  If a number is quoted, it
  281. must end with one of the normal word-terminating characters.  A number
  282. which contains only digits (no decimal point or exponent) is called
  283. an \f2integer\f1.  Note that a number with a decimal point is not
  284. considered an integer even if the digits after the decimal point are
  285. all zero.
  286. .PP
  287. Since a number is a word, the usual character-manipulating procedures may
  288. be applied to it.  For example,
  289. .EX
  290. print first 1024
  291. .EC
  292. prints the digit \f31\f1 which is the first character of the number.  In
  293. addition, there are arithmetic procedures which apply specifically to numbers:
  294. .EX
  295. print sum 3 2
  296. .EC
  297. prints the number 5.  These procedures will be listed later.
  298. .PP
  299. .UB "Lists."
  300. A word can be thought of as a list of characters; for
  301. example, the word \f3hello\f1 is a list of five letters.  In Logo it is
  302. possible to manipulate not only lists of characters but also lists of
  303. words, lists of lists of words, and so on.  This is a very powerful capability
  304. which allows very complicated data structures to be manipulated easily.  To
  305. indicate a list in a program, you put square brackets ([ and ]) around the
  306. list, and separate the list elements with spaces.  For example:
  307. .EX
  308. print [This is a list of seven words.]
  309. .EC
  310. A list all of whose elements are words is called a \f2sentence\f1.  Here
  311. is an example of a list which is not a sentence:
  312. .EX
  313. print [[This is a list][of two sentences.]]
  314. .EE
  315. Within a bracketed list, square brackets delimit sub-lists (lists which are
  316. elements of the main list).  The quotation mark, parentheses, and braces
  317. are not considered special within a bracketed list, unlike the rules for
  318. quoted words.  A list may extend over more than one line; that is, if you
  319. have typed an open square bracket ([) and have not yet typed the matching
  320. close square bracket, the Logo instruction is not ended by typing the RETURN
  321. key.
  322. .PP
  323. .UB "Variables."
  324. A variable is an entity which has a \f2name\f1, which
  325. is a word, and a \f2thing\f1 (also called a \f2value\f1), which
  326. can be any Logo object.  Variables
  327. are used to "remember" a computed object for repeated or delayed use
  328. in a program.  In Logo, the most common way that a variable acquires
  329. a value is that it is associated with an input to a user-written
  330. procedure.  In the following example, don't worry about the details
  331. of the format of the procedure, which will be explained later:
  332. .EX
  333. to pff :sentence
  334. print first first :sentence
  335. end
  336. .EC
  337. This is the definition of a command with one input.  The name of the
  338. command is \f3pff\f1.  It has one input because in the "title line" (the
  339. one starting \f3to pff\f1) there is one variable name after the command
  340. name.  The variable whose name is \f3sentence\f1 is associated with the
  341. first (and only, in this case) input to \f3pff\f1.  In the line starting
  342. with the word \f3print\f1, the notation \f3:sentence\f1 means "the \f2thing\f1
  343. of the variable whose \f2name\f1 is \f3sentence\f1".  (To refer to the
  344. name itself, quote it as you would any word.)  If this procedure is used
  345. in a Logo instruction like this:
  346. .EX
  347. pff [This is the poop.]
  348. .EC
  349. then the variable \f3sentence\f1 has the value \f3[This is the poop.]\f1.
  350. .PP
  351. It is also possible to assign a value to a variable by an explicit
  352. Logo instruction.  There is a primitive procedure to do this:
  353. .sp 1
  354. \f3make\f1 \(em Command, two inputs.
  355. .IN
  356. The first input is the name of a variable (that is, it must be a word); the
  357. second is any Logo object.  The effect of the command is to assign the
  358. second input as the value of the variable named by the first input.
  359. .OU
  360. If you are accustomed to programming in a non-procedural language like
  361. BASIC, you should strenuously avoid the temptation to overuse \f3make\f1;
  362. explicit assignment is almost always the wrong thing to do in Logo.  Total
  363. abstention is the best policy for a Logo beginner.
  364. .PP
  365. In Logo, variables are \f2dynamically scoped\f1.  That means that a
  366. variable can "belong to" a particular procedure; such a variable can
  367. be used by that procedure and by any procedure which is used by an
  368. instruction within the procedure, but is not available to the procedure
  369. which invoked the owning procedure.  In other words, such a \f2local\f1
  370. variable comes into being when the owning procedure starts running, and
  371. disappears when that procedure is finished.  It is possible for a
  372. procedure with a local variable to use another procedure with a local
  373. variable of the same name.  In that case, the variable belonging to the
  374. "inner" procedure is the one which is associated with the name as long
  375. as it exists; when the inner procedure is finished, the "hidden"
  376. variable belonging to the outer procedure is again available.
  377. .PP
  378. A variable which is associated with the input to a procedure is
  379. automatically local to that procedure.  Other variables are normally
  380. \f2global\f1: they are "permanent" and do not disappear when the
  381. procedure in which they get their values finish.  It is both possible
  382. and desirable to make such variables local, by an explicit instruction
  383. to that effect:
  384. .sp 1
  385. \f3local\f1 \(em Command, one input.
  386. .IN
  387. The input must be a word.  A variable with that word as its name
  388. is created, local to the currently running procedure (that is,
  389. local to the procedure in which the \f3local\f1 command is used).
  390. .OU
  391. The virtue of local variables is that they make procedures more
  392. independent of one another than they would be if global variables
  393. were used.  In other words, if you use local variables consistently,
  394. then nothing that happens in one procedure will change the values
  395. of variables used in another procedure.  This makes it very much
  396. easier to find program errors.
  397. .PP
  398. .UB "Case insensitivity."
  399. Names of procedures (primitive or user-defined) and names of variables
  400. may be typed in upper or lower case.  They are converted internally to
  401. lower case.  That is, the variables \f3foo\f1 and \f3FOO\f1 are the
  402. same variable.  Letters in other contexts are not converted to lower
  403. case.  For example, \f3equalp\f1 will report that the words \f3foo\f1
  404. and \f3FOO\f1 are not equal.
  405. .PP
  406. Names of procedures and names of variables may include only letters,
  407. digits, and the special characters period (.) and underscore (_).  Also,
  408. names of procedures are limited to 11 characters in some versions of Unix.
  409. .PP
  410. .UB "Primitive procedures to define user procedures."
  411. There are
  412. two ways to define your own procedure.  The first way, using the \f3to\f1
  413. command, is simple to learn but limited in flexibility.  The second way,
  414. using the \f3edit\f1 command, is more complicated to learn, but makes it
  415. easy to make changes in your procedures.  The \f3edit\f1 command uses the
  416. text editing program \f3edt\f1, just as you might use it outside of Logo
  417. to edit a document you want to print.  Once you've learned the special
  418. editing commands in \f3edt\f1, it's easy to use.  The \f3to\f1 command makes
  419. it possible to begin programming in Logo without having learned how to use
  420. \f3edt\f1.  It just lets you type in your procedure definition, without any
  421. provision for correcting errors or changing the definition of the procedure.
  422. It is fast and convenient for short procedures, but limited.
  423. .sp 1
  424. The \f3to\f1 command is unique, in Logo, in that its inputs are interpreted
  425. in a special way.  The inputs aren't \f2evaluated\f1: Logo doesn't run any
  426. procedures you name, or look up the values of any variables, before carrying
  427. out the \f3to\f1 command.  The example below should make this clearer.
  428. .sp 1
  429. \f3to\f1 \(em Command, special form, see below.
  430. .IN
  431. This command takes a variable number of inputs.  The first is the name
  432. of a procedure to be defined.  The rest, if any, must be preceded by
  433. colons, and are the names of variables to be used as inputs to the
  434. procedure.  Logo responds to the \f3to\f1 command by printing a
  435. "greater than" sign (>) prompt, to show you that you are defining a procedure
  436. rather than entering commands to be executed immediately.  You type
  437. the instruction lines which make up the definition.  When
  438. you are done with the definition, type the special word \f3end\f1 on
  439. a line by itself.  For example:
  440. .sp 1
  441. .nf
  442. \f3\z_?to twoprint :thing
  443. \z_>print :thing
  444. \z_>print :thing
  445. \z_>end
  446. \z_?\f1
  447. .fi
  448. .sp 1
  449. This example shows the definition of a procedure named \f3twoprint\f1,
  450. which has one input, named \f3thing\f1.  The procedure you are defining
  451. with the \f3to\f1 command must not already be defined.
  452. .OU
  453. \f3edit\f1 \(em Command, zero or one input.  Abbreviation: \f3ed\f1
  454. .IN
  455. The input to this command must be a word, which is the name of a procedure,
  456. or a list of words, each of which is the name of a procedure.
  457. (Unlike the \f3to\f1 command, but like all other Logo procedures, the
  458. \f3edit\f1 command evaluates its input, so you must use a quotation mark
  459. before the procedure name, if only one is given, to indicate
  460. that it is the name itself which is
  461. the input to \f3edit\f1; otherwise Logo would actually run the procedure
  462. to calculate the input to \f3edit\f1.)  The procedure you name may or may
  463. not already be defined.  Logo responds to the \f3edit\f1 command by running
  464. the text editor \f3edt\f1, editing the definition of the procedure(s) named in
  465. its input.  (If a procedure was not previously defined, Logo creates an
  466. initial definition for it which contains only a title line and the end line.)
  467. You then edit the definition(s) with \f3edt\f1.  When you write the file and
  468. leave \f3edt\f1, Logo will use the edited file as the definition(s) of the
  469. procedure(s).  You must not put anything in the file except procedure
  470. definitions; in other words, every nonempty line in the file must be between
  471. a "to" line and an "end" line.
  472. .sp 1
  473. If the \f3edit\f1 command is given with no input, \f3edt\f1 is given the same
  474. file as from the last time you used the \f3edit\f1 command.  This is a
  475. convenience for editing the same procedure(s) repeatedly.
  476. .sp 1
  477. If, while editing, you change your mind and want to leave \f3edt\f1
  478. without redefining anything, use the command \f3ESC ^Z\f1 instead of
  479. the normal \f3^Z\f1.  This special way of leaving \f3edt\f1 tells Logo
  480. not to redefine your procedures.  You have the choice, before exiting
  481. \f3edt\f1, of writing or not writing the temporary file which contains
  482. the definitions.  If you don't write the file, another \f3edit\f1 command
  483. with no input will re-read the previous contents of the temporary file;
  484. if you do, another \f3edit\f1 will re-read the new version.
  485. .sp 1
  486. If your Unix environment contains a variable named EDITOR, the contents of
  487. that variable is used as the name of the text editor program instead of
  488. the standard \f3edt\f1.  The variable can contain a full pathname, or just
  489. a program name if the program can be found in /bin or /usr/bin.  Your favorite
  490. editor may not have a facility like \f3edt\f1's ESC ^Z to abort redefinition.
  491. .OU
  492. \f3show\f1 \(em Command, one input.  Abbreviation: \f3po\f1
  493. .IN
  494. The input to this command is a word or a list of words.  Each word must be
  495. the name of a procedure.  The command prints out the definition(s) of the
  496. procedure(s) on your terminal.  (The abbreviation \f3po\f1 stands for
  497. \f3printout\f1, which is the name used for this command in some other versions
  498. of Logo.)
  499. .OU
  500. \f3pots\f1 \(em Command, no inputs.
  501. .IN
  502. This command types at your terminal the title lines of all procedures
  503. you've defined.  The name is an abbreviation for "print out titles".
  504. .OU
  505. \f3erase\f1 \(em Command, one input.  Abbreviation: \f3er\f1
  506. .IN
  507. As for the \f3show\f1 command, the input is either a word, naming one
  508. procedure, or a list of words, naming more than one.  The named procedures
  509. are erased, so that they are no longer defined.
  510. .OU
  511. .ti 5
  512. .UB "Primitive procedures to manipulate words and lists."
  513. There are
  514. primitive procedures to print text objects on the terminal, to read
  515. them from the terminal, to combine them into larger objects, to split
  516. them into smaller objects, and to determine their size and nature:
  517. .sp 1
  518. \f3print\f1 \(em Command, one input.  Abbreviation: \f3pr\f1
  519. .IN
  520. The input, which may be a word or a list, is printed on the terminal,
  521. followed by a new line character.  (That is, the terminal is positioned
  522. at the beginning of a new line after printing the object.)  If the
  523. object is a list, any sub-lists are delimited by square brackets, but
  524. the entire object is not delimited by brackets.
  525. .OU
  526. \f3type\f1 \(em Command, one input.
  527. .IN
  528. The input, which may be a word or a list, is printed on the terminal,
  529. \f2without\f1 a new line character.  (That is, the terminal remains
  530. positioned at the end of the object after printing it.)  Brackets
  531. are used as with the \f3print\f1 command.
  532. .OU
  533. \f3fprint\f1 \(em Command, one input.  Abbreviation: \f3fp\f1
  534. .IN
  535. The input is printed as by the \f3print\f1 command, except that if it
  536. is a list (as opposed to a word) it is enclosed in square brackets.  The
  537. name of the command is short for "full print".
  538. .OU
  539. \f3ftype\f1 \(em Command, one input.  Abbreviation: \f3fty\f1
  540. .IN
  541. The input is printed as by the \f3type\f1 command, except that if it
  542. is a list, it is enclosed in square brackets.
  543. .OU
  544. \f3readlist\f1 \(em Operation, no inputs.  Abbreviation: \f3rl\f1
  545. .IN
  546. Logo waits
  547. for a line to be typed by the user.  The contents of the line are made
  548. into a list, as though typed within square brackets as part of a Logo
  549. instruction.  (The user should not actually type brackets around the
  550. line, unless s/he desires a list of one element, which is a list
  551. itself.)  That list is the output from the operation.
  552. .OU
  553. \f3request\f1 \(em Operation, no inputs.
  554. .IN
  555. A question mark is printed on the terminal as a prompt.  Then Logo waits
  556. for a line to be typed by the user, as for \f3readlist\f1.
  557. .OU
  558. \f3word\f1 \(em Operation, two inputs.
  559. .IN
  560. The two inputs must be words.  The output is a word which is the
  561. concatenation of the two inputs.  There is no space or other
  562. separation of the two inputs in the output.
  563. .OU
  564. \f3sentence\f1 \(em Operation, two inputs.  Abbreviation: \f3se\f1
  565. .IN
  566. The two inputs may be words or lists.  The output is a list formed
  567. from the two inputs in this way: if either input is a word, that
  568. word becomes a member of the output list; if either input is a
  569. list, the \f2members\f1 of that input become members of the
  570. output.  Here are some examples:
  571. .EX
  572. .ta 2i 4i
  573. first input    second input    output
  574. "hello    "test    [hello test]
  575. "goodbye    [cruel world]    [goodbye cruel world]
  576. [a b]    [c d]    [a b c d]
  577. []    "garply    [garply]
  578. .EC
  579. If an input is the empty list, as in the last example above, it
  580. contributes nothing to the output.
  581. .OU
  582. \f3list\f1 \(em Operation, two inputs.
  583. .IN
  584. The output is a list of two elements, namely, the two inputs.  The
  585. inputs may be words or lists.
  586. .OU
  587. \f3fput\f1 \(em Operation, two inputs.
  588. .IN
  589. The first input may be any Logo object; the second must be a list.  The
  590. output is a list which is identical with the second input except that
  591. it has an extra first member, namely, the first input.
  592. .OU
  593. \f3lput\f1 \(em Operation, two inputs.
  594. .IN
  595. The first input may be any Logo object; the second must be a list.  The
  596. output is a list which is identical with the second input except that
  597. it has an extra last member, namely, the first input.
  598. .OU
  599. \f3first\f1 \(em Operation, one input.
  600. .IN
  601. The input may be any non-empty Logo object.  If the input is a list,
  602. the output is its first member.  If the input is a word, the output is
  603. a single-letter word, namely the first letter of the input.  If the
  604. input is empty (a word or list of length zero) an error results.
  605. .OU
  606. \f3last\f1 \(em Operation, one input.
  607. .IN
  608. The input may be any non-empty Logo object.  If the input is a list,
  609. the output is its last member.  If the input is a word, the output is
  610. a single-letter word, namely the last letter of the input.  If the
  611. input is empty (a word or list of length zero) an error results.
  612. .OU
  613. \f3butfirst\f1 \(em Operation, one input.  Abbreviation: \f3bf\f1
  614. .IN
  615. The input may be any non-empty Logo object.  If the input is a list,
  616. the output is a list equal to the input list with the first member
  617. removed.  (If the input list has only one member, the output is
  618. the \f2empty list\f1, a list of zero members.)  If the input is
  619. a word, the output is a word equal to the input word with the
  620. first letter removed.  (If the input is a single-letter word, the
  621. output is the \f2empty word\f1.)  If the input is empty, an
  622. error results.
  623. .OU
  624. \f3butlast\f1 \(em Operation, one input.  Abbreviation: \f3bl\f1
  625. .IN
  626. The input may be any non-empty Logo object.  If the input is a list,
  627. the output is a list equal to the input list with the last member
  628. removed.  (If the input list has only one member, the output is
  629. the \f2empty list\f1, a list of zero members.)  If the input is
  630. a word, the output is a word equal to the input word with the
  631. last letter removed.  (If the input is a single-letter word, the
  632. output is the \f2empty word\f1.)  If the input is empty, an
  633. error results.
  634. .OU
  635. \f3count\f1 \(em Operation, one input.
  636. .IN
  637. The input may be any Logo object.  If the input is a list, the
  638. output is a number indicating the number of members in the list.  (Note:
  639. only top-level members are counted, not members of members.  The count
  640. of the list
  641. .EX
  642. [[This is] [a list]]
  643. .EC
  644. is 2, not 4.)  If the input is a word, the output is the number of
  645. letters (or other characters) in the word.  Remember that in Logo a
  646. number is just a particular kind of word, so the output from \f3count\f1 can
  647. be manipulated like any other Logo word.
  648. .OU
  649. \f3emptyp\f1 \(em Operation (predicate), one input.
  650. .IN
  651. The input can be any Logo object.  The output is the word \f3true\f1 if
  652. the input is of length zero (i.e., it is the empty word or the empty
  653. list).  The output is the word \f3false\f1 otherwise.
  654. .OU
  655. \f3wordp\f1 \(em Operation (predicate), one input.
  656. .IN
  657. The input can be any Logo object.  The output is the word \f3true\f1 if
  658. the input is a word.  The output is the word \f3false\f1 if the input
  659. is a list.
  660. .OU
  661. \f3sentencep\f1 \(em Operation (predicate), one input.
  662. .IN
  663. The input can be any Logo object.  The output is the word \f3true\f1 if
  664. the input is a sentence, i.e., a list of words.  The output is the word
  665. \f3false\f1 if the input is a word, or if any member of the input is a
  666. list.
  667. .OU
  668. \f3is\f1 \(em Operation (predicate), two inputs.
  669. .IN
  670. The inputs can be any Logo objects.  The output is the word \f3true\f1 if
  671. the two inputs are identical.  That is, they must be of the same type
  672. (both words or both lists), they must have the same count, and their
  673. members (if lists) or their characters (if words) must be identical.  The
  674. output is the word \f3false\f1 otherwise.  (Note: this is an exception
  675. to the convention that names of predicates end with the letter "p".)
  676. .OU
  677. \f3memberp\f1 \(em Operation (predicate), two inputs.
  678. .IN
  679. If the second input is a word, the first input must be a word of
  680. length one (a single character), and the output is \f3true\f1 if and
  681. only if the first input is contained in the second as a character.  If
  682. the second input is a list, the first input can be any Logo object,
  683. and the output is \f3true\f1 if and only if the first input is a member
  684. of the second input.  (Note that this is member, not subset.)
  685. .OU
  686. \f3item\f1 \(em Operation, two inputs.  Abbreviation: \f3nth\f1
  687. .IN
  688. The first input must be a positive integer less than or equal to
  689. the \f3count\f1 of the second input.  If the second input is a word,
  690. the output is a word of length one containing the selected character
  691. from the word.  (Items are numbered from 1, not 0.)  If the second input
  692. is a list, the output is the selected member of the list.
  693. .OU
  694. .ti 5
  695. .UB "Primitive procedures for turtles and graphics."
  696. An important
  697. part of the Logo environment is a rich set of applications to which the
  698. computer can be directed.  The most important of these is \f2turtle
  699. geometry\f1, a way of describing paths of motion in a plane which is
  700. well-suited to computer programming.  There are two ways to use the
  701. turtle procedures.  First, you can control a \f2floor turtle\f1, a small
  702. robot which can move one the floor or on a table under computer
  703. control.  Second, you can use a \f2display turtle\f1 to draw pictures
  704. on the TV screen of a graphics terminal.
  705. .PP
  706. Each computer center has a different variety of graphics hardware
  707. available.  Floor turtles are very different from display turtles, but also
  708. each kind of display terminal has different characteristics.  For example,
  709. some terminals can draw in several colors; others can't.  The following
  710. descriptions of graphics primitives explain the "best" case for each one
  711. and mention restrictions on some graphics devices.
  712. .PP
  713. The floor turtle can draw pictures on paper, because it has a pen
  714. attached to its "belly": the underside of the turtle.  Since it is
  715. a mechanical device, however, it is not very precise; the pictures
  716. you get may not be exactly like what your program specifies.  A more
  717. interesting way to use the floor turtle is to take advantage of its
  718. \f2touch sensors\f1.  Switches under the turtle's dome allow the computer
  719. to know when the turtle bumps into an obstacle.  You can use this
  720. information to write programs to get around obstacles or to follow
  721. a maze.
  722. .PP
  723. The display turtle lives on the surface of a TV screen.  It can draw
  724. pictures more precisely than the floor turtle, since it does not
  725. measure distances and angles mechanically.  It is also faster than
  726. the floor turtle.  When using the display turtle, remember that
  727. it interprets commands relative to its own position and direction,
  728. just as the floor turtle does.  The command \f3left\f1, for example,
  729. turns the turtle to its own left, which may or may not be toward
  730. the left side of the TV screen.
  731. .sp 1
  732. \f3turtle\f1 \(em Command, one input.  Abbreviation: \f3tur\f1
  733. .IN
  734. The input is the name of a turtle.  You can only control one turtle
  735. at a time, so using this command a second time releases the turtle
  736. previously selected.  The names of floor turtles are numbers like
  737. \f30\f1 and \f31\f1.  If you are using
  738. a graphics display terminal (not just a text display trminal), you can
  739. control the display turtle by using the word \f3display\f1 (or the
  740. abbreviation \f3dpy\f1) as the turtle name.  (As usual, the word
  741. must be preceded by a quotation mark.)  If you use a graphics primitive
  742. without selecting a turtle, Logo assumes that you want to use the
  743. display turtle.  But once you select a floor turtle, you must say
  744. \f3turtle "display\f1 explicitly to switch to the display.
  745. .sp 1
  746. The word \f3off\f1 as input to the \f3turtle\f1 command releases a floor
  747. turtle, if you have one, or turns off the graphics display if you have
  748. been using the display turtle.  This also happens when you leave Logo.
  749. .OU
  750. \f3forward\f1 \(em Command, one input.  Abbreviation: \f3fd\f1
  751. .IN
  752. The input is a number, the distance you would like the turtle
  753. to move.  For a floor turtle, the unit of distance is however
  754. far the turtle can travel in 1/30 second.  For a display turtle,
  755. the unit is one dot on the TV screen.  (Note: on some displays, one
  756. dot horizontally may not be the same length as one dot vertically.  The
  757. \f3setscrunch\f1 command allows you to control the
  758. relative sizes so that squares come out
  759. square.)  The turtle moves in whatever direction it is pointing
  760. when you use the command.
  761. .OU
  762. \f3back\f1 \(em Command, one input.  Abbreviation: \f3bk\f1
  763. .IN
  764. The input is a number, a distance to move, as in the \f3forward\f1
  765. command.  The difference is that the turtle moves backward, i.e.,
  766. in the direction exactly opposite to the way it's pointing.
  767. .OU
  768. \f3left\f1 \(em Command, one input.  Abbreviation: \f3lt\f1
  769. .IN
  770. The input is a number, the number of degrees of angle through
  771. which the turtle should turn counterclockwise.  This command
  772. does not change the \f2position\f1 of the turtle, but merely
  773. its \f2heading\f1 (the direction in which it points).  The
  774. turn will be only approximately correct for the floor turtle,
  775. because of mechanical errors.  For the display turtle, the
  776. angle will be perfectly reproducible, although it may not look
  777. quite right on the screen because of the difference in size
  778. between horizontal and vertical dots.  Nevertheless, a display
  779. turtle program will work in the sense that when the turtle is
  780. supposed to return to its starting point, it will do so.
  781. .OU
  782. \f3right\f1 \(em Command, one input.  Abbreviation: \f3rt\f1
  783. .IN
  784. The input is a number; the turtle turns through the specified
  785. number of degrees clockwise.
  786. .OU
  787. \f3penup\f1 \(em Command, no inputs.  Abbreviation: \f3pu\f1
  788. .IN
  789. This command tells the turtle to raise its pen from the paper,
  790. so that it does not leave a trace when it moves.  In the case
  791. of the display turtle, there is no physical pen to move
  792. mechanically, but the effect is the same: any \f3forward\f1 or
  793. \f3back\f1 commands after this point do not draw a line.  The
  794. floor turtle starts with its pen up; the display turtle starts
  795. with its pen down.  Note: the floor turtle will not move on
  796. the carpet correctly with its pen down; put it on a smooth
  797. surface if you want to draw pictures.
  798. .OU
  799.