From 8ef1a70c0039b7e64e820a4451c05ebebcd6973f Mon Sep 17 00:00:00 2001 From: Alexey-Slyusar <42380964+Alexey-Slyusar@users.noreply.github.com> Date: Thu, 6 Sep 2018 18:51:56 +0000 Subject: [PATCH] clogo.manual A Description of the CLOGO Language and System (ver. 0.4) --- doc/_info_/clogo.manual | 497 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 494 insertions(+), 3 deletions(-) diff --git a/doc/_info_/clogo.manual b/doc/_info_/clogo.manual index 12697937..c7b629eb 100644 --- a/doc/_info_/clogo.manual +++ b/doc/_info_/clogo.manual @@ -1,14 +1,18 @@ -A Description of the CLOGO Language and System (ver. 0.2) +A Description of the CLOGO Language and System (ver. 0.4) 0. Abstract +----------- This document is based on Bolt Beranek and Newman, Inc., Report no.1889 "Programming-Languages as a Conceptual Framework for Teaching Mathematics" (Feurzeig, Papert at al., 1969). The description is relevant for CLOGO version 44 available on PDP-10/its. https://github.com/PDP-10/its. 1.The LOGO Language +------------------- + 1.1 Things, Operations, Commands, and Names + There are two kinds of LOGO things -- WORDS and SENTENCES. WORDS @@ -124,7 +128,7 @@ A shorthand way of writing THING OF "ANYTHING" is :ANYTHING. Thus, the effect of NAMING ------ -The LOGO command MAKE is used to construct a LOGO THING and give it a NAME. The following example shows how a student could use it to assign "JANE" as the name of "GIRL". +The LOGO command MAKE is used to construct a LOGO THING and give it a NAME. The following example shows how a user could use it to assign "JANE" as the name of "GIRL". MAKE ---- @@ -133,7 +137,7 @@ MAKE THING: "GIRL" ----- -The student's typing is underscored to distinguish it from LOGO's responses. +The user's typing is underscored to distinguish it from LOGO's responses. More typically, one names a more complex construction, as follows: @@ -458,10 +462,497 @@ Finally, it is not necessary to prefix the instruction in line 30 with the comma 1.6 Local and Global Names +In LOGO everything except the empty word is the name of something. Until they are otherwise assigned, almost all LOGO things name the empty word. + + ?PRINT :SOMETHING + (The computer prints the empty word by skipping a line.) + ?PRINT :AN_OTHER_THING + + ?PRINT :A + + ?PRINT "" + THE EMPTY WORD CANNOT BE A NAME. + ? + +The few exceptions, which don't initially name the empty word, are built-in LOGO names for special things such as the console bell, the blank character, etc. These are listed in Part 3 (Need to be checked). + +Names may have their things changed in two ways.The most direct way is by means of the instruction MAKE. + + ?MAKE + NAME: "ALPHA" + THING: "BETTY" + ?PRINT :ALPHA + BETTY + +The text following the words NAME: and THING: may be anything that has an output, that is a literal (like "ALPHA"),a name(like :JKS),or an operation with its inputs. + ?MAKE + NAME: :ALPHA + THING: "SAPLE" + ?PRINT :BETTY + SAPLE + ? + +The name here is :ALPHA, that is the LOGO thing "BETTY". + + ?MAKE + NAME: SENTENCE OF "DOT" AND :ALPHA + THING: BUTFIRST OF :BETTY + ?PRINT "DOT BETTY" + APLE + +Here the name of SENTENCE OF "DOT" AND :ALPHA which is "DOT BETTY" and the thing it names is BUTFIRST OF :BETTY, "APLE". + +The instruction LIST ALL NAMES causes all names with non-empty things to be listed. + + ?LIST ALL NAMES + :ALPHA IS "BETTY" + :BETTY IS "SAPLE" + "DOT BETTY" IS "APLE" ;;need to be checked + ? + +Just as the OF and AND in most instructions are optional, the carriage returns after the command MAKE and before the label THING are optional. The instruction in the form + + ?MAKE(carriage return) + NAME:"BB"(carriage return) + THING:"CABF"(carriage return) + +can also be written with the two inputs on one line. Thus: + + ?MAKE "BB" "CABF"(carriage return) + +The computer doesn't type out NAME: and THING: in this form so it is a little faster to type in. + +The slow form is useful in emphasizing the relation between NAME and THING during the early stages of teaching, however. + +The other method of changing names is by specifying inputs inprocedures. + + ?TO SHOW :X + >10 PRINT "NOWI AM GOING TO PRINT :X" + >20 PRINT :X + >END + >SHOW "CATS" + NOWIAM GOING TO PRINT :X + CATS + ? + +While the procedure SHOW is running, :X stands for "CATS". When it stops, however, the old THING OF "X" is restored. Thus, + + ?PRINT :X + (the empty word) + ?MAKE + NAME:"X" + THING:"OLD THING" + ?PRINT :X + OLD THING + ?SHOW "DOGS" + NOW I AM GOING TO PRINT :X + DOGS + ?PRINT :X + OLD THING + ? + +A name which is in force only during the running time of some procedure is called local tothat procedure. A name that isn't local to any procedure is called global. In the example above, :X ("OLD THING") was global, while :X ("DOGS") was local to SHOW. While a local :X is in force (i.e.,while the procedurefor which it is local is running), all references to :X as a name refer to the local name. + ?TO WORRY :X + >10 PRINT :X + >30 PRINT THING OF "X" + >40 MAKE + NAME:"x" + THING: WORD OF "CAT" AND :X + >50 PRINT :X + >END + WORRY DEFINED + ?PRINT :X + OLD THING + ?WORRY "PIPE" + PIPE + PIPE + CATPIPE + ?PRINT :X + OLD THING + ? + +One reason for this somewhat complicated situation is that it permits the user to forget about the choice of names inside of procedures that he has written. For example, suppose the user had written a procedure to output the product of two numbers and it had a title line TO PRODUCT :X AND :Y. Then, sometime later he wrote another program, called TO QUADRATIC :X, for computing (X+1)X+3X, which uses the procedure PRODUCT in its definition. + ?TO QUADRATIC :X + >10 MAKE + NAME: "FIRST TERM" + THING: PRODUCT OF (SUM OF :X AND "1") AND :X + >20 MAKE + NAME: "SECOND TERM" + THING: PRODUCT OF "3" AND :X + >30 OUTPUT SUM OF :FIRST_TERM AND :SECOND_TERM + >END + QUADRATIC DEFINED + ?PRINT QUADRATIC OF "4" + 32 + ? + +Notice that :X becomes "4" on entering QUADRATIC. In line 10 however PRODUCT OF "5" AND "4" is evaluated and so PRODUCT is run.But that causes :X to become "5" while PRODUCT is running. When PRODUCT is finished, however, we comeback to QUADRATIC, now at line 20 and see another reference to :X, meaning the :X of QUADRATIC ("4"). And, indeed, this is the way things work because the :X in PRODUCT is local tothat procedure and disappears when PRODUCT is finished, leaving the :X of QUADRATICin force. + +In this case the problem could have been gotten around simply byusing different input names for all procedures, a possible, if awkward, maneuver. There is an important case where that won't work, though, and that is inrecursive procedures. There, since the procedure being called is the same procedure as the one being run, the input names are, of course,identical. Here is an example of a recursive procedure that doesn't work properly because some global names are treated as though they were local. + + ?TO REVERSE :X + > 10 TEST EMPTYP OF :X + > 20 IF TRUE OUTPUT :EMPTY + > 30 MAKE + NAME: "NEW BEGINNING" + THING: LAST OF :X + >40 MAKE + NAME:"NEW END" + THING: REVERSE OF BUTLAST OF :X + >50 OUTPUT WORD OF :NEW_BEGINNING AND :NEW_END + >END + REVERSE DEFINED + ?PRINT REVERSE OF "CAT" + TTT + ? + +The problem here is at line 30 and at line 40. :NEW_BEGINNING isn't an input to REVERSE, so it isn't local. Therefore, its thing will change on subsequent calls of REVERSE. The computer does not save the things of global names in each round - it only does that for local names. (The same is true for :NEW_END though in this procedure that doesn't affect the result -- nothing that might change :NEW_END, such as a call to REVERSE, happens after line 40 where :NEW_END is set.) At line 40 another REVERSE is called. In executing this REVERSE procedure, :NEW_BEGINNING will change. REVERSE procedures can, of course, be written to avoid this problem. But this REVERSE procedure can easily be repaired by making :NEW_BEGINNING local to it. There is a command, LOCAL, to do this. LOCAL takes one input, the name that is to be made local to the procedure. + + ?TO REVERSE :X + >5 LOCAL "NEW BEGINNING" + > 10 TEST EMPTYP OF :X + . (same as before) + . + . + + >END + REVERSE DEFINED + ?PRINT REVERSE OF "CAT" + TAC + ? + + 1.7 List of Elementary Operations +1.FIRST (one input) + Its output is the first word of a sentence or the first + letter of a word. + FIRST OF "AB12X!" is "A" + FIRST OF "MOX SED PEAX" is "MOX" + +2.LAST (one input) + Its output is the last word of a sentence or the last letter + of a word; analogous to FIRST. + +3.BUTFIRST (one input) + Its output is all but the first word of a sentence or all + but the first letter of a word. + BUTFIRST OF "AB12X!" is "B12X!" + BUTFIRST OF "MOX SED PEAX" is "SED PEAX" +There is one tricky point here. BUTFIRST of a two-word sentenceis the last word of the sentence. It is a one-word sentence, however, not a word. This can be observed in the expression FIRST OF BUTFIRST OF "THE DOG" which has as its output the word"DOG" since that is the first word of the one-word sentence "DOG" that is the output of BUTFIRST OF "THE DOG". Continuing further,the output of FIRST OF FIRST OF BUTFIRST OF "THE DOG" is theword "D". In practice the output type (word or sentence) almost always works out as the user expects. + +4.BUTLAST (one input) + Analogous to BUTFIRST. + (It is worth noting that the output of BUTFIRST or BUTLAST is the + same type (word or sentence) as its input. On the other hand, + the output of FIRST or LAST is always a word.) + +5.WORD (two inputs) + Both inputs must be words. The output of the expression is + a new word made by concatenating the two inputs. + WORD OF "MO" AND "ZART" is "MOZART". + +6.SENTENCE (two inputs) + Analogous to WORD. Here the inputs may be either words or + sentences and the value is a sentence. + SENTENCE OF "MO" AND "ZART" is "MO ZART" + SENTENCE OF "AB" AND "CD EF" is "AB CD EF" + SENTENCE OF "" AND "APPLE" is "APPLE" + In the last example the output is a one-word sentence again. + +7.COUNT (one input) + The output of the expression is the number of letters in + the input if it is a word or the number of words if it is a + sentence. + COUNT OF "ABC" is "3" + COUNT OF "THE CAT IN THE HAT" is "5" + COUNT OF "" is "0" + +8.SUM (two inputs) + Both inputs must be numbers (i.e., words consisting only of + digits preceded by an optional + or - sign). The output of the + expression is the signed sum of the two inputs, prefixed by a - + sign if the sum is negative. + SUM OF "-5" AND "3" is "-2" + SUM OF "5" AND "-2" is "3" + +9.DIFFERENCE (two inputs) + Analogous to SUM.The output is the result of subtracting + the second input from the first. + DIFFERENCE OF "3" AND "-5" is "8" + +10.MAXIMUM (two inputs) + Analogous to SUM. The output is the larger of the two inputs. + MAXIMUM OF 2 AND 4 is 4. + Integers do not need to be quoted in LOGO. + +11.MINIMUM (two inputs) + Analogous to SUM. The output is the smaller of the two inputs. + +12.RANDOM (no inputs) + The output is a digit between 0 and 9 generated in a pseudo + -random manner. Larger pseudo-random numbers are generated + by concatenation.Thus, + WORD OF RANDOM AND RANDOM, yieldsa random number between + 00 and 99. + +13.DATE (no inputs) + The output is the current date, a word representing month, + day, year.For example,"10/31/1969". + +14.TIME (no inputs) + The output is the current time,a sentence like "1:32 AM". + +15.CLOCK (no inputs) + The output is a number giving the number of seconds + elapsedsince an internal clock was reset. + ?RESET CLOCK + . (some work taking abouthalf an hour) + . + . + ?PRINT CLOCK + 1836 + ?PRINT CLOCK + 1838 + +16.REQUEST (no inputs) + When the computer evaluates the expressionREQUEST, it + pauses to allow the user to type in something (often a requested + answer to a question) at the console. When the typing is + completed (as indicated when theuser types a carriage return), + the output of the expression is thetyped-in text.The following + procedure shows the use of REQUEST. + + ?TO COPYCAT + >10 PRINT "TELL ME SOMETHING." + >20 PRINT REQUEST + >30 COPYCAT + >END + COPYCAT DEFINED + ? + + COPYCAT + TELL ME SOMETHING. + 10 TEST EMPTYP OF :X + >20 OUTPUT WORD OF LAST OF :X AND REVERS OF BUTLAST OF :X + >END + REVERSE DEFINED + ? + +There are three errors in this definition.fFirst, a line is needed between 10 and 20 telling what to do if :X is the emptyword. That can be fixed by the following instructions. + + ?EDIT REVERSE + >15 IF TRUE OUTPUT :EMPTY + + +The first instruction, using the EDIT command, tells LOGO that the definition of REVERSE will be modified. The second instruction defines a new line in the procedure. This line is inserted as number 15 between lines 10 and 20. (Here you see our reason for generally numbering lines 10, 20, 30,...instead of 1, 2,3,... - to leave room for subsequent insertions.) + +The second error is a bug in the title line. There the input is referred to as :Y but elsewhere in the procedure as :X. The title line is changed as follows. + + >TITLE TO REVERSE :X + > + +Last, in line 20 REVERSE is spelled without the final E. We can correct this by simply retyping the line. + + >20 OUTPUT WORD OF LAST OF :X AND REVERSE OF BUTLAST OF :X + +Now we have finished fixing the procedure, so we type END. + + >END + REVERSE DEFINED + +After LOGO acknowledges the redefinition of REVERSE, we can tryout the modified procedure. + ?PRINT REVERSE OF "PITH" + HTIP + ? + +There is a useful feature which could have reduced our work in correcting line 20. The command EDIT LINE (one input) tells LOGO that the user wants to make changes in the line specified. In order to avoid retyping of correct words in the old line being corrected, the computer recognizes the key ^N (indicating the joint striking of the control key and the letter N key on the console) as representing "the next word in the old line". Each time ^N is struck, it causes the next word of the old line to be typed. Thus, in our example (the user's typing is underscored): + +>EDIT LINE 20 +>20 ^N OUTPUT ^NWORD ^NOF ^NLAST ^NOF ^N:X ^NAND ^NREVERS \E ^ROF BUTLAST OF :X + -- -- -- -- -- -- -- -- -- -- +(Since ^N and ^R don't type out anything on the console, the above line looks readable.) The ^R (standing for the rest or remainder of the old line) indicates to LOGO that it is to provide enough ^N's to finish the line. The backslash (\) before the E is used to erase the space the computer typed after REVERS. (In general, the backslash character \ erases the precedingcharacter, \\ erases the two preceding characters, and so on.) Weerases the preceding word (back to the first space) and types a \ for every character it erases. Backslash and We work during all typing, not just during editing. + + + + 2.1 Editing