Article development led by
Sometimes you just have
to make a better mousetrap.
By Matthew fLatt
cHoosInG THe RIGHT tool for a simple job is easy:
a screwdriver is usually the best option when you need
to change the battery in a toy, and grep is the obvious
choice to check for a word in a text document. for more
complex tasks, the choice of tool is rarely so straightforward—all the more so for a programming task,
where programmers have an unparalleled ability to
construct their own tools. Programmers frequently
solve programming problems by creating new tool
programs, such as scripts that generate source code
from tables of data.
Since programmers often build task-specific tools,
one way to make them more productive is to give them
better tool-making tools. When tools take the form of
program generators, this idea leads to libraries for creating
languages that are directly extensible. Programmers may
even be encouraged to think about a problem in terms of a
language that would better support the task. This approach
is sometimes called language-oriented programming. 3
Racket is both a programming language and a framework for building
programming languages. A Racket
program can contain definitions that
extend the syntax of the language for
use later in the same program, and
language extensions can be packaged
as modules for use in multiple programs. Racket supports a smooth path
from relatively simple language extensions to completely new languages,
since a programming tool, like any
other piece of software, is likely to start
simple and grow as demands on the
As an example task, consider the
implementation of a text-adventure
game (also known as interactive fiction), where a player types commands
to move around in a virtual world and
interact with objects:
You’re standing in a meadow.
There is a house to the north.
You are standing in front of a house.
There is a door here.
> open door
The door is locked.
To make the game interesting, a
programmer must populate the virtual
world with places and things that have
rich behavior. Most any programming
language could implement this virtual
world, but choosing the right language
construct (that is, the right tool) to represent each game element is a crucial
step in the development process.
The right constructs allow commands, places, and things to be created easily—avoiding error-prone boilerplate code to set up the world’s state
and connections—while also allowing
a programming language’s full power
to implement behaviors.
In a general-purpose programming language, no built-in language
construct is likely to be a perfect
fit. For example, places and things
could be objects, while commands
could be implemented as methods.
The game’s players, however, don’t