What programming language is most like natural language?

kliketa picture kliketa · Jan 29, 2009 · Viewed 24.6k times · Source

I got the idea for this question from numerous situations where I don't understand what the person is talking about and when others don't understand me.

So, a "smart" solution would be to speak a computer language. :)

I am interested how far a programming language can go to get near to (English) natural language. When I say near, I mean not just to use words and sentences, but to be able to "do" things a natural language can "do" and by "do" I mean that it can be used (in a very limited way) as a replacement for natural language.

I know that this is impossible (is it?) but I think that this can be interesting.

Answer

Beska picture Beska · Jan 29, 2009

There is a programming language called Inform that, in its most recent incarnation, Inform 7, looks a lot like natural language...in particular, written language.

Inform is very specifically for creating text adventure games, but there is no inherent reason that the concepts couldn't be extended into other realms.

Here's a small snippet of Inform 7 code, taken from the game Glass, by Emily Short.

Stage is a room. 

The old lady is a woman in the Stage. Understand "mother" or 
"stepmother" as the old lady. The old lady is active. The description 
of the lady is "She looks plucked: thin neck with folds of skin
exposed, nose beaky, lips white. Perhaps when her fortunes are mended
her cosmetics too will improve." 

The Prince is a man in the Stage. The description of the prince is
"He's tolerably attractive, in his flightless way. It's hard not to
pity him a little." The prince carries a glass slipper. The glass
slipper is wearable. Understand "shoe" or "heel" or "toe" or "foot"
as the slipper. The description of the slipper is "It is very small
for an adult woman's foot." 

Complete code can be found here.

This is a small simple example...it can actually handle a surprisingly robust set of ideas.

It should be pointed out that the code isn't really a strange cypher where the constructs have hidden meanings...this code does more or less what you would expect. For example:

The old lady is a woman in the Stage. Understand "mother" or 
"stepmother" as the old lady. 

creates an object that happens to be a female person, names that object "old lady", and places that object within the room object called the "Stage". Then two aliases ("mother" and "stepmother" are created that also both reference the "old lady" object.

Of course, as the examples get increasingly complex, the necessary hoops to jump through also become more complex. English is, by its very nature, ambiguous, while computer code is most definitively not. So we'll never get a "perfect marriage".