Inventing a Language - Tortoise

In this lesson we'll apply everything we've learned in the last five lessons and create a new simple programming language. This time we'll create an imperative language.

The goal of our new language is to draw fun pictures using turtle graphics. It should be usable by young kids as well as playful adults. Hopefully the language will teach something about geometry and introductory programming, but mostly we just want cool pictures.

Turtle graphics involves drawing using a real or imagined turtle with a pen on its tail. A program consists of commands to the turtle such as "walk forward 10 spaces" or "turn right 90 degrees". As the turtle follows the commands it leaves a trail that creates the picture. LOGO was the language that made turtle graphics famous.

Example programs

Our language will be called Tortoise. We already have a pretty good idea of what the language is for and what the main features are. The next step in the design is writing some example programs and deciding how the syntax works.

Since this language is supposed to be accessible to kids we'll try to make the syntax as simple as possible. But we still want features like loops and functions since they help in making complicated pictures with very little code. We'll break with LOGO tradition and decide to make the syntax more like C or JavaScript, but with some unique keywords so it's clear it is its own language.

Here's an example that makes a pleasant circular rose design:

Here is an example program that defines a square function and uses it to draw two squares:

Here is a function that draws a spiral using recursion:

We're allowing variables. In Tortoise we'll make the programmer declare variable names before they are used; this will help avoid accidental variables being created because of typos. We'll use a special := symbol instead of just = to avoid confusion with the mathematics equality symbol.