Which programming language is most similar to a natural language?

I came up with an idea on this issue from numerous situations where I do not understand what this person is talking about, and when others do not understand me.

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

I wonder how far a programming language can go to get closer to the (English) natural language. When I speak side by side, I do not mean just using words and sentences, but in order to be able to “do” things that a natural language can “do” and “do,” I mean that it can be used (in a very limited way ) as a substitute for natural language.

I know this is not possible (right?), But I think it might be interesting.

+54
programming-languages nlp
Jan 29 '09 at 15:12
source share
33 answers
  • one
  • 2

There is the Inform programming language, which in its latest incarnation, Inform 7, is very similar to a natural language ... in particular, to a written language.

Inform is very specific for creating adventure text games, but there are no reasons why concepts cannot be expanded to other areas.

Here's a small snippet of Inform 7 code taken from Glass, 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 tolerably attractive, in his flightless way. It 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 foot." 

Full code can be found here .

This is a small simple example ... he can really handle a surprisingly robust set of ideas.

It should be noted that the code is not really a weird cypher, where the constructs have hidden meanings ... this code does more or less what you expect. For example:

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

creates an object that is a female face that calls the object "old woman" and places this object in a room object called "Stage". Then two aliases are created ("mother" and "stepmother", which also refer to the object "old woman".

Of course, as examples become more complex, the necessary hoops for the transition also become more complex. English is inherently ambiguous, while computer code is most definitely absent. Therefore, we will never get a “perfect marriage”.

+115
Jan 29 '09 at 16:35
source share

Depends on what circles you enter, but LOLCODE can be considered as a 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 

With a serious record, VB is a fairly natural language. Easy for non-programming types to learn, so the syntax should be pretty easy to understand.

+43
Jan 29 '09 at 15:14
source share

The language in which Richard Prior used millions of dollars in Superman III was very close:

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

; -)

EDIT: fixed characters; -)

+31
Jan 29 '09 at 15:18
source share

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

+20
Jan 29 '09 at 15:17
source share

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

+18
Jan 29 '09 at 16:50
source share

Well 'ol AppleScript touts its resemblance to English as one of its strengths. However, working with him is not very convenient.

+17
Jan 29 '09 at 15:19
source share

If you are a connoisseur, Shakespeare's programming language is quite natural;)

There is a limit to how “natural” you can get in programming. Human languages ​​are too open for interpretation - the programming language must be specific and accurate, I do not think that it is well connected with the presence of a "natural" programming language.

+17
Jan 29 '09 at 15:23
source share

HyperTalk - Apple HyperCard language.

  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

+14
Jan 29 '09 at 15:36
source share

I do not know that I have come to the point that VB.NET is close to English, but I think it is about as close as you are. Of course, once you have programmed it for a while, it seems English - it reads like a book by an experienced VB programmer, but if you stop and think about the real world:

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

It has come a long way:

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

Of course, the English are ambiguous - does he want you to do all this 10 times or just write "Hello World" once, and then go to the next line 10 times?

I think we need to learn to speak less ambiguously:

Do this 10 times: on the console, write "Hello World" and go to the next line.

But I very much doubt that the programming language really reads like English. Even those Cobol fans who say it as a natural language are really not, if you stop and think about how you think about things in a real way, rather than how it is defined by a programming language.

Even in VB, you are limited by how the structure dictates how you do ...

+8
Jan 29 '09 at 15:38
source share

Good, Normal 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 have not actually used this - I found it here .

+7
Jan 29 '09 at 16:47
source share

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

Something else from syntactic hacks to make the code read like sentences in English or some other language. I am not entirely sure that they are useful. As an analogue, I can also make ASCII art with my code, but this does not mean that my language is based on the principles of visual composition.

To give an example of where this might not be useful, suppose that it does what it looks like in some ruby ​​/ small language:

 3.times say "hello!" 

