|
The Logo programming language is a functional programming language. It is an easier to read adaptation and dialect of the Lisp programming language; some have called it Lisp without the parentheses. It was created for educational use, more so for Constructivist teaching, by Danny Bobrow, Wally Feurzeig and Seymour Papert. Today, it is known mainly for its "turtle graphics", but it also has significant facilities for handling lists, files, and I/O. Logo can be used to teach most computer science concepts, as UC Berkeley Lecturer Brian Harvey does in his "Computer Science Logo Style" trilogy.
History Logo was created in 1967 at BBN, a Cambridge, Massachusetts research firm, by Wally Feurzeig and Seymour Papert*. Its intellectual roots are in artificial intelligence, mathematical logic and developmental psychology. The first four years of Logo research, development and teaching work was done at BBN. The first implementation was written in LISP on a PDP-1. Its name was "ghost". The goal was basic problem solving; the turtle gave immediate (non-written) feedback so bugs could be spotted. Lots of other effects have been proposed as causes. Power was not a significant factor in the design. However, ease of use for non-typists who had to use a Teletype, was a big consideration, plus informative error comments. The turtle was a rather late innovation. Logo is not too much different now from the basic concepts before the first turtle. The first turtle was a radio controlled (wireless) floor roamer named "Irving". Irving had touch sensors and could do forward, back, right, left (rotations), and ding (Irving had a bell). The earliest school users were at Muzzy Jr High, Lexington MA. Implementations There are over 130 implementations and dialects of Logo, each of which has its own strengths. Many are object-oriented. A popular cross-platform implementation is UCBLogo. MSWLogo (and its successor FMSLogo), its freeware Windows derivative, is commonly used in schools in the United Kingdom. Another version, used in schools in the US and a number of countries in Latin America, is MicroWorlds Logo. MicroWorlds developed from an earlier product released in 1986 called LogoWriter, a popular product that combined Logo and word processing. Comenius Logo is available in Dutch, German, Czech etc. SOLI Logo was a French version widely used in primary schools in the 1980s. In 1984, ExperLogo for the Macintosh added turtles in 3D and on the surface of spheres. It was also compiled instead of interpreted and hence was very fast. Lego/Logo was a system for controlling the turtle or Lego motors and sensors, and was often used in the classroom in the mid 90's. ARLOGO is an Arabic Port of UCBLOGO, considered the first open-source programming language in Arabic. A modern derivative of Logo is a variation that allows thousands of "turtles", each moving independently. There are two popular implementations: MIT StarLogo and NetLogo. These derivatives allow for the exploration of emergent phenomena and come with many experiments in social studies, biology, physics, and many other sciences. Although the focus is on the interactions of a large number of independent agents, these variations still capture the original flavor of Logo. There is no single agreed-upon Logo language definition or standard, only a loose tradition. As a result, there are substantial differences between the many dialects of Logo that have evolved. The code examples shown below would work in many Logo dialects, but not all. Programming The idea is that a turtle with a pen strapped to it can be instructed to do simple things like move forward 100 spaces or turn around. From these building blocks you can build more complex shapes like squares, triangles, circles--using these to draw houses or sailboats. The turtle moves with commands that are relative to its own position, "LEFT 90" meant rotate left by 90 degrees. A student could understand (and predict and reason about) the turtle's motion by imagining what they would do if they were the turtle. Papert called this "body syntonic" reasoning. The idea of turtle graphics is also useful for example in Lindenmayer system for generating fractals. Turtle programming The following are examples of Turtle code. While seemingly very simple, turtles can be given groups of instructions, essentially creating libraries of more complex commands. In practice short forms are used. For example, "LEFT 90" is written "LT 90". Key words are usually written in upper case for beginners, but more advanced texts use lower case. Example 1: a square FORWARD 100This draws a square with sides 100 units long (in the image the turtle has yet to turn LT 90 to be back in its starting position). Example 2: a triangle The commands may be written on one line, or more. REPEAT 3 FD 100 RT 120 Example 3: dotted line Example 4: loops You could also use loop (repeat) commands. This would draw the exact same box as in the first example: Which executes the command " FD 100 RIGHT 90" four times.An approximation of a circle can be constructed easily with 360 small rotations and a step forward: REPEAT 360 FD 1 RIGHT 1. Example 5: new words
Example 6: erasing (in the UCBLogo dialect) The turtle can erase a line, using the command PENERASE (PE). The pen can be restored with the command PENPAINT (PPT). EDALL (to enter the editor mode, then the actual procedure) CS CHAIR WAIT 200 ERASECHAIR This example introduces two new instructions, which are best taught by running them through a Logo interpreter and observing the result. This typifies the general spirit of Logo. Example 7: parameters: giving the word changeable information
The language Logo is generally known as an interpreted language, although recently there have been developed compiled Logo dialects - like ELICA. Logo is not case dependent, but retains the case used for formatting. It is written in lines. It is a compromise between a sequential programming language with block structures, and a functional programming language. There is no 'standard' LOGO, but UCBLogo is highly regarded. It is a teaching language but its list handling facilities make it remarkably useful for producing useful scripts. Functions and procedures Each line is made up of "function calls", of which there are two types: print.sum, first or readlist.A command is similar to a Pascal procedure, and an operation is similar to a Pascal function. 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.Mathematics in Logo uses prefix notation, like: sum . Infix is also available.
help "keyword (will bring up a full description of the expression). Logo allows for recursion, the process where a procedure calls itself. Example 8: A spiral drawn using recursion
Data There are three datatypes in UCBLogo, A number is a special case of word. There is no static typing. The interpreter detects the datatype by context. There are two important symbols :- this means 'the contents of'This is an extremely useful symbol that keeps reminding students that a variable is really some 'place' in memory. A number is a special case of self evaluation- it really could be written with a quote 2 is really "2 Assignment in Pascal x:= y +3 becomes in Logo make "x sum y 3 or make "x sum y "3 make takes 2 parameters, the second of which here is sum . Now sum takes two 'parameters' and is an 'operation', thus the calculation is possible. "3 evaluates to 3, and :y takes the contents of the thing called y, these are summed giving a number. The effect of make is to place the result into the first parameter.
An alternative way of looking at this, maybe, is that the second parameter is 'passed by value' while the first is 'passed by address.' Indirection (within a procedure) is possible with the form make .
Scoping Variables don’t have to be declared before use. Their scope is then global. A variable may be declared local, then its scope is limited to that procedure and its subprocedures (a.k.a. dynamic scope). Calling a 'procedure' with 'inputs', creates 'local variables' which hold the contents of the parameters.Lists Discussing lists comes as a surprise to a Pascal programmer, who has managed quite well without them, however this opens many new possibilities. Arrays are also provided for the timid. Example 9: using list primitives to extract the first five members of a list One way would be to use iteration. alist ifelse lessp count alist 6 op :alist make "olist repeat 5 make "olist lput first :alist :olist make "alist bf :alist output olist end show firstfive 1 2 3 4 5 6 7 8 9 1 2 3 4 5 foreach firstfive 1 2 3 4 5 6 7 8 9 show 10 - ? 9 8 7 6 5 Another, more elegant way would be numlist if num = 0 output output fput (first list) (firstnnum-1 butfirstlist) end to firstfive list output firstn 5 list end This method uses recursion, and is an example of a 'functional' rather than an 'imperative' programming approach. Control structure commands The standard Pascal controls are available, there is selection
There are iteration commands
Recursion is Logo's preferred processing paradigm. Template iteration The Pascal programmer will be surprised by a series of list based control structures. The basic idea is that you have two lists OPERATION a list of commands many data items each of the commands is applied in turn to each of the data items. There are several of these template commands with names like MAP, APPLY, FILTER, FOREACH, REDUCE and CASCADE. They repesent four flavours of template iteration, known as explicit-slot, named-procedure, named-slot (or Lambda) and procedure-text. show map ? * ? 5 6 7 25 36 49 show filter (count ?) > 4 the quick brown fox jumps over the lazy dog quick brown jumps show foreach 1 2 3 4 5 ? * 10 10 20 30 40 50 RUN list of commands run a list of commands (or programs) from in a program. Property lists A property list is a special list where the odd number items are property names, and the even are property values. There are three commands to process property list. pprop listnamenamevalueto add a new pair to the list remprop listnamenamevalueto remove a pair to the list show gprop listnamenameto get the matching value from the list I/O Commands Text may be written to the command window (output stream) using print, show and to the graphics window using label The standard commands are readlist readword readchar with the normal input stream being the keyboard. In Unix tradition the input stream can be changed, so input can come from a disk file. Similarly, output can be redirected. The technique will be familiar to Pascal Programmers- using a sequenceopenread filename setreadfilename setreadpos nn readchar setread close filename. There are equivalent commands to change the output stream, openwrite, openappend, setwrite, setwritepos nn. dribble filename Creates a transcript of everything that is typed in or outputted to the command window. nodribble This turns it off. Graphics Turtle graphics is a powerful method of introducing thinking but LOGO also has a few useful Cartesian commands home returns the turtle to (0,0) setx xx sety yy sends the turtle, still drawing to (xx,yy) seth nn sets the turtle on a heading or compass bearing of (nn) Example 10: calculating and drawing a sundial for a given latitude
MSWLogo extensions MSWLogo supports multiple turtles, and 3D Graphics. MSWLogo allows input from COM ports and LPT ports and also 'hardware' ports. MSWLogo also supports a windows interface thus I/O is available through this GUI- and keyboard and mouse events can trigger interrupts. cs show 40 make "latitude readword uses keyboard input for i 0 6 1 make "ang arctan product sin :latitude tan product :i 15 ;the calculation rt :ang fd 200 bk 200 lt :ang ;draw the morning line lt :ang fd 200 bk 200 rt :ang ;use symmetry to draw the afternoon line pu setx -300 sety -300 seth 90 pd send the turtle to the bottom fd 300 seth 270 rt 90 - latitude fd 300draw the style or gnomon pu home pd tidy it up end Hello World Hello world program TO HELLO PRINT Hello, world! END See also Bibliography | |||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||
![]() |
|
| |