1
0
mirror of https://github.com/PDP-10/its.git synced 2026-03-20 08:28:43 +00:00

clogo.manual

A Description of the CLOGO Language and System (ver. 0.4)
This commit is contained in:
Alexey-Slyusar
2018-09-06 18:51:56 +00:00
committed by GitHub
parent af8dbb7601
commit 8ef1a70c00

View File

@@ -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.
<WHO ARE YOU
WHO ARE YOU?
TELL ME SOMETHING.
<WHY SHOULD I
?WHY SHOULD I
?TELL ME SOMETHING.
<ARE YOU SOME KIND OF NUT
ARE YOU SOME KIND OF NUT
TELL ME SOMETHING.
<
. .
. .
. .
The less then sign (<) is typed by the REQUEST command to indicate to
the user that the computer is waitingfor his typing.
17.ASK (one input)
This is similar to REQUEST except that there is an input -
the maximum number of seconds the computer should wait for type-in
to be completed. If time runs out, the out put of the expression
is the empty 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. ???
The followingare all predicates; i.e., they output TRUEor FALSE.
19.IS (two inputs)
This is the most general of the built-in predicates. Most
others could be built out of it.The output of the expression
is"TRUE" if the things expressed by the two inputsare identical,
letter for letter; otherwiseits output is "FALSE".
IS "CAT" "CAT" is "TRUE"
IS 03 is 3 is "FALSE"
IS LAST OF 03 FIRST OF 3 is "TRUE"
20.EMPTYP (one input)
Its output is "TRUE" if the inputis the empty word.
It is"FALSE" otherwise.
EMPTYP OF :X has the same effect as
IS :X "" or
IS :X :EMPTY ???
21.ZEROP (one input)
The input must express a number, otherwise there is an error.
If the input is equal to 0 (+0, -0, 00, etc.), the output of the
expression is "TRUE". If the input is a non-zero number, the output
of the expression is "FALSE".
22.WORDP (one input)
WORDP outputs "TRUE" if its input is a word (not a sentence).
It outputs "FALSE" otherwise.
23.SENTENCEP (one input)
Like WORDP, except it outputs "TRUE" if the input is a
sentence. SENTENCEP and WORDP both output "TRUE" for the empty
word.For any other input their outputs are opposite.
24.NUMBERP (one input)
NUMBERP outputs "TRUE" if its input is a number in standard
form (that is, 123, +17, -000 give "TRUE", while A37, 7+8, ++3,
7.5 give "FALSE"). NUMBERP outputs "TRUE" for precisely those
things which are legal inputs for SUM, DIFFERENCE, ZEROP,
GREATERP, MAXIMUM, and MINIMUM.
25.GREATERP (two inputs)
The inputs must be numbers. GREATERP outputs "TRUE" if the
first input is larger than the second. It outputs "FALSE" if
the first is less than or equal to the second.
1.8 List of Elementary Commands
1.TO
This command indicates the beginning of a procedure defini
-tion. Immediately following the TO on the same instruction line
is the name of the procedure being defined (this must be a word,
not a sentence) and the names of its inputs, if it has any.
2.END (no inputs)
This indicates the completion of a procedure definition.
3.OUTPUT (one input)
This command causes a procedure to output the LOGO word or
sentence specified in its input.It can only be used within the
definition of a procedure.When the procedure is running and the
OUTPUT command is encountered, its input becomes the output of
the procedure. The procedure then stops and LOGO proceeds with
its program by running the instruction that called this
procedure.
4.STOP (no input)
Like the command OUTPUT, STOP causes a procedure to stop
(but without causing it to output). Again, as with OUTPUT, the
program then goes on with the instruction that invoked this
procedure.
5.GO TO LINE (one input)
Only used within the definition of a procedure.The input
must be the number of a line in that procedure (or an operation
whose output is such a number). When the procedure runs, execu-
tion of the GO TO LINE command causes the computer to execute
its next instructions in numerical sequence beginning with the
line referred to in the command's input (instead of continuing
in its current numerical sequence).
6.LOCAL (one input)
Only used within a procedure definition. The command causes
its input to become a localname as in the case with procedure
inputs. (See Section 1.6 for detailed discussion.)
7.TEST (one input)
The input must either beone of the two words "TRUE" or
"FALSE" or an operation which outputsone of them. The result
of the command is to set the "truth flag" either to true or
false. The "truth flag" is automatically local to every proce-
dure and is initially set to true.
8.IF TRUE (one input)
Here the input may bea command or an operation. The status
of the truth flag is tested and the input isexecuted if the flag
is true.
9.IF FALSE (one input)
Like IF TRUE, except that its input is executedif the flag
is false.
10.GOODBYE (no inputs)
Disconnects the user from the computer and turns off his
console.
11.PRINT (one input)
Causes the input to be typed on the console followedby a
carriage return - line feed.
12.TYPE (one input)
Like PRINT but without the final carriage return - line feed.
TYPE facilitates the typing of a series of printouts on a single
line.
13.MAKE (two inputs)
The first input becomes the name of the second input, as
discussed in detail in Section 1.6.
14.DO (one input)
The input must be a LOGO instruction. The DO command causes
this instruction to be executed.
15.RESET CLOCK (no inputs)
Causes a special LOGO one-second counter, CLOCK, to be reset
to zero. CLOCK is started off at zero when a user starts up LOGO.
It is incremented automatically.
16.WAIT (one input)
The input must be a number.The command causes the computer
to pause that number of seconds.Pauses of more than 24 hours
are illegal.
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.
2.1 Editing
After a procedure has been defined and run, it often becomes necessary to make some changes in its definition. This can be done using the command EDIT. To illustrate the use of EDIT,consider the following definition of the procedure REVERSE.
?TO REVERSE :Y
>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