This is good, it makes my code a little more readable, and it has the same fun in it that it has a parrot that can speak, but it is only useful if I know the basic rules of a computer language. The fact that this is similar to English does not give me any additional leverage or understanding. I cannot use English to process grammar in my brain to generate sentences like the following:

 // The dot looks like misplaced punctuation // in the "English" above, but it essential in // the computer language 3 times say "hello!" // syntax error // In a natural language, a reordering might make // sense, but it 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 
+6
Jan 29 '09 at 17:10
source share

gherkin is a domain language for describing executable bdd specifications. It is used among other cucumber (ruby) and specflow (dotnet).

Example

  Feature: Browsing In order to see who 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 | 
+6
Jan 19 '11 at 10:51
source share

Well, Ruby and Python should be pretty close. Ruby even gets to adding special keywords that mimic real life. For example, the if keyword, etc.

Of course, you type real code in either of these two languages, it doesn't look very much like a natural language, but again, what is it?

+5
Jan 29 '09 at 15:16
source share

I would say SQL or COBOL.

+5
Jan 29 '09 at 15:18
source share

VB.NET syntax is very close to English

+4
Jan 29 '09 at 15:17
source share

Forth is Polish, and for some people it will work naturally.

“Learn fast, I will” - Yoda.

+4
Jan 29 '09 at 18:29
source share

Well, natural language is ambiguous, and understanding requires a little more than literal linear reading. But, being provided, VB.NET comes close to some constructs. The closest I've seen.

For a loop in VB.NET

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

This is about the “natural,” as I have seen, without being too verbose.

+3
Jan 29 '09 at 15:15
source share

This is called "pseudo-code." You use any means necessary to transmit information about the intention of the code (you wrote or write later).

Any programming language has some functions that are ambiguous for outsiders.

+3
Jan 29 '09 at 15:20
source share

Although not quite what you asked for, there are languages ​​that do what you want, but from a different direction. Lojban , for example, is a language that is used as a natural language, but without ambiguity.

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

+3
Jan 14 '10 at 5:41
source share

Applescript looks like a natural language.

+2
Jan 29 '09 at 15:19
source share

I believe that William Shakespeare was the best programmer in the world ...

Shakespeare's programming language

+2
Jan 29 '09 at 16:51
source share

Sanskrit is close to what you are describing. It has no redundancy, it was the first language that follows BNF, which is the basis for all modern programs. linguistic grammar, and it shares a common Indo-European descent with English

+2
Mar 08 '09 at 17:13
source share

I believe your question is based on a bug. Programming is not generally related to translation from a human language to a computer. This is an understanding of technical problems and the development of programs that are complex; entering text into the code is secondary. Learning a programming language will not make someone a programmer more than learning a musical notation will make them a composer.

However, if you write at a fairly high level in almost any language and spend a few minutes explaining the syntax, you can convey the essence of the piece of code to a special non-programmatic one. Conversely, a sufficiently accurate specification of a natural language can sometimes be translated into high-level functions (although people rarely want to make an effort to write such a specification.)

+2
Jan 14 '10 at 6:35
source share

COBOL was created with the special intention of being like natural language (in this case, English)

+1
Jan 29 '09 at 15:17
source share

With Ruby and Oslo (and possibly F #) you can create a very easy-to-use DSL. This is at least Oslo's promise. You can find an example of Oslo grammar for BDD here .

+1
Jan 29 '09 at 15:39
source share

For me, this is Python.

Ymmv

+1
Aug 05 '10 at 17:34
source share

Cobol is close to English since it gets

I believe that the logo is also not too far from English

0
Jan 29 '09 at 15:18
source share

I would like for CO mmon B usiness O to be L- oriented, which reads like English, so everyone, even non-programmers, could get away from it ... Maybe we should create it! ( stolen from here )

0
Jan 29 '09 at 15:22
source share

What we usually call "pseudo-code" is very, very close to Pascal . This probably does not make it particularly close to natural English, but if it weren’t easier than most languages, we wouldn’t write pseudo-code at all (we just write the code).

0
Jan 29 '09 at 16:05
source share

I suggest Lua . Code example:

 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, but pretty damn readable, even if I say so myself!

0
Aug 29 '09 at 3:12
source share
  • one
  • 2



All Articles