kli*_*eta 56 nlp programming-languages
我从很多情况下得到了这个问题的想法,我不明白这个人在说什么,什么时候别人不理解我.
因此,"智能"解决方案是说一种计算机语言.:)
我感兴趣的是编程语言可以接近(英语)自然语言.当我说近,我的意思不仅仅是使用单词和句子,而是能够"做"自然语言可以"做"的事情和"做",我的意思是它可以被使用(以非常有限的方式)作为自然语言的替代品.
我知道这是不可能的(是吗?)但我认为这可能很有趣.
Bes*_*ska 117
有所谓的通知,在其最近的化身,通知7编程语言,看起来很多像自然语言...特别是书面语言.
Inform非常专门用于创建文本冒险游戏,但没有固有的理由说这些概念无法扩展到其他领域.
这是一小段Inform 7代码,取自Emily Short的游戏Glass.
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." 
Run Code Online (Sandbox Code Playgroud)
完整的代码可以在这里找到.
这是一个简单的小例子......它实际上可以处理一组令人惊讶的强大想法.
应该指出的是,代码实际上并不是一个奇怪的密码,其中构造具有隐藏的意义......这段代码或多或少地与你期望的一样.例如:
The old lady is a woman in the Stage. Understand "mother" or 
"stepmother" as the old lady. 
Run Code Online (Sandbox Code Playgroud)
创建一个恰好是女性的对象,将对象命名为"老太太",并将该对象放置在称为"舞台"的房间对象中.然后创建了两个别名("母亲"和"继母",它们也都引用了"老太太"对象.
当然,随着示例变得越来越复杂,跳过的必要环节也变得更加复杂.就其本质而言,英语是模棱两可的,而计算机代码最明确的不是.所以我们永远不会得到"完美的婚姻".
Ale*_*ort 43
取决于你滚动的圈子,但LOLCODE可以被认为是自然语言;)
示例循环:
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
Run Code Online (Sandbox Code Playgroud)
严肃地说,VB是一种非常自然的语言.非程序员类型很容易学习,因此语法必须非常容易理解.
Gal*_*ian 32
理查德·普赖尔(Richard Pryor)在超人III中用来转移数百万美元的语言非常接近:
> TRANSFER $1,000,000 DOLLARS TO WEBSTER'S ACCOUNT.... NOW
Run Code Online (Sandbox Code Playgroud)
;-)
编辑:字符更正;-)
Jos*_*ein 20
COBOL读起来很像英语
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.
Run Code Online (Sandbox Code Playgroud)
        Ant*_*ert 14
HyperTalk - Apple的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
Run Code Online (Sandbox Code Playgroud)
        我不知道我会说VB.NET接近英语,但我认为它与你真正的接近.当然,一旦你设定了一段时间,好像英语-它确实读起来就像一本书,一个经验丰富的VB程序员,但如果你停下来思考现实世界的英语:
For i As Integer = 1 To 10
  Console.WriteLine("Hello World")
Next
Run Code Online (Sandbox Code Playgroud)
离我们还有很长的路要走
写下"Hello World"并移动到控制台的下一行10次.
当然,英语是模棱两可的 - 它是否要你做整整10次,或者只写一次"Hello World",然后移动到下一行10次?
我想我们需要学会以不那么模糊的方式交谈:
这样做10次:在控制台中,写下"Hello World"并移动到下一行.
但我非常怀疑是否有一种真正像英语一样的编程语言.即使是那些说它就像自然语言的Cobol狂热分子 - 如果你停下来想想你如何以真实的方式思考事物而不是以编程语言定义的方式思考,那就不是了.
即使在VB中,你也只限于框架决定你做事的方式......
那么,简单的英语,当然!
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.
Run Code Online (Sandbox Code Playgroud)
我实际上没有用过这个 - 我在这里找到了它.
gherkin是一种特定于域的语言,用于描述可执行的 bdd -specifications.它由黄瓜(红宝石)和 specflow(dotnet)使用.
例
    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  |
Run Code Online (Sandbox Code Playgroud)
        小智 6
Perl有一些基于人类如何处理自然语言的设计原则(参见http://www.wall.org/~larry/natural.html).
与语法黑客不同的是,使用英语或其他语言将代码读成句子.我并不完全相信这些是有用的.作为类比,我也可以使用我的代码制作ASCII艺术,但这并不意味着我的语言基于视觉构图的原则.
举一个它可能没用的地方的例子,假设这看起来像是用一些rubyish/smalltalky语言做的:
3.times say "hello!" 
Run Code Online (Sandbox Code Playgroud)
这很好,它使我的代码更具可读性,并且有一种类似的乐趣就是让一只可以说话的鹦鹉,但它只有在我了解计算机语言的基本规则时才有用.碰巧看起来像英语的事实让我没有额外的杠杆或洞察力.我无法在脑中使用英语语法处理引擎来生成如下句子:
// 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
Run Code Online (Sandbox Code Playgroud)
        嗯,Ruby和Python应该相当接近.Ruby甚至可以添加模拟现实生活的特殊关键字.比如除非关键字等
当然,你用这两种语言中的任何一种键入真实代码,它不是真的像自然语言,但那又是什么?
我会说SQL或COBOL.