有没有一种语义接近英语的编程语言?

发布于 2024-10-09 15:12:50 字数 1720 浏览 0 评论 0原文

大多数语言允许“调整”语法的某些扩展部分(C++C#) 和/或您将在其中使用的语义您的代码(Katahdinlua)。但我还没有听说过一种语言可以完全定义代码的外观。那么,是否已经存在某种语言具有覆盖所有语法和语法的功能?定义语义 ?

我想要做的示例基本上来自下面的 C# 代码:

foreach(Fruit fruit in Fruits)
{
  if(fruit is Apple)
  {
    fruit.Price =  fruit.Price/2;
  }
}

我希望能够用我的完美语言编写上述代码,如下所示:

Check if any fruits are Macintosh apples and discount the price by 50%.

从编码员的角度来看这个“想象”的优点语言是:

  1. 发生的事情非常清楚(自我描述) - 毕竟它是简单的英语,即使孩子也会理解我的程序
  2. 隐藏我必须用 C# 编写的所有复杂性。但我为什么要关心学习这个 if 语句、算术运算符等,因为已经实现了。

我认为维护此程序的编码员的缺点是:

  1. 也许您会以与我不同的方式表达此程序,因此您可能无法获得所有 我在句子中表达的信息
  2. 程序可能非常冗长且难以调试,但如果可能的话,甚至接近上面这种类型的语法,也许更多的人会开始编程,对吧?我想那真是太棒了。我可以去上班,然后写一篇文章在 winform 上画一个正方形,如下所示:

创建一个名为 MyGreetingForm 的表单。画一个正方形,中间有 MyGreetingForm 的一边为 100 分。在方块中间用 Arial 字体写“Hello!单击此处继续”。

在上面的代码中,解析器基本上必须猜测我想使用 前一句中的未命名方块,我想编写这样一个智能解析器会很困难,但我想做的事情却很简单。

如果用户单击 MyGreetingForm 中间的方块,则显示 MyMainForm。

在上面的代码中,“基本上”编译器必须:1)生成一个事件处理程序 2)检查中间是否有任何方块表单,如果有 - 3)隐藏表单并显示另一个表单

这看起来很难做到,但在我看来并非不可能,至少近似于此(我个人可以生成一个解析器来执行 np 以上的 3 个步骤& 即使在 c# a.MyEvent=+handler; 中添加,它也必须以任何方式执行,所以我在这里没有看到问题)所以我想也许有人已经做了这样的事情?或者创建这样一种我看不到的“论文风格”编程语言是否存在一些实际的复杂性负担?我的意思是,如果解析器不是那么好,会发生什么更糟糕的情况? - 你的程序会崩溃,所以你必须重新措辞:)

Most languages allow to 'tweek' to certain extend parts of the syntax (C++,C#) and/or semantics that you will be using in your code (Katahdin, lua). But I have not heard of a language that can just completely define how your code will look like. So isn't there some language which already exists that has such capabilities to override all syntax & define semantics ?

Example of what I want to do is basically from the C# code below:

foreach(Fruit fruit in Fruits)
{
  if(fruit is Apple)
  {
    fruit.Price =  fruit.Price/2;
  }
}

I want do be able to to write the above code in my perfect language like this:

Check if any fruits are Macintosh apples and discount the price by 50%.

The advantages that come to my mind looking from a coder's perspective in this "imaginary" language are:

  1. It's very clear what is going on (self descriptive) - it's plain English after all even kid would understand my program
  2. Hides all complexities which I have to write in C#. But why should I care to learn that
    if statements, arithmetic operators etc since there are already implemented

The disadvantages that I see for a coder who will maintain this program are:

  1. Maybe you would express this program differently from me so you may not get all the
    information that I've expressed in my sentence
  2. Programs can be quite verbose and hard to debug but if possible to even proximate this type of syntax above maybe more people would start programming right? That would be amazing I think. I can go to work and just write an essay to draw a square on a winform like this:

Create a form called MyGreetingForm. Draw a square with in the middle of
MyGreetingFormwith a side of 100 points. In the middle of the square write "Hello! Click here to continue" in Arial font.

In the above code the parser must basically guess that I want to use
the unnamed square from the previous sentence, it'd be hard to write such a smart parser I guess, yet it's so simple what I want to do.

If the user clicks on square in the middle of MyGreetingForm show MyMainForm.

In the above code 'basically' the compiler must: 1)generate an event handler 2) check if there is any square in the middle of the form and if there is - 3) hide the form and show another form

