Natural Language and DSLs

A year ago I had blogged about Inform 7, an interesting DSL for the implementation of interactive fiction. I had briefly explored it, but didn’t do much more, because some of the concepts made it hard to use for my purposes (e.g. “relations” could only be defined between instances of objects, not classes. So you needed a lot of workarounds). However, just recently the developers released a new version that removes several limitations.

I happen to come back to look at the DSL, if only for inspiration on how you can find notations that seem natural and yet are formal.  Inform 7

  • wants describe a “world” in an executable way
  • expects its users to be literary inclined, not programming geeks.

These goals are obviously similar to the use of DSLs. An example of how a description of a physical system could look like can be found in the examples:

1
2
3
4
5
6
7
8
9
10
11
12
"Lead Cuts Paper"
 
A weight is a kind of value. 10kg specifies a weight. Everything has a weight. A thing usually has weight 1kg.
 
A container has a weight called breaking strain. The breaking strain of a container is usually 50kg. Definition: A container is bursting if the total weight of things in it is greater than its breaking strain.
 
A lead pig, a feather, a silver coin and a paper bag are in a room called the Metallurgy Workshop. The paper bag is a container with breaking strain 2kg.  The lead pig has weight 50kg.
 
Every turn when a container (called the sack) held by someone visible (called the chump) is bursting:
 say "[The sack] splits and breaks under the weight! [if the player is the chump]You discard[otherwise][The chump] discards[end if] its ruined remains, looking miserably down at [the list of things in the sack] on the floor.";
 now all of the things in the sack are in the location;
 remove the sack from play.

Especially the first three lines show how a physical system with rules can be described in (almost) natural language. And it can actually be executed. This is a transcript of the session:

Lead Cuts Paper
An Interactive Fiction
Release 1 / Serial number 100707 / Inform 7 build 6E72 (I6/v6.31 lib 6/12N) SD
 
Metallurgy Workshop
You can see a lead pig, a feather, a silver coin and a paper bag (empty) here.
 
>get pig
Taken.
 
>get bag
Taken.
 
>put pig into bag
You put the lead pig into the paper bag.
 
The paper bag splits and breaks under the weight! You discard its ruined remains, looking miserably down at the lead pig on the floor.

Of course, we’d probably not describe lead pigs put components of cars and satellites ….

 

Another interesting feature is the specification of tabular data. Again from the docs:

Table 2.1 – Selected Elements

Element Symbol Atomic number Atomic weight
“Hydrogen” “H” 1 1
“Iron” “Fe” 26 56
“Zinc” “Zn” 30 65
“Uranium” “U” 92 238

And the access to the table:

symbol in row 3 of the Table of Selected Elements

It will be interesting to see, if notations like this will establish themselves more and more.

1 Response to "Natural Language and DSLs"

Leave a Comment