Usergenic

Thoughts on humane software development

The Inform Language

| Comments

I’ve been fascinated for a little while by the programming language called Inform 7. (Note as of writing, the main website is under maintenance, so here is the Inform Wikipedia article as backup.) It is a language designed specifically for crafting works of interactive fiction (aka “text adventures”). Version 7’s syntax in particular is based on natural language, and as a result, source code for games written in Inform are often quite intelligible to those not well versed in programming or the Inform language specifically.

Here is an example of defining mutually exclusive properties…

Boolean properties
1
2
3
A thing can be lit or unlit.
A person can be slumbering or wakeful.
A person is usually wakeful.

Here’s an interesting predicate “instead” which provides an override kind of like aspect oriented programming…

Instead
1
2
Instead of doing something to a slumbering wyvern,
say "Best let sleeping wyverns lie."

Here’s a simple rule that changes the lit/unlit based on light source…

Lit/Unlit
1
2
Every turn: if the player is not affected by light,
now the player is unlit.

A before advice to guard saving the game when not in a safe place…

Save game guard
1
2
3
4
5
6
Check saving the game: if the location is not the
Sanctum Sanctorum and the location is not the
Temple of Peace, say "(The game can only be saved
when in an indisputably safe place. This is not
that place. You will know it when you find it.)"
instead.

Here’s an after advice to modify the display of a character based on their state of being in a web or not…

Webbed
1
2
After printing the name of a person who is affected
by web when we are looking, say " (webbed)".

Sometimes the emphasis on natural language becomes a little contorted though when writing procedural code…

Inform language example
1
2
3
4
5
6
7
8
This is the exorcise undead removal rule:
    repeat with turned one running through
    the undead people in the location
    begin;
        remove the turned one from play;
        award the permanent strength
        of the turned one points;
    end repeat.

Anyways just found this kind of interesting/inspirational and wanted to share.

Comments