It looks very hard to do but it doesn't look impossible IMO to me at least approximate this (I can personally generate a parser to perform the 3 steps above np & it's basically the same that it has to do any way when you add even in c# a.MyEvent=+handler; so I don't see a problem here) so I'm thinking maybe somebody already did something like this ? Or is there some practical burden of complexity to create such a 'essay style' programming language which I can't see ? I mean what's the worse that can happen if the parser is not that good? - your program will crash so you have to re-word it:)

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

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

发布评论

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

评论(6

轮廓§ 2024-10-16 15:12:50

查看:

渗透秩序
简单英语程序员

代码示例:

The background is a picture.

A button has a box and a name.

To clear the status:
  Clear the status' string.
  Show everything.

To create the background:
  Draw the screen's box with the white color.
  Loop.
  Pick a spot anywhere in the screen's box.
  Pick a color between the lightest gray color and the white color.
  Dab the color on the spot.
  If a counter is past 80000, break.
  If the counter is evenly divisible by 1000, refresh the screen.
  Repeat.
  Extract the background given the screen's box. \or Create the background from the screen. Or something.

Check out:

The Osmosian Order
of Plain English Programmers

Code Example:

The background is a picture.

A button has a box and a name.

To clear the status:
  Clear the status' string.
  Show everything.

To create the background:
  Draw the screen's box with the white color.
  Loop.
  Pick a spot anywhere in the screen's box.
  Pick a color between the lightest gray color and the white color.
  Dab the color on the spot.
  If a counter is past 80000, break.
  If the counter is evenly divisible by 1000, refresh the screen.
  Repeat.
  Extract the background given the screen's box. \or Create the background from the screen. Or something.
提赋 2024-10-16 15:12:50

一些互动小说设计师使用与英语极其接近的语言语法。这里有一些 Inform 7 代码,您可以在线玩

The foyer is a room.

The apple is in the foyer. It is edible. The description is "This is a ripe, 
green granny smith apple."

The apple core is a thing. The description is "This apple core all that is 
left of that granny smith apple you just consumed."

After eating the apple:  
  now the apple core is in the player;
  say "You gobble down the apple careful not to eat any of those cyanide-
  laced seeds you heard about."

我辅导了一门使用 Inform 7 的课程。其中一位导师的印象是作业是设计,而不是编写游戏。因此,他通过阅读来标记程序,但没有意识到它们是实际的程序。

Some Interactive fiction designers use a language syntax extremely close to the English language. Here's some Inform 7 code, which you can play online:

The foyer is a room.

The apple is in the foyer. It is edible. The description is "This is a ripe, 
green granny smith apple."

The apple core is a thing. The description is "This apple core all that is 
left of that granny smith apple you just consumed."

After eating the apple:  
  now the apple core is in the player;
  say "You gobble down the apple careful not to eat any of those cyanide-
  laced seeds you heard about."

I tutored a course that used Inform 7. One of the tutors had the impression the assignment was to design, not write a game. So he marked the programs by reading them, without realising they were actual programs.

鼻尖触碰 2024-10-16 15:12:50

我不认为这将是一项容易的任务,也不认为它会让调试变得更容易。

您将如何处理这些问题?

  • 拼写错误
  • 世界不同地区的不同方言 世界
  • 同一地区的不同方言
  • 同义词
  • 您首先解析句子的哪一部分?
  • 眼泪(撕裂)和眼泪(从眼睛)这两个词的拼写相同,但含义不同。

带回COBOL或者你还记得“向西走”、“检查门”、“推门”吗、“开门”、“用钥匙开门”:)

编辑 - 您将如何强式输入此内容?

I don't think that this would be an easy task nor do I think it is going to make life easier for debugging

How would you deal with these issues?

  • spelling mistakes
  • different dialects in different parts of world
  • different dialects in the same part of the world
  • synonyms
  • which part of sentence do you parse first?
  • tear (rip) and tear (from eye) both words spellings are the same but mean two different things.

Bring back COBOL or can you remember "Walk West", "Examine Door", "Push Door", "Open Door", "Use key on door" :)

edit - how would you strongly type this?

守护在此方 2024-10-16 15:12:50

我编写了一个可扩展的英语到 Python 编译器,名为 EngScript,它将结构化英语转换为工作的 Python 代码。

这是 EngScript 代码的示例:

print{create a string from the file called "README.txt"}
print{save the string "Woohoo!" to a file called "ExampleText.txt"}
print{the first 3 letters of "EngScript"}

这是 EngScript 编译器生成的输出:

print(pythonFunctions.stringFromTextFile("README.txt"))
print(pythonFunctions.writeStringToFile("ExampleText.txt", "Woohoo!"))
print("EngScript"[0:(3 - 1)+1])

