Let’s hear it for Logo!

Recently I had the occasion of helping my autistic son with some elementary mathematics. He’s very averse to writing, but he doesn’t mind using a computer. And so I thought we might do a little experimenting with Logo and its Turtle Graphics. I haven’t used Logo really in over 20 years, I think. But I used to teach Logo as part of a “Computing for Education” subject and I developed a great fondness for the language. I’m happy to say that my recent rediscovery has only strengthened my regard for it.

Logo was developed at MIT in 1967 (which makes it 50 this year) by the late Seymour Papert and associates. It was designed as a “language for learning” and it’s one of the unfair twists of fate that most people’s conception of Logo (if they have one at all), is that it’s programming “for kids”; not a serious language; not worth considering by adults. Such a view is very wrong. Logo was designed according to the principle of “low threshold, high ceiling” which means that even very young children can drive a turtle around with simple commands; more adept programmers can write high-level compilers.

In many ways Logo has been superseded by more colourful, whizz-bang environments such as Scratch (also from MIT), and certainly Scratch is more immediately exciting and interesting. But Scratch is more of a kids environment. I don’t know of anybody who would seriously suggest teaching tertiary computing with Scratch. But Logo as such a beginner language has had a very persuasive advocate in Brian Harvey, whose three volumes of “Computer Science, Logo style” – still in print but also available as downloads from his website, show how Logo can be used to teach computing at a deep level.

Anyway, the apparent simplicity of Logo is one of its great strengths.

Logo is a dialect of Lisp, more by way of Scheme than Common Lisp, which should immediately give it some street cred. Although most people’s concept of Logo start and finish with Turtle Graphics, it has powerful text and list handling abilities, lots of control structures, and of course being a lisp-like language means you can write your own control structures for it.

There are many versions of Logo, but probably the closest to a “standard” would be the version developed by Brian Harvey and his students at the UC Berkeley, and known as Berkeley Logo, or just as ucblogo.

Here’s a little example of Logo in action: implementation of merge sort. As you may recall, this is a general purpose sorting algorithm that works by dividing the list into two roughly equal halves, recursively merge-sorting each half, and then merging the two sorted haves into one list. One of the many nice attributes of Logo is the ease of using recursion – so much so, in fact, that recursion is a more natural way of looping or repeating than standard for or while loops. So merge sort (or really, any other recursive procedure) is a doddle in Logo.

;; halve breaks up a list into two halves: [1 2 3 4 5] -> [[1 2] [3 4 5]]

to halve :list
localmake "n count :list
localmake "h int :n/2
output list (cascade :h [lput item # :list ?] []) ~
       (cascade (:n-:h) [lput item #+h :list ?] [])

;; merge joins two sorted lists

to merge :list1 :list2
if emptyp :list1 [output :list2]
if emptyp :list2 [output :list1]
ifelse (first :list1) < (first :list2) output se (first :list1) (merge (bf :list1) :list2) ~
       output se (first :list2) (merge :list1 (bf :list2))

;; This is the mergesort procedure

to mergesort :list
if emptyp :list output []
localmake "halves halve :list
output merge (mergesort first :halves) (mergesort last :halves)

This is a pretty brain-dead implementation, all I’ve done really is copy down the definition. No doubt a better Logo programmer could use more of its clever commands to write a smaller, and no doubt faster, program. You can see another version at the Rosetta Stone site; also check out their Logo version of Quicksort. And there are also many other algorithms implemented in Logo.

Leave a Reply

Your email address will not be published. Required fields are marked *