什么编程语言最像英语?

发布于 2024-09-06 06:47:39 字数 338 浏览 7 评论 0原文

我主要是一名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 程序吗?是否有比这些更类似于英语的编程语言?

I'm mainly a Python programmer, and it is often described as being "executable pseudo-code". I have used a little bit of AppleScript, which seems to be the most English-like programming language I have ever seen, because almost operators can be words, and it lets you use "the" anywhere (for example, this stupid example I just came up with:

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

is a valid AppleScript program. Are there any programming languages that are even more English-like than these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

情场扛把子 2024-09-13 06:47:39

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

If you mean inconsistent in application of rules with lots of bizarre edge cases and sharp corners to injure the learner, there's very few programming languages more English-like than C++.

百合的盛世恋 2024-09-13 06:47:39

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

以下是来自 Wikipedia 的示例:

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

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

The Shakespeare answer reminded me of Inform 7, which is a serious programming language for writing interactive fiction. It's probably the language most closest to English that exists and has a well-defined semantics.

Here is a sample from Wikipedia:

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

The sample uses an extensive library of objects which is available for user. But the language itself is in fact Turing complete, and you can define objects with any behaviour in it.

计㈡愣 2024-09-13 06:47:39

冒着成为愤怒的手指摇晃的风险:我声称类似自然语言对于编程语言来说是一个糟糕的目标。具体来说,自然语言表达的目标是影响世界,让其他人想要亲吻你而不是打你;这与编程语言话语的目标非常不同,编程语言话语的目的是在计算机或其他人可以评估的明确定义的领域中提供明确的陈述。更好的问题可能是:哪种编程语言最不容易意外搬起石头砸自己的脚?

...当然,这根本不是你问的。

At the risk of being a raging finger-wagger: I claim that natural-language-like is a bad goal for programming languages. Specifically, the goal of a natural language utterance is to influence the world so that other human beings want to kiss you rather than punch you; this is very different from the goal of a programming language utterance, which is intended as an unambiguous statement in a well-defined domain that a computer or another person can evaluate. A better question might be: which programming language makes it most difficult to accidentally shoot yourself in the foot?

... which is not at all what you asked, of course.

2024-09-13 06:47:39

COBOL 一直被认为是非常“自然的语言”。以下是 99 瓶啤酒页面的摘录:

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

当然,“自然语言”并不总是(通常?)编程语言的优点,其中精确性是当今的秩序(自然语言几乎总是模棱两可的 - 添加编程语言所需的精确性只会使其变得冗长)。

COBOL was always considered pretty "natural language". Here's an extract from the 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

Of course, "natural language" is not always (often?) a virtue amoung programming languages, where preciseness is the order of the day (and natural language is almost always ambiguous - adding the preciseness required by a programming languages just makes it verbose).

北音执念 2024-09-13 06:47:39

莎士比亚编程语言怎么样?这是“hello world”源代码的一部分,来自 wikipedia

               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]

:就像代码突出显示在这里不起作用一样。 :/

How about the Shakesspeare programming language. Here's a part of the "hello world" source, out of wikipedia:

               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]

Seems like code highlighting doesn't work here. :/

转角预定愛 2024-09-13 06:47:39

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

VB.NET (though your AppleScript example beats VB.NET), SQL or COBOL (the source of this style). Lolcode is "language"-like but I'm glad English isn't like it.

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
情话已封尘 2024-09-13 06:47:39

在查看了所有答案后,我确信 AppleScript 实际上是最自然的语言。

After reviewing all the answers, I'm convinced that AppleScript actually is the most natural language like.

那一片橙海, 2024-09-13 06:47:39

您听说过超新星吗?它是一种自然的编程语言。即使您只需说“我想要窗口,窗口标题是你好”,也可以在 Supernova 中创建一个窗口。

Have you heard about Supernova. It's a natural programming language. Even you can create a window in Supernova by just saying I want window and the window title is hello.

待"谢繁草 2024-09-13 06:47:39

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

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

    RETURN "return value!"
END FUNCTION

I hate to plug my own stuff (well not really) but 7Basic has a pretty english-like syntax:

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

    RETURN "return value!"
END FUNCTION
慢慢从新开始 2024-09-13 06:47:39

我认为讨论 Dijkstra 式的编程精度在哪里是必要的,在哪里不需要,会很有趣。在需要细节的低级编程中,精度也很重要。由于编程原语的级别更高,也许没有那么多......

I think a discussion of where Dijkstra-like programmatic precision is necessary vs where it is not would be interesting. In lower level programming where detail is needed, so is precision. As programming primitives are higher level, perhaps not so much ...

空城仅有旧梦在 2024-09-13 06:47:39

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

一个有趣的例子是照应宏,Paul Graham 在他的《On Lisp》一书中对此进行了描述。照应宏是一个将某些表达式绑定到其体内的符号“it”的宏,因此我们可以轻松引用它:

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

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

还有许多其他照应宏的示例,例如绑定循环变量的 for 循环等。事实上,您甚至可以使用宏来为您生成照应宏。

Maybe Common Lisp? Macros in Lisp allow you to define abstractions as "new words". That's as close to pseudocode or English as you want to get (because when describing program in our thoughts or discussions, we use a lot of abstractions from the mechanics of particular language).

An interesting example are anaphoric macros, which Paul Graham describes in his book On Lisp. Anaphoric macro is a macro that binds some expression to the symbol "it" inside it's body, so we can easily refer to it:

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

In this line, the get-data is function which either returs some object or nil. If it returns the data, they are bind to "it" variable, which is the processed by "do-something" function. If the data returned are nil, the condition is not satisfied and the clause is not executed.

There are many other examples of anaphoric macros, like for loops, that bind the loop variable, and so on. In fact, you can even have macros that generate anaphoric macros for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文