I have written an extensible English-to-Python compiler called EngScript, which converts structured English into working Python code.

This is an example of EngScript code:

print{create a string from the file called "README.txt"}
print{save the string "Woohoo!" to a file called "ExampleText.txt"}
print{the first 3 letters of "EngScript"}

This is the output that was generated by the EngScript compiler:

print(pythonFunctions.stringFromTextFile("README.txt"))
print(pythonFunctions.writeStringToFile("ExampleText.txt", "Woohoo!"))
print("EngScript"[0:(3 - 1)+1])
孤芳又自赏 2024-10-16 15:12:50

实时代码!
有一些“自然语言”、高级、类似英语的编程或脚本语言。可能所有这些都受到了最古老的 COBOL 的启发。我个人最喜欢这些语言是 LiveCode。 LiveCode 是 MetaCard 的后代,MetaCard 是 Apple 现已不复存在的 HyperCard 的 Linux 克隆版本,它使用一种名为 HyperTalk 的类似英语的脚本语言,该语言受到 SmallTalk 的启发,进而启发了 JavaScript(以及整个万维网)。 HyperTalk 是另一种类似英语的脚本语言 AppleScript(以及后来的 AppleScriptObjC)的基础,该语言至今仍随 macOS 一起提供。 LiveCode 使用一种称为 LiveCodeScript 或 LCS 的语言,与已存在多年的其他 HyperCard 克隆(SuperCard、Adobe 的 Lingo/Flash ActionScript、Open Xion、Oracle 的 Toolbook 等)一样,它的核心与 HyperTalk 非常相似,通常称为 X-Talk 语言。 LiveCode 有几个优点;它仍然在生产中,它有双重许可证(开源和商业版本),引擎是跨平台的(Mac、Win、Linux、HTML5、iOS、Android 和服务器版本),并且像 HyperCard 一样也是一个 GUI 工具包,并且它是可扩展的。 LiveCode 团队目前正在开发一种新的低级编程语言,称为 LiveCode Builder(LCB)。 LCB 也是类似英语的,虽然 LCB 的可读性比 LCS 差一些,但它的目标是具有与 C++、Objective C 等较低级语言相同的功能,允许使用代码库扩展 LiveCode 平台以及其他编程语言库生成的框架,并最终允许 LiveCode IDE 用它自己的语言编写。

LiveCode!
There are a few "natural language", high-level, English-like programming or scripting languages. Probably all of them were inspired by the oldest, COBOL. My personal favorite of these languages is LiveCode. LiveCode is a decendent of MetaCard, a Linux clone of Apple’s now defunct HyperCard that used an English-like scripting language called HyperTalk, which was inspired by SmallTalk, and in turn inspired JavaScript (as well as the entire World-Wide-Web). HyperTalk was the basis for another English-Like scripting language called AppleScript (and later AppleScriptObjC), which still comes with macOS to this very day. LiveCode uses a language called LiveCodeScript, or LCS which, like other HyperCard clones and that have existed over the years (SuperCard, Adobe’s Lingo/Flash ActionScript, Open Xion, Oracle’s Toolbook, etc.), is very similar to HyperTalk at it’s core, often referred to as an X-Talk language. LiveCode has several advantages; it’s very much still in production, it has a dual license (open source and commercial versions), the engine is cross-platform (Mac, Win, Linux, HTML5, iOS, Android, and a server version), and like HyperCard it is also a GUI toolkit and it is extensible. The LiveCode team is currently working on new a lower-level programming language called LiveCode Builder, or LCB. LCB is also an English-like, although LCB is a bit less readable than LCS, it has a goals of having capabilities on par with lower-level languages like C++, Objective C, etc., allowing for extending the LiveCode platform with code libraries and frameworks produced by other programming language libraries, and ultimately allowing for the LiveCode IDE to be written in it’s own language.

醉生梦死 2024-10-16 15:12:50

尝试使用名为“Google”的编程语言 - 它具有自然的英语界面,并且您的代码片段会返回您建议的所有答案。有趣的是,在您提出这个问题六分钟后,这个页面就成为该查询的#1:

检查是否有任何水果是 Macintosh
苹果并折扣50%

使用 Google API,我认为您已经具备了自然英语编程语言的基础。

Try using the programming language called 'Google' - it has a natural English interface and your code fragment throws back all the answers you are suggesting. Interestingly just six minutes after you asked this question, this very page is #1 for the query:

Check if any fruits are Macintosh
apples and discount the price by 50%

Use the Google API and I think you have the basis of a natural English programming language.

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