What programming language is most like natural language?

Programming LanguagesNlp

Programming Languages Problem Overview


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.

Programming Languages Solutions


Solution 1 - Programming Languages

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".

Solution 2 - Programming Languages

Depends on what circles you roll in, but LOLCODE could be considered like natural language ;)

Example loop:

HAI
    CAN HAS STDIO?
    I HAS A VAR
    IM IN YR LOOP
        UP VAR!!1
        VISIBLE VAR
        IZ VAR BIGGER THAN 10? KTHXBYE
    IM OUTTA YR LOOP
KTHXBYE

On a serious note, VB is a pretty natural language. It's easy for non-programmer types to learn, so the syntax must be pretty easy to understand.

Solution 3 - Programming Languages

The language Richard Pryor used to transfer millions of dollars with in Superman III was very close:

> TRANSFER $1,000,000 DOLLARS TO WEBSTER'S ACCOUNT.... NOW

;-)

EDIT: characters corrected ;-)

Solution 4 - Programming Languages

COBOL reads a lot like English

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.     HELLOWORLD.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 MAIN-LOGIC SECTION.
100300 BEGIN.
100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
100600     STOP RUN.
100700 MAIN-LOGIC-EXIT.
100800     EXIT.

source

Solution 5 - Programming Languages

Lisp (of course (if you know what I mean (LOL)))

Solution 6 - Programming Languages

Good 'ol http://en.wikipedia.org/wiki/AppleScript">AppleScript</a> touts its likeness to english as one of its strengths. However, it's not very fun to work with.

Solution 7 - Programming Languages

If you're a connoisseur, the Shakespeare Programming Language is fairly natural ;)

There is a limit to how 'natural' you can get in programming though. Human languages are too open to interpretation - a programming language needs to be specific and precise, I don't think that meshes well with having a 'natural' programming language.

Solution 8 - Programming Languages

HyperTalk - the language behind Apple's HyperCard.

 on mouseUp
   put "100,100" into pos
   repeat with x = 1 to the number of card buttons
     set the location of card button x to pos
     add 15 to item 1 of pos
   end repeat
 end mouseUp

HyperTalk on Wikipedia

Solution 9 - Programming Languages

I don't know that I'd go as far as to say that VB.NET is close to the English language, but I think it's about as close as you really get. Sure, once you've programmed it for a while, it seems like English - it does read like a book to a seasoned VB programmer, but if you stop and think about real world English:

For i As Integer = 1 To 10
  Console.WriteLine("Hello World")
Next

Is a long way from:

> Write "Hello World" and move to the next line of the console 10 times.

Of course, the English is ambiguous - does it want you to do the whole thing 10 times, or just write "Hello World" once and then move to the next line 10 times?

I guess we need to learn to talk in a less ambiguous fashion:

> Do this 10 times: In the console, write "Hello World" and move to the next line.

But I doubt very much there's a programming language that really reads like English. Even those Cobol fanatics that say it's like natural language - it really isn't if you stop and think about how you think about things in a real way instead of in the manner defined by the programming language.

Even in VB you're limited to the way the framework dictates the way you do things...

Solution 10 - Programming Languages

Well, Plain English, of course!

To sing the beer song:
  Put 99 into a number.
  Loop.
  If the number is 0, break.
  Format a string given the number and "bottle" and "bottles".
  Write the string then " of beer on the wall, " then the string then " of beer.".
  Format another string given the number minus 1 and "bottle" and "bottles".
  Write "Take one down and pass it around, " then the other string then " of beer on the wall.".
  Skip a line.
  Subtract 1 from the number.
  Repeat.
  Write "No more bottles of beer on the wall, no more bottles of beer.".
  Write "Go to the store and buy some more, 99 bottles of beer on the wall.".

To format a string given a number and a singular string and a plural string:
  If the number is 0, put "no more " then the plural into the string; exit.
  If the number is 1, put "1 " then the singular into the string; exit.
  Put the number then " " then the plural into the string.

I haven't actually used this - I found it here.

Solution 11 - Programming Languages

