什么编程语言最像英语?

时间:2010-06-18 05:27:26

标签: applescript programming-languages nlp

我主要是一个Python程序员,它经常被描述为“可执行的伪代码”。我使用了一点AppleScript,它似乎是我见过的最类似英语的编程语言,因为几乎所有运算符都可以是单词,它可以让你在任何地方使用“the”(例如,这个愚蠢的例子我只是想出了:

set the firstnumber to 1
set the secondnumber to 2
if the firstnumber is equal to the secondnumber then 
    set the sum to 5
end if

是一个有效的AppleScript程序。是否有比这些语言更像英语的编程语言?

11 个答案:

答案 0 :(得分:14)

如果你的意思是在规则的应用方面存在不一致,有很多奇怪的边缘情况和尖锐的角落会伤害学习者,那么很少有编程语言比C ++更像英语。

答案 1 :(得分:12)

莎士比亚的回答让我想起了Inform 7,这是一种用于编写互动小说的严肃编程语言。它可能是最接近英语的语言,并且具有明确定义的语义。

以下是维基百科的一个示例:

"Hello Deductible" by "I.F. Author"

The story headline is "An Interactive Example".

The Living Room is a room. "A comfortably furnished living room."
The Kitchen is north of the Living Room.
The Front Door is south of the Living Room.
The Front Door is a door. The Front Door is closed and locked.

The insurance salesman is a man in the Living Room. "An insurance salesman in a tacky polyester suit. He seems eager to speak to you." Understand "man" as the insurance salesman.

A briefcase is carried by the insurance salesman. The description is "A slightly worn, black briefcase." Understand "case" as the briefcase.

The insurance paperwork is in the briefcase. The description is "Page after page of small legalese." Understand "papers" or "documents" or "forms" as the paperwork.

Instead of listening to the insurance salesman for the first time:

    say "The salesman bores you with a discussion of life insurance policies. From his briefcase he pulls some paperwork which he hands to you.";
    move the insurance paperwork to the player.

该示例使用了一个广泛的对象库,可供用户使用。但是语言本身实际上是图灵完成的,你可以定义具有任何行为的对象。

答案 2 :(得分:9)

冒着被肆无忌惮的手指摇摆的风险:我声称自然语言就像编程语言一样糟糕。具体来说,自然语言话语的目标是影响世界,以便其他人想要吻你而不是打你;这与编程语言话语的目标非常不同,编程语言话语旨在作为计算机或其他人可以评估的明确定义的域中的明确语句。一个更好的问题可能是:哪种编程语言最难以意外地射击自己?

......当然,这根本不是你所要求的。

答案 3 :(得分:6)

COBOL一直被认为是非常“自然的语言”。以下是99 bottles of beer page

的摘录
move spaces to buffer bb1                                 
move 1 to j                                               
divide i by 10 giving k remainder l                       
string bb8(k + 1) delimited space into bb1 pointer j      
if j > 1                                                  
   then move bb7(l + 1) to bb1(j + 1:)                    
   else move bb7(i + 1) to bb1                            
end-if

当然,“自然语言”并不总是(通常是)一种编程语言的优点,其中精确性是一天的顺序(自然语言几乎总是模棱两可的 - 增加了编程语言所需的精确性它详细)。

答案 4 :(得分:4)

Shakesspeare编程语言怎么样?以下是wikipedia中“hello world”来源的一部分:

               Act I: Hamlet's insults and flattery.
               Scene I: The insulting of Romeo.

[Enter Hamlet and Romeo]
Hamlet:
You lying stupid fatherless big smelly half-witted coward! You are as
stupid as the difference between a handsome rich brave hero and thyself!
Speak your mind!
You are as brave as the sum of your fat little stuffed misused dusty
old rotten codpiece and a beautiful fair warm peaceful sunny summer's
day. You are as healthy as the difference between the sum of the
sweetest reddest rose and my father and yourself! Speak your mind!
You are as cowardly as the sum of yourself and the difference
between a big mighty proud kingdom and a horse. Speak your mind.
Speak your mind!
[Exit Romeo]

似乎代码突出显示在这里不起作用。 :/

答案 5 :(得分:3)

VB.NET(尽管你的AppleScript示例胜过VB.NET),SQL或COBOL(这种风格的来源)。 Lolcode就像“语言”一样,但我很高兴英语不喜欢它。

VB.NET

If MsgBox("The process will be started", MsgBoxStyle.OkCancel, "Title") = DialogResult.OK Then 
   'ok was clicked
Else
  'cancel was clicked
 End If

COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
    RECORD CONTAINS 55 CHARACTERS
    DISPLAY 'Hello, world'.
    STOP RUN.

SQL

SELECT * 
    FROM Book
    WHERE price > 100.00
    ORDER BY title;

Lolcode

ON CATURDAY
    IM IN YR BED
        I IZ SLEEPIN!!10
        VISIBLE "Z!"
    KTHX
KTHXBYE

答案 6 :(得分:2)

在回顾完所有答案之后,我确信AppleScript实际上是最自然的语言。

答案 7 :(得分:1)

您是否听说过Supernova。这是一种自然的编程语言。甚至只需说I want window and the window title is hello.

就可以在Supernova中创建一个窗口

答案 8 :(得分:0)

我讨厌插入我自己的东西(不是真的),但7Basic有一个非常英语的语法:

BEGIN FUNCTION (variable AS INTEGER) AS STRING
    PRINT "Hello!"

    RETURN "return value!"
END FUNCTION

答案 9 :(得分:0)

我认为讨论Dijkstra类程序精度在哪里是必要的而不是在哪里不是很有趣。在需要细节的低级编程中,精度也是如此。由于编程原语更高层次,也许不是那么多......

答案 10 :(得分:-4)

也许是Common Lisp? Lisp中的宏允许您将抽象定义为“新单词”。这就像你想要的那样接近伪代码或英语(因为在我们的思想或讨论中描述程序时,我们使用了大量来自特定语言的机制的抽象)。

一个有趣的例子是回指宏,Paul Graham在其着作“论Lisp”中描述了这些宏。回指宏是一个宏,它将一些表达式绑定到它体内的符号“it”,所以我们可以很容易地引用它:

(aif (get-data) (do-something it)) 

在这一行中,get-data是一个返回某个对象或nil的函数。如果它返回数据,它们将绑定到“it”变量,该变量由“do-something”函数处理。如果返回的数据为nil,则不满足条件,并且不执行该子句。

还有许多其他的回指宏示例,例如for循环,它们绑定循环变量,依此类推。事实上,你甚至可以拥有为你生成照应宏的宏。

相关问题