Logo Programming Language
The Logo Programming Language
Logo is a specialized dialect of Lisp created primarily as an educational instrument. Its core design philosophy centers on several key pillars: interactivity, modularity, extensibility, and flexible data typing.
🕹️ Interactivity
While some versions of Logo support compilation, it is predominantly used as an interpreted language. This allows students and programmers to receive instantaneous feedback, which significantly streamlines the learning curve and the debugging process.
Consider this typical interaction with the Logo interpreter:
I don't know how to fowad (The system doesn't recognize this as a built-in "primitive" or a user-defined procedure).fowad
forwardNot enough inputs to forward (The command is recognized, but it requires a distance value to execute).
forward 100(The turtle successfully moves forward 100 units).
🧱 Modularity and Extensibility
Logo programs are typically constructed from a series of small, manageable procedures. These are usually authored in a text editor using the to keyword to define the procedure name and end to close it.
Procedure Hierarchy
Logo allows for "nesting" procedures, where a simple action becomes a building block for a more complex one.
Example Code:
to square
repeat 4 [forward 50 right 90]
end
to flower
repeat 36 [right 10 square]
end
to garden
repeat 25 [set-random-position flower]
end
Note: In the example above, set-random-position is not a primitive. However, it can be easily created using the primitives random and setposition (also known as setpos or setxy).
The "Vocabulary" Concept
Once a procedure is defined, it behaves exactly like a built-in primitive. To an outside observer, it is impossible to distinguish between a native command and a user-defined one without knowing the specific implementation.
For instance, the pick procedure (used to select a random item from a list) is a primitive in some versions but must be manually coded in others:
to who
output pick [Sandy Dale Dana Chris]
end
Programming in Logo is essentially the act of expanding the language's vocabulary, teaching it new concepts using words it already understands—much like how humans acquire a spoken language.
🔢 Data Types and Flexibility
Unlike many languages that require strict declarations (e.g., distinguishing between integers and floating-point numbers), Logo handles data types dynamically to reduce the burden on the programmer.
Basic Arithmetic
Logo handles math intuitively:
The word Command
The word primitive is used for concatenation, and it treats numbers and strings flexibly.
| Input Command | Result | Note |
|---|---|---|
print word "apple "sauce | applesauce | String concatenation |
print word "3 "4 | 34 | Number-strings joined |
print 12 + word "3 "4 | 46 | Concatenation result treated as number () |
Advanced Logic
Logo supports complex structures, including recursion and list manipulation.
Recursive Factorial:
to factorial :number
if :number = 1 [output 1]
output :number * factorial :number - 1
end
; print factorial 3 -> 6
; print factorial 5 -> 120
List Reversal:
to reverse :stuff
ifelse equal? count :stuff 1
[output first :stuff]
[output sentence reverse butfirst :stuff first :stuff]
end
; print reverse [apples and pears] -> pears and apples
🚀 Enhancements and Variations
While the basics are universal, various implementations have added powerful features:
- Object Logo: An object-oriented version developed for the Macintosh.
- MicroWorlds Logo & Control Lab (LEGO): These versions introduce multi-tasking, allowing multiple processes to run at once.
Sequential vs. Concurrent Execution
In standard Logo, commands run one after another:
repeat 9999 [forward 1 right 1] print "HELLO The turtle finishes its long journey before "HELLO" is printed.
In MicroWorlds Logo, you can use launch or forever for concurrency:
launch [repeat 9999 [forward 1 right 1]] print "HELLOThe turtle starts moving, and "HELLO" appears immediately.forever [forward 1 right 1] print "HELLOThe turtle moves indefinitely, and "HELLO" appears immediately.
📚 Find Out More
If you wish to dive deeper into the world of Logo, consider these resources:
Recommended Reading:
- Computer Science Logo Style (Three-volume set) by Brian Harvey.
- Advanced Logo by Michael Friendly.
Getting Started Checklist:
- Visit the official Logo software page.
- Download a distribution:
- UCBLogo
- MSWLogo
- FMSLogo
- StarLogo TNG
- StarLogo Nova
![]()
A Serbo-Croatian translation of this text is available. For more info, search for: "What Is Logo?", "history logo programming", "logo and learning", "a logo primer", or "logo and natural language".
Copyright ©2023 Logo Foundation.