Functions and Procedures
Each line is made up of function calls, or subroutines in programming terminology, of which there are two types:
- commands (which do something—effects—but do not return a value) like
print
. - operations (which just return a value, its output) like
sum
,first
orreadlist
.
A command is similar to a Pascal procedure, and an operation is similar to a Pascal function. (See also: command-query separation, where a query is an operation in Logo). A special subset of operations, called predicates, which just output the word true
or false
, are conventionally written with a final p
. Examples include emptyp
, wordp
, and listp
.
- Expressions can be primitives, or can be defined by the user.
- Expressions can take zero, one or more parameters.
Procedures can be defined on the command line, using the TO END pair:
TO CHAIR REPEAT 4 FD 200 ENDHowever, in some early Logos the procedure is limited to the physical line length of the input device.
All Logos can invoke an Editor, usually by EDALL. In the editor, procedures may be written over many lines, as nothing is interpreted until the edit is complete.
EDALL TO CHAIR REPEAT 4 FD 200 ENDThe new word is saved into the available vocabulary, but the definition will be lost once the Logo session is over. Internally procedures are words and in this case, any time CHAIR
is entered, the sequence REPEAT 4 FD 200
will be executed. The word CHAIR
can be used as a command; for example, REPEAT 4
would repeat the CHAIR
operation four times.
A WAIT delay between the drawing and the erasing can introduce the illusion of motion:
CS REPEAT 20Read more about this topic: Logo (programming Language), Syntax
Famous quotes containing the words functions and/or procedures:
“When Western people train the mind, the focus is generally on the left hemisphere of the cortex, which is the portion of the brain that is concerned with words and numbers. We enhance the logical, bounded, linear functions of the mind. In the East, exercises of this sort are for the purpose of getting in tune with the unconsciousto get rid of boundaries, not to create them.”
—Edward T. Hall (b. 1914)
“Young children learn in a different manner from that of older children and adults, yet we can teach them many things if we adapt our materials and mode of instruction to their level of ability. But we miseducate young children when we assume that their learning abilities are comparable to those of older children and that they can be taught with materials and with the same instructional procedures appropriate to school-age children.”
—David Elkind (20th century)