After playing around with Logo for a week or so, I decided to jump in and learn Lisp. Logo, with its lists and its functional style, reminded me of Lisp, so I wasn't surprised to learn that "Logo ... is a dialect of Lisp."
Over the past two years I've been increasingly fascinated by the high praise heaped upon Lisp by many leading programmers, and have watched with interest as others dip their toes in the Lisp pond. All in all, it just seemed like a good time to see what the fuss is about.
A bit of Googling and clicking later, I decided that Scheme, rather than Common Lisp, is the better option for someone whose main aim is to learn Lisp. The next step was to pick a Scheme implementation, and I downloaded DrScheme, because it had an IDE, and came with an online book called "Teach Yourself Scheme in Fixnum Days".
My main memory of university Lisp is counting parentheses. I had to spend hours counting each and every one - back and forth, up and down - to make sure they matched, and matched in the way the program needed them to. I was very happy to find that the DrScheme IDE counted parentheses for me, highlighting the matching parenthesis and everything in between, each time I cursor over one. It has a helpful code indenter too. After just a few hours, I'm not so worried by the little curvy things any more.1
The main DrScheme IDE window has a file edit area at the top, and a REPL area at the bottom. You type your program in the top window, click the "run" button and watch the results come out the bottom. Pretty easy. You can call up a help window to access some pretty comprehensive documentation, including two books - "Teach Yourself Scheme", mentioned above, and "How to Design Programs", a basic computing science text.
Primarily built as a teaching environment, DrScheme comes with plenty of fun bits. On discovering the included turtle graphics library, I immediately set about recreating every Logo program I have ever written. It brought a smile to my face.
Scheme is not object oriented in the sense that Smalltalk or Java is object oriented; the Scheme specification does not mandate OO constructs like class or method definitions. DrScheme, on the other hand, comes with two implementations of objects and classes, one of which is a standard library while the other is part of an extension library called "Swindle", and claims some compatability with CLOS. The Teach Yourself Scheme book suggests a third way. I'm currently using the standard libary OO, and it's working just fine.
The only gripe I have with DrScheme is that some implementation specific features are too poorly documented for me to use them properly. The upcoming book "How to use Scheme" might remedy the situation.
To this programmer, the striking thing about Lisp is the wide range of choices at almost every step along the way. The only things that aren't optional are parentheses.^2^ While choice has its downsides, from a learning perspective I greatly appreciate seeing multiple implementations of the same basic ideas.
In my next Lisp post, I'll explain how I'm using Lisp to clean up my lounge room.
1My experience with parentheses in Scheme is similar to my experience with indenting in Python, in that I initially I found it hard to follow the code structure, but learned quickly enough.
2Although, if Logo really is a dialect of Lisp, then parentheses are optional too.
One reason for having a weblog is that it makes a handy notebook of important things to remember. For instance, I cut-and-paste from this post on reconfiguring log4j every few months.
Now, excuse me while I code a small patch for a production application...
Bill’s reality distortion field was – no doubt – still affecting Casey as he wrote, and it caused him to coin a new phrase, a phrase that I look forward to being able to use myself, one day. He says,
I did, however, stand on the inner surface of the donut…
Concerning a fictional event, in one act. For four players.
The Manager has made three cups of tea. He hands one to each of the Other Employees.
Other Employees: Thankyou, thankyou.
The Manager: You're welcome.
The Manager picks up his own cup.
Employee Without Tea: Oh. Where's mine?
TM: I thought you said you didn't want one.
EWT: No, I said I did want one. But it's OK... I'll make my own.
TM: Sorry about that. I'll make one for you.
The Manager gets a cup and teabag from the drawer. He puts the cup next to the jug, puts the teabag in the cup. The he picks up his own cup and steps back.
TM (To EWT): First, boil the jug again, so the water's nice and hot.
Employee Without Tea puts the jug on to boil. The Manager looks on in satisfaction, enjoying his tea. The jug, having just been boiled, reboils in just a few seconds.
TM: Yes, it's important to have the water at the right temperature for tea.
The Other Employees nod vigorously at The Manager's wise pronouncement.
TM: Now, quickly, while the water's still boiling, pour the water into the cup.
Employee Without Tea pours the jug.
TM: OK. And now just jiggle it up and down until it's the colour you want.
Employee Without Tea picks up cup and jiggles the teabag. As he jiggles, he starts to realise who is making the cup of tea.
TM: There you go. Nothing like a good hot cup of tea, is there?
EWT: Err... Thankyou?
TM: You're welcome!
Exit The Manager, job well done.
Just to clarify, yes, this is fictitious. It sprung into my head after hearing just two or three half-sentences emanating from the tea room this morning. Given the people involved, my fanciful imagination is certainly wrong. That said, there are one or two workplaces I've known where it might have happened exactly like that.
Looking for a way to introduce programming to my sons, I downloaded MSWLogo the other day. Gee it’s fun.
Logo was designed as a teaching language. Logo is centred around the turtle and the drawing area. You give simple commands to the turtle –
forward 100 and
right 90 – and wherever the turtle goes, it leaves a line. You can combine these commands into simple programs, and with just a few lines of code, can draw some neat patterns.
I settled on MSWLogo, on the strength of positive comments from pages I found by searching for logo programming on Google. MSWLogo has a drawing window, a command window and a text editor (screenshot). What more could a junior programmer want?
Fiddling with Logo on the way home reminded me of my first, tentative adventures with Basic on the TRS-80 pocket computer. Logo is responsive and interesting – you can “make it do stuff.”
Time for an example. Here is the turtle on a blank screen:
The turtle is kind of triangular. According to one Logo text, its name is Ernestine. The turtle’s pen is tied to its tail, right in the middle of its flat backside. Now, using the editor, we rattle off a quick program:
repeat 4 [forward 50 right 90]
From the command prompt, we can now type ”
square”, and sure enough:
The triangle is, of course, the turtle, back where it started, in the middle of the screen. Now we can use our square in another program:
repeat 8 [
And here is what it looks like:
Not bad for a few lines of code. What I found most fun, though, was drawing fractals with recursion. This little routine draws a tree, splitting each branch in two.
to tree :size
if (:size > 10) [
tree :size * 0.8
tree :size * 0.8
tree 30” gives:
More complex fractals can be drawn with not that much more code. I even had it drawing the dragon curve in eight lines of code.
MSWLogo comes with an impressive range of demos. There are some 3d graphics, a bunch of games, and a Pascal compiler, written in Logo, that converts Pascal to Logo and executes it.
I’m glad I gave Logo a whirl. It stretched me, All in all, I can heartily recommend Logo as a fun toy for programmers. Logo encourages a different kind of thinking, and gives a big payback for a small investment.