From 9c283c488371d514622c6613f7e6bb8b09eb819a Mon Sep 17 00:00:00 2001 From: Alexey-Slyusar <42380964+Alexey-Slyusar@users.noreply.github.com> Date: Sat, 8 Sep 2018 16:55:33 +0000 Subject: [PATCH] CLOGO.MANUAL A Description of the CLOGO Language and System (ver. 0.5) --- doc/_info_/clogo.manual | 299 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 278 insertions(+), 21 deletions(-) diff --git a/doc/_info_/clogo.manual b/doc/_info_/clogo.manual index c7b629eb..1f2fd451 100644 --- a/doc/_info_/clogo.manual +++ b/doc/_info_/clogo.manual @@ -1,5 +1,5 @@ -A Description of the CLOGO Language and System (ver. 0.4) +A Description of the CLOGO Language and System (ver. 0.5) 0. Abstract ----------- @@ -381,6 +381,7 @@ Once procedures like DOUBLE or DUB are defined, they are virtually indistinguish 1.5 Recursion + pIn fact, since a defined procedure can be used just like a built-in procedure, it can even be used in its own definition. Sometimes this gets nowhere - ?TO TYPEALOT @@ -497,7 +498,7 @@ 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" + ?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". @@ -507,7 +508,7 @@ The instruction LIST ALL NAMES causes all names with non-empty things to be list ?LIST ALL NAMES :ALPHA IS "BETTY" :BETTY IS "SAPLE" - "DOT BETTY" IS "APLE" ;;need to be checked + ;DOT BETTY; IS "APLE" ? 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 @@ -527,11 +528,11 @@ The slow form is useful in emphasizing the relation between NAME and THING durin The other method of changing names is by specifying inputs inprocedures. ?TO SHOW :X - >10 PRINT "NOWI AM GOING TO PRINT :X" + >10 PRINT "NOW I AM GOING TO PRINT :X" >20 PRINT :X >END >SHOW "CATS" - NOWIAM GOING TO PRINT :X + NOW I AM GOING TO PRINT :X CATS ? @@ -552,11 +553,12 @@ While the procedure SHOW is running, :X stands for "CATS". When it stops, howeve ? 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" + NAME:"X" THING: WORD OF "CAT" AND :X >50 PRINT :X >END @@ -572,6 +574,7 @@ A name which is in force only during the running time of some procedure is calle ? 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" @@ -579,7 +582,7 @@ One reason for this somewhat complicated situation is that it permits the user t >20 MAKE NAME: "SECOND TERM" THING: PRODUCT OF "3" AND :X - >30 OUTPUT SUM OF :FIRST_TERM AND :SECOND_TERM + >30 OUTPUT SUM OF ;FIRST TERM; AND ;SECOND TERM; >END QUADRATIC DEFINED ?PRINT QUADRATIC OF "4" @@ -599,7 +602,7 @@ In this case the problem could have been gotten around simply byusing different >40 MAKE NAME:"NEW END" THING: REVERSE OF BUTLAST OF :X - >50 OUTPUT WORD OF :NEW_BEGINNING AND :NEW_END + >50 OUTPUT WORD OF ;NEW BEGINNING; AND ;NEW END; >END REVERSE DEFINED ?PRINT REVERSE OF "CAT" @@ -624,6 +627,7 @@ The problem here is at line 30 and at line 40. :NEW_BEGINNING isn't an input to 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. @@ -757,11 +761,9 @@ There is one tricky point here. BUTFIRST of a two-word sentenceis the last word 18.THING (one input) The output of this expression is the thing named by the input. - THING OF "X" is exactly the same as :X.The utility of THING - lies in expressions like THING OF :X (the analogous ::X is illegal) - and THING OF WORD OF :X AND :Y. ??? + THING OF "X" is exactly the same as :X. -The followingare all predicates; i.e., they output TRUEor FALSE. +The followingare all predicates; i.e., they output TRUE or FALSE. 19.IS (two inputs) This is the most general of the built-in predicates. Most @@ -777,7 +779,7 @@ The followingare all predicates; i.e., they output TRUEor FALSE. It is"FALSE" otherwise. EMPTYP OF :X has the same effect as IS :X "" or - IS :X :EMPTY ??? + IS :X :EMPTY 21.ZEROP (one input) The input must express a number, otherwise there is an error. @@ -901,6 +903,9 @@ The followingare all predicates; i.e., they output TRUEor FALSE. 2.The LOGO System ----------------- + + + We distinguish the LOGO system from the LOGO languageas follows. The language consists of all those things (the operations, commands, names, etc., and the rules governing their relationsand usage) necessary to express an executable LOGO program. The system consists of those additional things - features and facilities - that aid a user in his programming work at the computer terminal. These have to do mainly with program manipulation and debugging capabilities such as listing, editing,storing, and retrieving. @@ -916,7 +921,7 @@ After a procedure has been defined and run, it often becomes necessary to make s 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. +There are three errors in this definition. First, 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 @@ -946,25 +951,269 @@ After LOGO acknowledges the redefinition of REVERSE, we can tryout the modified 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 +>20 ^N OUTPUT ^NWORD ^NOF ^NLAST ^NOF ^N:X ^NAND ^NREVERSE ^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. +(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. - - - -2.1 Editing - 2.2 Abbreviating + +To reduce the user's typing, the computer recognizes short formsfor most commands. These are called abbreviations. + + ?P S OF "CAT" AND "DOG" + CAT DOG + +P is the abbreviation for PRINT and S for SENTENCE. The long forms are substituted internally for the abbreviations as soon as the abbreviations are typed in. Thus, if you were to type in a procedure definition using abbreviations and then list it, the computer would type it back to you in expanded form. + +Also, text included between quotation marks or slashes is notinterpreted as an abbreviation. Thus, + ?P "P P P S" + P P P S + ? + +The user can make his own abbreviations with the command ABBREVIATE (two inputs). The first input can be any LOGO thing. The second must be a word which will become the abbreviation. + + ?ABBREVIATE "PRINT WORD" "PW" + PW "HELLO" "!" + HELLO! + ? + 2.3 Listing and Erasing + +The command LIST causes the computer to type out, in standard format, the entity or entities specified by its input. The command has several forms. + +1.LIST (one input) + +The input here must be a procedure name.The computer types the definition of the procedure. + + ?LIST REVERSE + TO REVERSE :X + 10 TEST EMPTYP :X + 20 IF TRUE OUTPUT "EMPTY" + 30 OUTPUT WORD OF LAST OF :X AND REVERSE OF BUTLAST OF :X + END + ? + + +2.LIST ALL PROCEDURES + +The computer lists all the procedure definitions currently inthe student's workspace (see Section 2.5). + +3.LIST CONTENTS + +Lists the title line of every defined procedure currently in the student's workspace. + + ?LIST CONTENTS + TO REVERSE :X + TO PRODUCT :X AND :Y + TO FACTORIAL :N + +4.LIST ALL NAMES + +All names whose things are not the empty word are listed. + + ?LIST ALL NAMES + :X IS "OLD THING" + :CAT IS "HOTDOG" + :N IS "15" + +5.LIST ALL ABBREVIATIONS + +All student-defined abbreviations are listed. + + ?LIST ALL ABBREVIATIONS + + R: REVERSE + PR: PRODUCT + !: FACTORIAL + +: PRINT SUM + ? + +6.LIST ALL + +All procedures, all names, and all abbreviations are listed. + +The following two list instructions have meaning onlywhile aprocedure is being defined or edited. + + + - - - + +The command ERASE provides a means of removingmaterial from thecomputer's memory.The forms of the ERASE command are similarto those for LIST. + +1.ERASE (one input) + +The input must be a procedure name, as with LIST.Thatprocedure definition is erased. + +2.ERASE ALL PROCEDURES + +All procedure definitions currently inthe student's workspace are erased. + +3.ERASE ALL NAMES + +All names are given empty things. + +4.ERASE ALL ABBREVIATIONS + +All abbreviations are forgotten. + +5.ERASE ABBREVIATION (one input) + +Just that specific abbreviation is erased. + ?ERASE ABBREVIATION "PW" + ? + +PW would no longer be an abbreviation for PRINT WORD. + +6.ERASE ALL + +The computer is restored to its initial state, as it was when the student first entered. + +The following instruction is used only while defining or editing a procedure. + +7.ERASE LINE (one input) + +The input must be a number.The indicated line is deleted fromthe procedure definition. +Two special commands indirectly involve listing. The command BURY makes a procedure unlistable. This command can only beused by a teacher (the computer recognizes a teacher by his password). It has proved useful in presenting assignments.Theteacher writes a procedure, buries it, and then asks the studentsto write a procedure that has the same effect as the buried one.DIGUP (also for use of the teacher only) undoes the effect ofBURY. + +8.LIST TITLE + +The title line of the procedure is listed. + +9.LIST LINE (one input) + +The input must be a number. That line is listed. + + 2.4 Debugging + +The LOGO system has built-in aids to help students find the bugs in the their programs. A bug will have one of two effects. It may cause the computer to try to execute an illegal instruction or it may direct the execution of instructions that are legal but which produce a wrong answer or no answer at all, e.g., it may put the computer in a loop that never ends. +In the first case, the computer immediately stops doing instructions and types out a diagnostic message describing the error and telling where it occurred. (Some typical diagnostic messagesare listed at the end of this section.) Here is an example ofthe first kind of bug. Let us define a procedure GREET. + ?TO GREET :X + >10 PRINT SENTENCE OF "HELLO," AND :X + >20 PRONT "HOW ARE YOU?" + >30 PRINT "SEE YOU LATER" + >END + GREET DEFINED + +Now let's run it. + + GREET "JOHN" + HELLO, JOHN + PRONT NEEDS A MEANING. + I WAS AT LINE 20 IN GREET + +There was a bug. The diagnostic message tells us what is wrong and where the error was found. So we fix the bug. + + ?EDIT GREET + >20 PRINT "HOW ARE YOU" + >END + GREET DEFINED + +We try again. + ?GREET "JOHN" + HELLO, JOHN + HOW ARE YOU + SEE YOU LATER + ? + +This time GREET works. + +When the procedure GREET was being defined, the computer didn't object when line 20 was typed in, nor should it have. It is possible that a procedure PRONT might have been written later, after GREET was defined. And, if the student had defined PRONT, before running GREET, for example + + ?TO PRONT :X + >10 PRINT :X + >END + PRONT DEFINED + +GREET would have worked perfectly well. + +In the above example, the computer's diagnostic message pointed to the source of the error and thus was directly helpful. Often ,however, we get situations where the illegal instruction isn't the cause of the error at all. For example, in the course of running a procedurethe computer may say + + DIFFERENCE OF "AB" AND "1"? INPUTS MUST BE NUMBERS. + I WAS AT LINE 30 OF PRODUCT. + +And when we look at PRODUCT we see something like + + 30 OUTPUT SUM OF :X AND PRODUCT OF :X AND DIFFERENCE OF :Y AND "1" + +The error is that somehow :Y must have become "AB" instead of a number. But, the location of the error isn't line 30. :Y is being set up incorrectly somewhere else. This type of error then is really like the second kind mentioned above.The computer gets past it without performing an illegal instruction but it produces a result which shows up as faulty later when the computer is performing another instruction, perhaps in a different procedure. In this case the diagnostic is less helpful and more work must be done to find the error. + +The most powerful method for pinpointing errors of this sort is to plant, at strategic spots in the procedures, lines of the form PRINT SENTENCE OF "AT LINE--- IN PROCEDURE --- :Y IS" AND :Y with the blanks filled in appropriately. Now, when the procedures run, they will leave a trace showing the things of "Y" and how they change. Using this trace, it is easy to see where :Y goes wrong. After the bug is fixed, the tracing linescan be erased. To reduce the editing work required to put inand subsequently remove tracing lines, the LOGO system has the built-in facility of tracing title lines and output lines. The operation of the TRACE command is illustrated in the following example, another REVERSE procedure. + + ?TO REVERSE :X AND :Y (:Y should startas the empty word) + >10 TEST EMPTYP :X + >20 IF TRUE OUTPUT :Y + >30 OUTPUT REVERSE OF BUTLAST OF :X AND WORD OF :Y AND + LAST OF :X + >END + REVERSE DEFINED + +This is a correct procedure. + + PRINT REVERSE OF "CAT" AND ""TAC + +This is how we put a TRACE on it. + + ?TRACE REVERSE + +This is what happens when we run a traced procedure. + ?PRINT REVERSE OF "CAT" AND "" + REVERSE OF "CAT" AND "" + REVERSE OF "CA" AND "T" + REVERSE OF "C" AND "TA" + REVERSE OF "" AND "TAC" + REVERSE OUTPUTS "TAC" + REVERSE OUTPUTS "TAC" + REVERSE OUTPUTS "TAC" + REVERSE OUTPUTS "TAC" + TAC + +To remove the TRACE on REVERSE we simply write + + ?ERASE TRACE REVERSE + ? + +The LOGO commands TRACE ALL PROCEDURES and ERASE ALL TRACES are useful with programs involving several procedures, and particularly with recursively chained procedures. + +Diagnostic Messages + +There are about 100 diagnostic messages. The following are some typical ones. + +THAT ISN'T YOUR FILE. +MEANINGLESS CHARACTER. +IF WHAT?(IF TRUE OR IF FALSE ONLY). +THE TITLE MUST BEGIN WITH TO. +END WHAT? +YOU'RE NOT DEFINING ANYTHING. +GO WHERE? +LIST WHAT? +ERASE WHAT? +YOU CAN'T TRACE BUILT-IN OPERATIONS. +DON'T USE THE EMPTY WORD FOR A NAME. +THE INPUTS TO WORD MAY NOT BESENTENCES. +ILLEGAL COMMAND. +THE INPUT TO TEST MUST BE A PREDICATE. +YOU FORGOT THE LINE NUMBER. + +The following four comments mean that thenumber of inputs foundon the line and the numberneeded didn't match. The exact comment chosen depends on the particular parsing error. + +SOMETHING EXTRA +SOMETHING MISSING +SOMETHING EXTRA IN A NAME (with the MAKE command) +SOMETHING EXTRA IN A THING '' '' '' '' + + 2.5 Filing +An important aspect of writing programs in LOGO is building complex programs from simpler ones. For example, assume a MULTIPLY procedure has been written. Sometime later the student may write a FACTORIAL procedure using the MULTIPLY. Then, perhaps, a PROBABILITY procedure using FACTORIAL and other procedures. Finally, PROBABILITY might end up in some game-playing strategy program. +LOGO contains a facility for filing a way procedure definitions. The basic unit of a LOGO file is an entry. This is like a single file folder and may contain procedure definitions, names, andabbreviations. In a well organized file, each entry contains a related group of procedures, names, and abbreviations (for example, those that are used for playing NIM,or those used insolving linear equations). +An entry has a name which consists of two words. The first wordis the file name and is common to all the entries in a file (it is often the name of the student who owns the file). The second word usually describes the entry and distinguishes it from other entries in the same file. Examples of names are JIM EQUATIONS, NANCY RANDOMSENT, SCOTT NIM. +An entry is created by the command SAVE. The entry contain severything that would be listed by LIST ALL, that is, all procedures, all names, and all abbreviations made by the studentduring this session. This material, comprising everything inhis active area of the computer's memory, is called the student's workspace. + + 3.Summary of LOGO Operations, Commands, Special Names, and Abbreviations @@ -1053,6 +1302,14 @@ RESET RESET CLOCK SETS CLOCK TO ZERO ABBREVIATE SETS UP ABBREVIATIONS TEST SETS TRUTH FLAG + NAMES + +:EMPTY THE EMPTY THING +:CONTENTS A SENTENCE OF DEFINED PROCEDURE NAMES +:BLANK A BLANK SPACE +:QUOTE A QUOTE MARK +:SKIP A NEW LINE + ABBREVIATIONS ABB ABBREVIATION