The Logo Programming Language, a dialect of Lisp, was
designed as a tool for learning. Its features -
modularity, extensibility, flexibility of data types -
follow from this
Although there are some versions of Logo that compile,
it is generally implemented as an interpreted language.
interactivity of this approach provides the user with
feedback on individual instructions, thus aiding in the
learning process. Error messages are descriptive. For
know how to fowad
(The word fowad is not a primitive - one of
Logo's built in words - nor a procedure that you've
inputs to forward
(Now that you've spelled it correctly, Logo knows the
word forward, but can't run your instruction
requires additional information.
(Logo is happy. There's no error message. The turtle
moves forward 100 steps.)
Modularity and Extensibility
Logo programs are usually collections of small
procedures. Generally, procedures are defined by writing
them in a text
editor. The special word to is followed by the
name of the
procedure. Subsequent lines form the procedure definition.
The word end
signals that you're finished.
In our turtle graphics
example we defined a procedure to draw a square
repeat 4 [forward 50 right 90]
and used it as a subprocedure of another procedure
repeat 36 [right 10 square]
Similarly, flower could be a building block of
repeat 25 [set-random-position flower]
No, set-random-position is not a primitive, but
random is and so is setposition (or setpos
or setxy). Or you could write set-random-position
using forward and right with random.
Once a Logo procedure is defined it works like the Logo
primitives. In fact, when you look at Logo programs
there's no way of
knowing which words are primitives and which are
you know that particular Logo implementation. In our language
sample we used the procedure pick
to randomly select an item from a list, for example in the
output pick [Sandy Dale Dana Chris]
In some versions of Logo pick is a primitive
while in others you have to write it yourself. Who
and work the same way in either case.
Logo allows you to build up complex projects in small
steps. Programming in Logo is done by adding to its
teaching it new words in terms of words it already knows.
In this way
it's similar to the way people learn spoken language.
Logo works with words and lists. A Logo word is a
string of characters. A Logo list is an ordered collection
of words and
or lists. Numbers are words, but they're special because
you can do
things like arithmetic with them.
Many programming languages are pretty strict about
wanting to know exactly what kind of data you claim to be
makes things easier for the computer, but harder for the
Before adding a couple of numbers you might have to
they are integers or real numbers. The computer needs to
things. But most people don't think about this so Logo
takes care of it
for you. When asked to do arithmetic Logo just does it.
print 3 + 4
print 3 / 4
If you are unfamiliar with Logo but work in other
programming languages, the following sequence may surprise
print word "3
print 12 +
word "3 "4
Here's a recursive procedure that computes factorials:
if :number = 1 [output 1]
output :number * factorial :number - 1
Here's a procedure to reverse a list of words:
ifelse equal? count
[apples and pears]
pears and apples
You might also want to take a look at Brian Harvey's
interesting Logo sample.
The features just illustrated are common to all
versions of Logo. Some Logo implementations include
There was an object-oriented Logo called Object Logo
for the Macintosh.
MicroWorlds Logo includes multi-tasking so that several
independent processes may be run simultaneously. The same
in the software for Control Lab, a LEGO Logo product. An
massively parallel Logo is StarLogo.
In a traditional Logo the command to the turtle
[forward 1 right 1]
would take a while to execute. The instruction
[forward 1 right 1] print "HELLO
would cause the word HELLO to appear after the
turtle was done moving.
In MicroWorlds Logo typing
[repeat 9999 [forward 1 right 1]] print "HELLO
would start the turtle going. The word HELLO
would appear as soon as the first process is launched. Or
[forward 1 right 1] print "HELLO
would initiate a process that would continue until you
stopped it. Again, the word HELLO would appear as
soon as the
turtle process is initiated.
Find out More
To find out more about the Logo programming language
look at Brian Harvey's three-volume epic Computer
Science Logo Style and
Michael Friendly's Advanced
If you do not have Logo and want to get started, you
might want look at our Logo
page. Or, you can just download UCBLogo, MSWLogo, FMSLogo,
A Serbo-Croatian translation of this article
is available here.