Uses of Textual DSLs: IF (Interactive Fiction)

I was reminded of the early age of text adventures by this slashdot article. The great adventures by Infocom and Magnetic Scrolls bring back memories of long hours of trying to solve puzzles. Text adventures have long lost their market share to graphical adventures, but it seems there is a strong community of interactive fiction. A quick look at the current tooling shows a surprising example of textual DSLs. The IF authoring system Inform 7 uses a textual DSL for specifying the game, that makes it easy for authors, not programmers, to create interactive fiction. Look at this piece of “source code”, describing objects and their locations and what happens, when you attack “the donkey”:

The Twinkie is a thing.
The description of the Twinkie is “A confection made of gelatin and preservatives.”
Two hands are part of every person.
The prevailing wind is a direction that varies.

Instead of attacking the donkey:
remove the donkey from play;
if the donkey carries something, now everything carried by the donkey is in the location;
say “The donkey bolts, of course.”


The textual DSL is a formal variant of English. The source code for the game itself reads like English. This is a more complex piece  code (from the Inform 7 docs):

“Interrogation”

The X-Ray Vision Wand is carried by the player.

Instead of waving the X-Ray Vision Wand:
say “Disappointingly, nothing happens.”

Instead of waving the X-Ray Vision Wand when the player can see someone who is concealing something:
say “The wand glows green. Immediately you see on the monitor [a list of things which are concealed by people who can be seen by the player].”

After printing the name of a thing (called target) which is carried by someone while waving the wand:
say ” (carried by [a random person who carries the target])”

The Interrogation Chamber is a room. “Despite its gothic name, this room is a rather civilized place for your work, with large plate-glass windows and a fitted carpet.”

A thing can be secret or obvious. A thing is usually obvious.

Brian is in the Interrogation Chamber.”Brian lounges against the wall.” Brian carries a quantity of plastic explosive. The explosive is secret.

Janine is in the Interrogation Chamber. “Janine toys nervously with a laptop bag.” Janine carries a chocolate biscuit, a laptop bag, and a microfilm. The microfilm is secret. The laptop bag is wearable. In the bag is a laptop computer.

Rule for deciding the concealed possessions of something: if the particular possession is secret, yes; otherwise no.

Instead of examining someone: say “[The noun] is openly carrying [a list of unconcealed things carried by the noun].”

Test me with “wave wand / examine janine / examine brian”.


Leave a Reply

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