---
title: "Logo语言"
author: "panlw"
date: "2008-11-04T11:35:30Z"
tags: []
slug: "logo"
draft: false
lastmod: "2008-11-11T21:14:05Z"
id: 262015
url: "https://panlw.iteye.com/blog/262015"
---

# Logo (programming language)

### From Wikipedia, the free encyclopedia

Jump to: [navigation](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#column-one) , [search](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#searchInput)

Logo [![](http://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Remi_turtlegrafik.png/300px-Remi_turtlegrafik.png)](http://en.wikipedia.org/wiki/Image:Remi_turtlegrafik.png "Remi turtlegrafik.png") [Paradigm](http://en.wikipedia.org/wiki/Programming_paradigm "Programming paradigm") [functional](http://en.wikipedia.org/wiki/Functional_programming "Functional programming") , [educational](http://en.wikipedia.org/wiki/Educational_programming_language "Educational programming language") Appeared in 1967 Designed by [Wally Feurzeig](http://en.wikipedia.org/wiki/Wally_Feurzeig "Wally Feurzeig") & [Seymour Papert](http://en.wikipedia.org/wiki/Seymour_Papert "Seymour Papert") [Developer](http://en.wikipedia.org/wiki/Software_developer "Software developer") Wally Feurzeig & Seymour Papert [Typing discipline](http://en.wikipedia.org/wiki/Type_system "Type system") Dynamic [Major implementations](http://en.wikipedia.org/wiki/Programming_language_implementation "Programming language implementation") [UCBLogo](http://en.wikipedia.org/wiki/UCBLogo "UCBLogo") , many others Influenced by [Lisp](http://en.wikipedia.org/wiki/Lisp_programming_language "Lisp programming language") Influenced [Smalltalk](http://en.wikipedia.org/wiki/Smalltalk "Smalltalk") , [Etoys](http://en.wikipedia.org/wiki/Etoys_%28programming_language%29 "Etoys (programming language)") , [Scratch](http://en.wikipedia.org/wiki/Scratch_%28programming_language%29 "Scratch (programming language)")

**Logo** is a [computer programming language](http://en.wikipedia.org/wiki/Computer_programming_language "Computer programming language") used for [functional programming](http://en.wikipedia.org/wiki/Functional_programming "Functional programming") . It is an easier-to-read adaptation and dialect of the [Lisp](http://en.wikipedia.org/wiki/Lisp_%28programming_language%29 "Lisp (programming language)") language; some have called it Lisp without the [parentheses](http://en.wikipedia.org/wiki/S-expression "S-expression") . Today, it is known mainly for its [turtle graphics](http://en.wikipedia.org/wiki/Turtle_graphics "Turtle graphics") , but it also has significant facilities for handling lists, files, I/O, and [recursion](http://en.wikipedia.org/wiki/Recursion "Recursion") .

Logo was created for [educational](http://en.wikipedia.org/wiki/Education "Education") use, more so for [constructivist](http://en.wikipedia.org/wiki/Constructivism_%28learning_theory%29 "Constructivism (learning theory)") [teaching](http://en.wikipedia.org/wiki/Teaching "Teaching") , by [Daniel G. Bobrow](http://en.wikipedia.org/wiki/Daniel_G._Bobrow "Daniel G. Bobrow") , [Wally Feurzeig](http://en.wikipedia.org/wiki/Wally_Feurzeig "Wally Feurzeig") and [Seymour Papert](http://en.wikipedia.org/wiki/Seymour_Papert "Seymour Papert") . It can be used to teach most computer science concepts, as [UC Berkeley](http://en.wikipedia.org/wiki/UC_Berkeley "UC Berkeley") Lecturer [Brian Harvey](http://en.wikipedia.org/w/index.php?title=Brian_Harvey_%28Lecturer%29&amp%3Baction=edit&amp%3Bredlink=1 "Brian Harvey (Lecturer) (page does not exist)") does in his *Computer Science Logo Style* trilogy.

## Contents

\[[hide]() ]

- [1 History](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#History)
- [2 Implementations](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Implementations)
- [3 Influence](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Influence)
- [4 Programming](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Programming)
  
  - [4.1 Syntax](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Syntax)
  - [4.2 The pen](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#The_pen)
  - [4.3 Loops](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Loops)
  - [4.4 Defining procedures, the need for an editor](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Defining_procedures.2C_the_need_for_an_editor)
  - [4.5 Animation](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Animation)
- [5 The language](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#The_language)
  
  - [5.1 Functions and procedures](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Functions_and_procedures)
  - [5.2 Data](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Data)
    
    - [5.2.1 Scoping](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Scoping)
  - [5.3 Lists](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Lists)
  - [5.4 Control structure commands](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Control_structure_commands)
  - [5.5 Template iteration](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Template_iteration)
  - [5.6 Property lists](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Property_lists)
  - [5.7 I/O Commands](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#I.2FO_Commands)
  - [5.8 Graphics](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Graphics)
  - [5.9 MSWLogo extensions](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#MSWLogo_extensions)
- [6 See also](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#See_also)
- [7 Further reading](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#Further_reading)
- [8 External links](http://en.wikipedia.org/wiki/Logo_%28programming_language%29#External_links)

&lt;script type="text/javascript"&gt;&lt;/script&gt;

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=1 "Edit section: History") ] History

Logo was created in [1967](http://en.wikipedia.org/wiki/1967 "1967") at [Bolt, Beranek and Newman](http://en.wikipedia.org/wiki/Bolt,_Beranek_and_Newman "Bolt, Beranek and Newman") (BBN), a [Cambridge, Massachusetts](http://en.wikipedia.org/wiki/Cambridge,_Massachusetts "Cambridge, Massachusetts") research firm, by [Wally Feurzeig](http://en.wikipedia.org/wiki/Wally_Feurzeig "Wally Feurzeig") and [Seymour Papert](http://en.wikipedia.org/wiki/Seymour_Papert "Seymour Papert") [\[1\]](http://el.media.mit.edu/Logo-foundation/logo/index.html "http://el.media.mit.edu/Logo-foundation/logo/index.html") . Its intellectual roots are in [artificial intelligence](http://en.wikipedia.org/wiki/Artificial_intelligence "Artificial intelligence") , [mathematical logic](http://en.wikipedia.org/wiki/Mathematical_logic "Mathematical logic") and [developmental psychology](http://en.wikipedia.org/wiki/Developmental_psychology "Developmental psychology") . The first four years of Logo research, development and teaching work was done at BBN. The first implementation of Logo, called Ghost, was written in LISP on an [SDS 950](http://en.wikipedia.org/w/index.php?title=SDS_950&amp%3Baction=edit&amp%3Bredlink=1 "SDS 950 (page does not exist)") . The goal was to create a math land where kids could play with words and sentences. Modeled on LISP, the design goals of Logo included accessible power\[[*clarify*](http://en.wikipedia.org/wiki/Wikipedia:Please_clarify "Wikipedia:Please clarify") ] and informative error messages. The use of virtual [Turtles](http://en.wikipedia.org/wiki/Turtle_%28robot%29 "Turtle (robot)") allowed for immediate visual feedback and debugging.

The first working [turtle robot](http://en.wikipedia.org/wiki/Turtle_%28robot%29 "Turtle (robot)") was created at [MIT](http://en.wikipedia.org/wiki/MIT "MIT") in 1969. A display turtle preceded the physical floor turtle. Modern Logo has not changed too much from the basic concepts before the first turtle. The first turtle was a tethered floor roamer, not [radio-controlled](http://en.wikipedia.org/wiki/Radio-control "Radio-control") or [wireless](http://en.wikipedia.org/wiki/Wireless "Wireless") . Later, BBN developed a turtle named Irving that had touch sensors and could move forwards, backwards, rotate, and ding its bell. The earliest year-long school users of Logo were in 1968-69 at Muzzey Jr High, [Lexington MA](http://en.wikipedia.org/wiki/Lexington,_Massachusetts "Lexington, Massachusetts") . The virtual and physical turtles were first used by fifth graders at the Bridge School in Lexington, MA in 1970-71.

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=2 "Edit section: Implementations") ] Implementations

As of July 2008 there were 187 [implementations and dialects of Logo](http://elica.net/download/papers/LogoTreeProject.pdf "http://elica.net/download/papers/LogoTreeProject.pdf") , each with its own strengths. Most of those 187 are no longer in wide use, but many are still under active development.

As yet there is no single agreed-upon Logo language definition or standard, though there is a broad consensus on core aspects of the language. There are substantial differences between the many dialects of Logo. The situation is confused by the regular appearance of [turtle graphics](http://en.wikipedia.org/wiki/Turtle_graphics "Turtle graphics") programs that mistakenly call themselves Logo.

The most broadly used and prevalent early implementation of Logo was [Apple](http://en.wikipedia.org/wiki/Apple_Inc. "Apple Inc.") Logo, which was developed by LCSI for the Apple II computer and popular during the 1980s.

The closest thing to a de facto Logo standard today is [UCBLogo](http://www.cs.berkeley.edu/%7Ebh/logo.html "http://www.cs.berkeley.edu/~bh/logo.html") , also known as Berkeley Logo. It is free and cross-platform. UCBLogo has only a rudimentary graphical user interface, so several projects exist that provide a better interface. MSWLogo, and its successor [FMSLogo](http://www.fmslogo.org/ "http://www.fmslogo.org/") , for Windows, are commonly used in schools in the [United Kingdom](http://en.wikipedia.org/wiki/United_Kingdom "United Kingdom") and [Australia](http://en.wikipedia.org/wiki/Australia "Australia") . Commercial Logos that are still widely used in schools include [MicroWorlds](http://en.wikipedia.org/wiki/MicroWorlds "MicroWorlds") Logo and [Imagine Logo](http://www.logo.com/imagine/ "http://www.logo.com/imagine/") .

Some modern derivatives of Logo allow thousands of independently moving turtles. There are two popular implementations: [MIT](http://en.wikipedia.org/wiki/MIT "MIT") 's [StarLogo](http://en.wikipedia.org/wiki/StarLogo "StarLogo") and [CCL](http://en.wikipedia.org/w/index.php?title=Center_for_Connected_Learning&amp%3Baction=edit&amp%3Bredlink=1 "Center for Connected Learning (page does not exist)") 's [NetLogo](http://en.wikipedia.org/wiki/NetLogo "NetLogo") . They allow for the exploration of [emergent phenomena](http://en.wikipedia.org/wiki/Emergence "Emergence") and come with many experiments in social studies, biology, physics, and other areas.

Most Logos are 2D, but the Elica interpreter is notable for supporting 3D graphics. Most Logo implementations are interpreted, but some compilers have been built, including the Lhogho compiler, by the same author as Elica. Although most often used for graphics, Logo can also control robots. It was interfaced with [Lego bricks](http://en.wikipedia.org/wiki/Lego "Lego") , although Lego decided later to use another language in the commercial Lego Mindstorms products. The Mindstorms [GUI](http://en.wikipedia.org/wiki/GUI "GUI") interface is based on [LabVIEW](http://en.wikipedia.org/wiki/LabVIEW "LabVIEW") by [National Instruments](http://en.wikipedia.org/wiki/National_Instruments "National Instruments") . An interface also exists for [Cricket robots](http://en.wikipedia.org/w/index.php?title=Cricket_robot&amp%3Baction=edit&amp%3Bredlink=1 "Cricket robot (page does not exist)") .

[ObjectLOGO](http://en.wikipedia.org/wiki/ObjectLOGO "ObjectLOGO") is a variant with object-oriented extensions.

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=3 "Edit section: Influence") ] Influence

Logo was a primary influence on the [Smalltalk](http://en.wikipedia.org/wiki/Smalltalk "Smalltalk") programming language. It is also the main influence on the [Etoys](http://en.wikipedia.org/wiki/Etoys_%28programming_language%29 "Etoys (programming language)") educational programming environment and language, which is essentially a Logo written in [Squeak](http://en.wikipedia.org/wiki/Squeak "Squeak") (a variant of [Smalltalk](http://en.wikipedia.org/wiki/Smalltalk "Smalltalk") ).

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=4 "Edit section: Programming") ] Programming

*See also: [Turtle graphics](http://en.wikipedia.org/wiki/Turtle_graphics "Turtle graphics")*

Logo's best-known feature is the turtle, which is an on-screen [cursor](http://en.wikipedia.org/wiki/Cursor "Cursor") (derived originally from a robot of the same name), which can be given movement and drawing instructions, and is used to programmatically produce line graphics. It is traditionally and most often represented pictorially either as a triangle or a turtle icon (though it can be represented by any icon). Turtle graphics were added to the Logo language by Seymour Papert in the late 1960s to support Papert's version of the [turtle robot](http://en.wikipedia.org/wiki/Turtle_%28robot%29 "Turtle (robot)") , a simple robot controlled from the user's workstation that is designed to carry out the drawing functions assigned to it using a small retractable pen set into or attached to the robot's body.

As a practical matter, the use of turtle geometry instead of a more traditional model mimics the actual movement logic of the turtle robot. Turtle geometry works somewhat differently from (x,y) addressed [Cartesian geometry](http://en.wikipedia.org/wiki/Cartesian_geometry "Cartesian geometry") , rather operating in a [Euclidean space](http://en.wikipedia.org/wiki/Euclidean_space "Euclidean space") (i.e., relative measures and angles without an origin, unlike coordinate-addressed systems such as [PostScript](http://en.wikipedia.org/wiki/PostScript "PostScript") ). 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. Some Logo implementations, particularly those that allow the use of concurrency and multiple turtles, support [collision detection](http://en.wikipedia.org/wiki/Collision_detection "Collision detection") and allow the user to redefine the appearance of the turtle cursor, essentially allowing the Logo turtles to function as [sprites](http://en.wikipedia.org/wiki/Sprite_%28computer_graphics%29 "Sprite (computer graphics)") .

Turtle geometry is also sometimes used in environments other than Logo as an alternative to a strictly coordinate-addressed graphics system. For instance, the idea of turtle graphics is also useful in [Lindenmayer system](http://en.wikipedia.org/wiki/Lindenmayer_system "Lindenmayer system") for generating [fractals](http://en.wikipedia.org/wiki/Fractal "Fractal") .

[]()

[]()

#### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=5 "Edit section: Syntax") ] Syntax

Commands may be written on one line, or more. Many commands have mnemonic short forms; for example `FORWARD` and `RIGHT` are coded `FD` and `RT` respectively. This makes the input less onerous. Anything written after the ; (semicolon) is ignored, allowing the coder to insert comments.

```
FORWARD 100 ; draws a square with sides 100 units long
LEFT 90
FORWARD 100
LEFT 90
FORWARD 100
LEFT 90
FORWARD 100
LEFT 90
```

```
FD 100 RT 120 FD 100 RT 120 ; draws a triangle
FD 100 RT 120
```

The [Hello World](http://en.wikipedia.org/wiki/Hello_World "Hello World") program in Logo looks like this:

```
print [Hello World]
```

Loading a file will include all its defined procedures into the currently open file. If the file being opened has commands that are not in a defined procedure they will be run on startup and will be removed from the workspace (except for variable assignments), so if the file is then saved it becomes blank. For example, one could have a helloworld.lgo which prints [Hello World](http://en.wikipedia.org/wiki/Hello_World "Hello World") and becomes blank when EDALL is called:

```
print [Hello World]
```

Alternatively, one could put the command in a procedure that is run when the program is loaded.

```
to main
 print [Hello World!]
end

make "startup [main]
```

[]()

[]()

#### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=6 "Edit section: The pen") ] The pen

[![](http://upload.wikimedia.org/wikipedia/en/5/5a/Ex3.jpg)](http://en.wikipedia.org/wiki/Image:Ex3.jpg "Turtle drawing a dotted Line")

[![](http://en.wikipedia.org/skins-1.5/common/images/magnify-clip.png)](http://en.wikipedia.org/wiki/Image:Ex3.jpg "Enlarge")

Turtle drawing a dotted Line

The analogy of a turtle with a pen attached to its tail is often used. The turtle's pen can be lifted and lowered, thus drawing a rudimentary dotted line.

```
FD 20    ; drawing a line and moving
PENUP    ; lifting the pen so it won't draw anything
FD 20    ; not drawing but moving
PENDOWN  ; lowering the pen so it draws again
FD 20    ; drawing a line and moving
PENUP     ;lifting the pen so it won't draw anything
FD 40    ; not drawing but moving
PENDOWN  ;lowering the pen so it draws again
RT 20    ;drawing a line and moving
```

[]()

[]()

#### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=7 "Edit section: Loops") ] Loops

There are three loop (repeat) commands; `REPEAT` is one. This draws the a box.

```
REPEAT 4 [FD 100 LEFT 90]
```

The command `FD 100 LEFT 90` is executed 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]` . Loops may be embedded, giving spectacular results with little effort.

```
REPEAT 36[ RT 10 REPEAT 360 [FD 1 RT 1]]
FD 25
RT 90
```

[]()

[]()

#### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=8 "Edit section: Defining procedures, the need for an editor") ] Defining procedures, the need for an editor

[![](http://upload.wikimedia.org/wikipedia/en/c/c3/Ex5.jpg)](http://en.wikipedia.org/wiki/Image:Ex5.jpg "Basic Chair")

[![](http://en.wikipedia.org/skins-1.5/common/images/magnify-clip.png)](http://en.wikipedia.org/wiki/Image:Ex5.jpg "Enlarge")

Basic Chair

Procedures can be defined on the command line, using the `TO END` pair:

```
TO CHAIR  REPEAT 4 [FD 100 RT 90]  FD 200  END
```

However, 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 100 RT 90]  FD 200
END
```

The 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 100 LEFT 90] FD 200` will be executed. The word `CHAIR` can be used as a command; for example, `REPEAT 4 [CHAIR]` would repeat the `CHAIR` operation four times.

[]()

[]()

#### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=9 "Edit section: Animation") ] Animation

Logo was designed in spirit of low threshold and no ceiling, which enables easy entry by novices and yet meet the needs of high-powered users. Animations require both the ability to draw shapes and to erase shapes. The process is the same, except that in the former a line is deposited on the display device and in the latter a line is removed. Using the turtle analogy, the turtle's pen must paint, and the turtle's pen must erase.

In UCBLogo, the turtle can be set to erase using the command `PENERASE` (`PE` ). Now any future FD movements will erase anything beneath them. The pen can be restored with the command `PENPAINT` (`PPT` ).

```
EDALL

 ;(to enter the editor mode, then the actual procedure)


TO ERASECHAIR
PE
BK 200 REPEAT 4 [FD 100 RT 90]  
PPT
END



```

```
CS CHAIR WAIT 200 ERASECHAIR
```

A `WAIT` delay between the drawing and the erasing introduces the illusion of motion.

```
CS REPEAT 20 [CHAIR WAIT 200 ERASECHAIR FD 20]
```

Logo can pass extra information to its words, and return information. The procedure, (word) is instructed to expect something and give that something a name. The colon is used for this purpose. It passes the information *by value* and the colon is pronounced as *the value of* . When the procedure is run with a command such as `CHAIR 200` , the word `:thesize` takes the value 200 so when `FD :thesize` is executed, the interpreter understands *FD, the value of 200* .

```
EDALL

 ;(to enter the editor mode, then the actual procedure)
 
TO CHAIR  :thesize
REPEAT 4 [FD :thesize  RT 90] FD :thesize FD :thesize
END
```

```
CS REPEAT 9 [CHAIR 50 RT 20 CHAIR 100 WAIT 50 RT 20]
```

[![Pattern](http://upload.wikimedia.org/wikipedia/en/3/3e/Ex7.jpg)](http://en.wikipedia.org/wiki/Image:Ex7.jpg "Pattern")

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=10 "Edit section: The language") ] The language

Logo is generally known as an interpreted language, although recently there have been developed compiled Logo dialects—such as Lhogho or Liogo. Logo is not case-sensitive but retains the case used for formatting. 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.

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=11 "Edit section: Functions and procedures") ] Functions and procedures

Each line is made up of function calls, or [subroutines](http://en.wikipedia.org/wiki/Subroutine "Subroutine") in programming terminology, of which there are two types:

- commands (which do something—effects—but don't return a value) like `print` .
- operations (which just return a value, its output) like `sum` , `first` or `readlist` .

A command is similar to a [Pascal](http://en.wikipedia.org/wiki/Pascal_%28programming_language%29 "Pascal (programming language)") procedure, and an operation is similar to a Pascal function. (See also: [command-query separation](http://en.wikipedia.org/wiki/Command-query_separation "Command-query separation") , where a query is an operation in Logo). A special subset of operations, called [predicates](http://en.wikipedia.org/wiki/Predicate_%28computer_programming%29 "Predicate (computer programming)") , 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.

Mathematics in Logo uses prefix notation, like: `sum :x :y, product :x :y, difference :x :y, quotient :x :y` . Infix is also available.

```
help "keyword ;(will bring up a full description of the expression).
```

[![](http://upload.wikimedia.org/wikipedia/en/1/14/Ex8.jpg)](http://en.wikipedia.org/wiki/Image:Ex8.jpg "Recursive Spiral")

[![](http://en.wikipedia.org/skins-1.5/common/images/magnify-clip.png)](http://en.wikipedia.org/wiki/Image:Ex8.jpg "Enlarge")

Recursive Spiral

Logo allows for [recursion](http://en.wikipedia.org/wiki/Recursion "Recursion") , the process where a procedure calls itself.

```
to spiral :size
   if  :size > 30 [stop] ; an exit condition
   fd :size rt 15        ; many lines of action
   spiral :size *1.02    ; the tailend recursive call
end
```

```
spiral 10
```

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=12 "Edit section: Data") ] Data

There are three datatypes in UCBLogo,

- the word,
- the list,
- the array.

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

- The colon `:` - this means *the contents of* .

This is an extremely useful symbol that keeps reminding students that a variable is really some 'place' in memory.

- The quote- this means '"the word is evaluated as itself"', or '"its value after evaluation is the same as it was before"'. This is important.

A number is a special case of self evaluation—it really could be written with a quote **2** is really **"2**

Variable [assignment](http://en.wikipedia.org/wiki/Assignment_%28computer_science%29 "Assignment (computer science)") (eg. `x := y + 3` ) is handled in Logo with the `make` command:

```
   make "x sum :y 3 
```

or

```
   make "x sum :y "3
```

`make` takes 2 parameters, the second of which here is `sum :y "3` . `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. From a programmatical perspective, the first argument to `make` is passed by reference, while the second is passed by value.

[]()

[]()

#### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=13 "Edit section: Scoping") ] 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 any procedures that it calls (a.k.a. dynamic [scope](http://en.wikipedia.org/wiki/Scope_%28programming%29 "Scope (programming)") ). Calling a procedure with inputs (the name usually used for arguments in the Logo literature) also creates local variables that hold the argument values.

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=14 "Edit section: Lists") ] Lists

Logo inherits lists from [Lisp](http://en.wikipedia.org/wiki/Lisp_%28programming_language%29 "Lisp (programming language)") , and they are its primary method of storing vectors. Arrays are also provided.

- Operators exist to convert words into lists, and lists into arrays and back again.
- This data type has the advantage over arrays that it is infinitely expandable. Data are extracted using the operations first, butfirst, last, butlast, butmember, member and item. Data elements are added using sentence fput and lput.
- A list can be considered to be a queue with the operators queue and dequeue, or a stack with the operations push and pop.
- Recursion rather than iteration is the natural method to process lists.

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=15 "Edit section: Control structure commands") ] Control structure commands

Logo provides several common control structures.

- ifelse test \[ do\_if\_true list ] \[do\_if\_false list]

There are iteration commands

- while condition \[instruction list]
- until condition \[instruction list ]
- repeat number \[instruction list]

Recursion is Logo's preferred processing paradigm.

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=16 "Edit section: Template iteration") ] Template iteration

Logo also provides list-based control structures. The basic idea is of 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 represent four flavours of template iteration, known as explicit-slot, named-procedure, named-slot (or Lambda), and procedure-text.

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=17 "Edit section: Property lists") ] 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 :listname :name :value ;to add a new pair to the list
remprop :listname :name :value ;to remove a pair to the list
show gprop :listname :name  ;to get the matching value from the list
```

See [Associative array](http://en.wikipedia.org/wiki/Associative_array "Associative array")

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=18 "Edit section: I/O Commands") ] 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.

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=19 "Edit section: Graphics") ] Graphics

Turtle graphics is a powerful method of introducing thinking but LOGO also has a few useful [Cartesian](http://en.wikipedia.org/wiki/Cartesian_coordinate_system "Cartesian coordinate system") 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)
```

[]()

[]()

### [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=20 "Edit section: MSWLogo extensions") ] 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.

Simple [GIF](http://en.wikipedia.org/wiki/GIF "GIF") animations may also be produced on MSWlogo version 6.5 with the *gifsave* command.

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=21 "Edit section: See also") ] See also

- [Lego Logo](http://en.wikipedia.org/wiki/Lego_Logo "Lego Logo") , which uses Logo to control Lego bricks

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=22 "Edit section: Further reading") ] Further reading

- *Computer Science Logo Style* , Brian Harvey, MIT Press (3 volumes) [ISBN 0-262-58148-5](http://en.wikipedia.org/wiki/Special:BookSources/0262581485) , [ISBN 0-262-58149-3](http://en.wikipedia.org/wiki/Special:BookSources/0262581493) , [ISBN 0-262-58150-7](http://en.wikipedia.org/wiki/Special:BookSources/0262581507) . Available [online](http://www.cs.berkeley.edu/%7Ebh/ "http://www.cs.berkeley.edu/~bh/")
- *Practical logo for the Atari ST (Paperback)* , Martin Sims, Glentop [ISBN 1851810307](http://en.wikipedia.org/wiki/Special:BookSources/1851810307) ,[ISBN 978-1851810307](http://en.wikipedia.org/wiki/Special:BookSources/9781851810307) . Available [online](http://www.amazon.co.uk/Practical-logo-Atari-ST-Sims/dp/1851810307/ref=sr_1_1/202-2514229-1823846?ie=UTF8&amp%3Bs=books&amp%3Bqid=1172743982&amp%3Bsr=8-1 "http://www.amazon.co.uk/Practical-logo-Atari-ST-Sims/dp/1851810307/ref=sr_1_1/202-2514229-1823846?ie=UTF8&amp;s=books&amp;qid=1172743982&amp;sr=8-1")
- *How to Think Like a Computer Scientist: Logo Version (Paperback)* , Allen Downey & Guido Gay, Lulu .
- *The Great Logo Adventure* , Jim Muller, Doone Publications [ISBN 0-9651934-6-2](http://en.wikipedia.org/wiki/Special:BookSources/0965193462) (Now out of print but downloadable free of charge in pdf form from The MSWLogo website - from where you can also download the freeware MSWLogo program)
- [*To Artifical Intelligence* (1976)](http://history.dcs.ed.ac.uk/archive/docs/ArtificialIntelligence/art0084.html "http://history.dcs.ed.ac.uk/archive/docs/ArtificialIntelligence/art0084.html") Early AI textbook where Logo is used extensively. (Using the Edinburgh University dialect, AI2LOGO)
- [Turtle Geometry](http://www.amazon.com/gp/product/0262510375 "http://www.amazon.com/gp/product/0262510375") Abelson and diSessa
- *Children Designers* , Idit Harel Caperton, Ablex Publishing Corporation [ISBN 0-89391-8788](http://en.wikipedia.org/wiki/Special:BookSources/0893918788) -5. Available [online](http://www.amazon.com/Children-Designers-Interdisciplinary-Constructions-Computer-Rich/dp/0893917885/ref=sr_1_2?ie=UTF8&amp%3Bs=books&amp%3Bqid=1222280226&amp%3Bsr=8-2 "http://www.amazon.com/Children-Designers-Interdisciplinary-Constructions-Computer-Rich/dp/0893917885/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1222280226&amp;sr=8-2")

[]()

[]()

## [\[]()[edit](http://en.wikipedia.org/w/index.php?title=Logo_%28programming_language%29&amp%3Baction=edit&amp%3Bsection=23 "Edit section: External links") ] External links

[![Commons::Category:Logo (programming language)](http://upload.wikimedia.org/wikipedia/en/thumb/4/4a/Commons-logo.svg/50px-Commons-logo.svg.png)](http://commons.wikimedia.org/wiki/Category:Logo_%28programming_language%29 "commons:Category:Logo (programming language)")

[Wikimedia Commons](http://en.wikipedia.org/wiki/Wikimedia_Commons "Wikimedia Commons") has media related to:

*[**Logo (programming language)**](http://commons.wikimedia.org/wiki/Category:Logo_%28programming_language%29 "commons:Category:Logo (programming language)")*

[![Wikibooks](http://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Wikibooks-logo-en.svg/50px-Wikibooks-logo-en.svg.png)](http://en.wikipedia.org/wiki/Image:Wikibooks-logo-en.svg "Wikibooks")

[Wikibooks](http://en.wikipedia.org/wiki/Wikibooks "Wikibooks") has a book on the topic of

*[**Logo Programming**](http://en.wikibooks.org/wiki/Logo_Programming "wikibooks:Logo Programming")*

- [papert](http://logo.twentygototen.org/_5VudSp4 "http://logo.twentygototen.org/_5VudSp4") , an online implementation of Logo using [HTML canvas](http://en.wikipedia.org/wiki/Canvas_%28HTML_element%29 "Canvas (HTML element)") and [Javascript](http://en.wikipedia.org/wiki/Javascript "Javascript")
- [ACSLogo](http://www.alancsmith.co.uk/logo/index.html "http://www.alancsmith.co.uk/logo/index.html") for Mac OS X
- [Berkeley Logo](http://www.cs.berkeley.edu/%7Ebh/logo.html "http://www.cs.berkeley.edu/~bh/logo.html") (UCBLogo)
- [Elica](http://www.elica.net/ "http://www.elica.net/") a 3D Logo
- [FMSLogo](http://fmslogo.sourceforge.net/ "http://fmslogo.sourceforge.net/")
- [Gary Stager's Logo Resources](http://www.stager.org/logo.html "http://www.stager.org/logo.html")
- [Lhogho](http://lhogho.sourceforge.net/ "http://lhogho.sourceforge.net") a Logo compiler for Linux and Windows
- [Logo Computer Systems, Inc.](http://www.microworlds.com/ "http://www.microworlds.com") maker of Microworlds, a commercial Logo
- [Logo (programming language)](http://www.dmoz.org/Computers/Programming/Languages/Lisp/Logo// "http://www.dmoz.org/Computers/Programming/Languages/Lisp/Logo//") at the [Open Directory Project](http://en.wikipedia.org/wiki/Open_Directory_Project "Open Directory Project")
- [MSWLogo](http://www.softronix.com/logo.html "http://www.softronix.com/logo.html")
- [Wiki history of Logo](http://logothings.wikispaces.com/ "http://logothings.wikispaces.com/") covering the very early days
- [XLogo](http://xlogo.tuxfamily.org/ "http://xlogo.tuxfamily.org") a Logo programming interpreter under GPL Licence. (Support [Linux](http://en.wikipedia.org/wiki/Linux "Linux") , [Windows](http://en.wikipedia.org/wiki/Windows "Windows") , [Mac](http://en.wikipedia.org/wiki/Macintosh "Macintosh") ...)

Retrieved from "[http://en.wikipedia.org/wiki/Logo\_(programming\_language)](http://en.wikipedia.org/wiki/Logo_%28programming_language%29) "

[Categories](http://en.wikipedia.org/wiki/Special:Categories "Special:Categories") : [Dynamically-typed programming languages](http://en.wikipedia.org/wiki/Category:Dynamically-typed_programming_languages "Category:Dynamically-typed programming languages") | [Educational programming languages](http://en.wikipedia.org/wiki/Category:Educational_programming_languages "Category:Educational programming languages") | [Functional languages](http://en.wikipedia.org/wiki/Category:Functional_languages "Category:Functional languages") | [Lisp programming language family](http://en.wikipedia.org/wiki/Category:Lisp_programming_language_family "Category:Lisp programming language family") | [1960s software](http://en.wikipedia.org/wiki/Category:1960s_software "Category:1960s software") | [Robotics suites](http://en.wikipedia.org/wiki/Category:Robotics_suites "Category:Robotics suites")