Perl has some design principles that are based on how humans process natural languages (see http://www.wall.org/~larry/natural.html ).

That's a different thing from syntactical hacks to make code read like sentences in English or some other language. I'm not entirely convinced that those are useful. As an analogy, I can also make ASCII art with my code, but that doesn't mean that my language is based on principles of visual composition.

To give an example of where it may not be useful,suppose this does what it looks like it does in some rubyish/smalltalky language:

3.times say "hello!" 

That's nice, it makes my code a bit more readable, and there's a similar sort of fun in it to having a parrot that can talk, but it's only useful if I know the underlying rules of the computer language. The fact that it happens to look like English gives me no extra leverage or insight. I can't use the English grammar processing engine in my brain to generate sentences like the following:

// The dot looks like misplaced punctuation 
// in the "English" above, but it's essential in 
// the computer language
3 times say "hello!" // syntax error

// In a natural language, a reordering might make
// sense, but it's impossible here because the word
// order was essential to carrying the parameters
// to the method invocation in the right order.
say "hello" 3 times // syntax error

Solution 12 - Programming Languages

gherkin is a domain specific language to describe executable bdd-specifications. It is used among other by cucumber (ruby) and specflow (dotnet).

Example

	Feature: Browsing
		In order to see who's been on the site
		As a user
		I want to be able to view the list of posts

	Scenario: Navigation to homepage
		When I navigate to /Guestbook
		Then I should be on the guestbook page

	Scenario: Viewing existing entries
		Given I am on the guestbook page
		Then I should see a list of guestbook entries
			And guestbook entries have an author
			And guestbook entries have a posted date
			And guestbook entries have a comment

	Scenario: Most recent entries are displayed first
		Given we have the following existing entries
			| Name      | Comment      | Posted date       |
			| Mr. A     | I like A     | 2008-10-01 09:20  |
			| Mrs. B    | I like B     | 2010-03-05 02:15  |
			| Dr. C     | I like C     | 2010-02-20 12:21  |
		  And I am on the guestbook page
		Then the guestbook entries includes the following, in this order
			| Name      | Comment      | Posted date       |
			| Mrs. B    | I like B     | 2010-03-05 02:15  |
			| Dr. C     | I like C     | 2010-02-20 12:21  |
			| Mr. A     | I like A     | 2008-10-01 09:20  |

Solution 13 - Programming Languages

Well, Ruby and Python are supposed to be fairly close. Ruby even goes to the length of adding special keywords that simulate real life. Such as the unless keyword, etc.

Of course, one you type real code in either of those 2 languages, it's not really like natural language, but then again what is?

Solution 14 - Programming Languages

I'd say SQL or COBOL.

Solution 15 - Programming Languages

the syntax of VB.NET is very near to English language

Solution 16 - Programming Languages

Forth is reverse-Polish based, and would work naturally for some people.

"Learn Forth quickly I will" - Yoda.

Solution 17 - Programming Languages

Well natural language is equivocal, and takes a bit more than a literal linear reading to understand. But that being granted, VB.NET is getting close in some constructs. Closest I've seen.

For Loop in VB.NET

For i = 0 To 2
  'loop time!
Next i

It's about as "natural" as I've seen without being too verbose.

Solution 18 - Programming Languages

That is called "pseudocode". You use whatever means necessary to communicate the intent of the code (you have written or will later write).

Any programming language has some features that are ambiguous to outsiders.

Solution 19 - Programming Languages

Although not exactly what you asked for, there are languages that accomplish what you want, but from the other direction. Lojban, for example, is a language made to be used as a natural language, but without ambiguity.

> Lojban (pronounced [ˈloʒban]) is a > constructed, syntactically unambiguous > human language based on predicate > logic.

Solution 20 - Programming Languages

Applescript looks like natural language.

Solution 21 - Programming Languages

I believe William Shakespeare was the world's best programmer...

The Shakespeare Programming Language

Solution 22 - Programming Languages

I believe your question is based on a fallacy. Programming is not mainly about translating from human to computer language. It is understanding technical problems and designing programs that is hard, typing in the code is a minor part. Learning a programming language won't make someone a programmer any more than learning musical notation will make them a composer.

That said, if you write at a high enough level in almost any language and spend a few minutes explaining syntax, you can communicate the gist of a piece of code to a dedicated non-programer. Conversely, a precise enough natural language specification can sometimes be translated into high level functions (although people are rarely willing to put in the effort to write such a spec.)

Solution 23 - Programming Languages

COBOL was created with the specific intent of being like natural language (English in this case)

Solution 24 - Programming Languages

With Ruby and Oslo (and possibly F#), you could build a very language-friendly DSL. That's at least the promise of Oslo. You can find an example of an Oslo grammar for BDD here.

Solution 25 - Programming Languages

Sanskrit comes close to what you describe. It has no redundancies, it was the first language to follow BNF which is the basis of all modern prog. language grammar, and it shares a common Indo-European descent with English

Solution 26 - Programming Languages

Cobol is close to English as it gets

I believe Logo is also not too far from the English language

Solution 27 - Programming Languages

I wish there was a COmmon Business Oriented Language that read like English so everyone, even non-programmers could unterstand it... Maybe we should create one! (stolen from here)

Solution 28 - Programming Languages

What we normally call "pseudo-code" is very, very close to Pascal. That probably doesn't make it particularly close to natural English, but if it weren't simpler than most langauges, we wouldn't write pseudo-code at all (we'd just write code).

Solution 29 - Programming Languages

I thought of Eiffel. Quote from here:

> Raphael Simon, lead software engineer > for Eiffel Software, said the language > was designed so that one could use > natural language to write the program.

See for example the 99 bottles of beer program.

I wouldn't say it's the "most" natural, but I find it rather natural.

Solution 30 - Programming Languages

For me, It is Python.

YMMV

Solution 31 - Programming Languages

I propose Lua. Sample Code:

function modulus(num, mod)
    return num % mod
end
for i = 1, 1000 do
    local done = false
    if modulus(i, 3) == 0 then
        print("Fizz")
    else if modulus(i, 5) == 0 then
        done = true
        print("Buzz")
    end
    if modulus(i, 5) == 0 and not done then
        print("Buzz")
    end
    print(" ")
end

not the most english-like, but pretty darn readable even if i do say so myself!

Solution 32 - Programming Languages

Of course it would also have to have an ability to generate concepts and then "name" these concepts, so these could be used to express more complex construct, i.e. basically would have to have some sort of support for ontology of the world, it is supposed to be used in. I think if something like "inform" language describe in an earlier post, coupled with some backend concept network or ontology database, would be a good way to start.

Solution 33 - Programming Languages

Natural languages are notorious for their inconsistent grammars. The most consistence grammar of any natural language is of Sanskrit. In fact the structure of this language is so solid that it was possible to have a prominent search engine based on pronunciation. Alas, this language is more or less is dead.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkliketaView Question on Stackoverflow
Solution 1 - Programming LanguagesBeskaView Answer on Stackoverflow
Solution 2 - Programming LanguagesAlex FortView Answer on Stackoverflow
Solution 3 - Programming LanguagesGalwegianView Answer on Stackoverflow
Solution 4 - Programming LanguagesJosh MeinView Answer on Stackoverflow
Solution 5 - Programming LanguagesCarl SeleborgView Answer on Stackoverflow
Solution 6 - Programming LanguagesBartek TatkowskiView Answer on Stackoverflow
Solution 7 - Programming Languagesuser7094View Answer on Stackoverflow
Solution 8 - Programming LanguagesAnthonyLambertView Answer on Stackoverflow
Solution 9 - Programming LanguagesBenAlabasterView Answer on Stackoverflow
Solution 10 - Programming LanguagesLucas JonesView Answer on Stackoverflow
Solution 11 - Programming Languagesuser8599View Answer on Stackoverflow
Solution 12 - Programming Languagesk3bView Answer on Stackoverflow
Solution 13 - Programming LanguagesSashaView Answer on Stackoverflow
Solution 14 - Programming LanguagesGraeme PerrowView Answer on Stackoverflow
Solution 15 - Programming Languagesuser434917View Answer on Stackoverflow
Solution 16 - Programming LanguagesDavid ThornleyView Answer on Stackoverflow
Solution 17 - Programming LanguagesSampsonView Answer on Stackoverflow
Solution 18 - Programming LanguagesLeonidasView Answer on Stackoverflow
Solution 19 - Programming LanguagesGraphics NoobView Answer on Stackoverflow
Solution 20 - Programming LanguagesmouvicielView Answer on Stackoverflow
Solution 21 - Programming LanguagesMike RobinsonView Answer on Stackoverflow
Solution 22 - Programming LanguagesRossFabricantView Answer on Stackoverflow
Solution 23 - Programming LanguagesJason PunyonView Answer on Stackoverflow
Solution 24 - Programming Languagesuser29439View Answer on Stackoverflow
Solution 25 - Programming LanguagesRenoView Answer on Stackoverflow
Solution 26 - Programming LanguagesSQLMenaceView Answer on Stackoverflow
Solution 27 - Programming LanguagesTamas CzinegeView Answer on Stackoverflow
Solution 28 - Programming LanguagesrmeadorView Answer on Stackoverflow
Solution 29 - Programming LanguagesDaniel DaranasView Answer on Stackoverflow
Solution 30 - Programming LanguagesrpgView Answer on Stackoverflow
Solution 31 - Programming LanguagesRCIXView Answer on Stackoverflow
Solution 32 - Programming LanguagesdattaView Answer on Stackoverflow
Solution 33 - Programming LanguagesDilawarView Answer on Stackoverflow