Can also classical programming, the project won the 5500 Star in GitHub!

 

"Formerly, Cang Jie for the book, and the rain millet, ghost night crying," Chinese characters appear, the birth of a great world civilization. The emergence of programming languages, so that human and computer generated a real connection, and promote the development of modern civilization.

So, the combination of ancient Chinese and programming languages ​​will produce what kind of spark? Recently, there has been a classical code to do the project on GitHub, is the world's first door almost classical programming languages ​​(of course, the bottom or converted to run JavaScript or Python).

Classical programming language turned out

If Chinese is the main language used in programming languages, we Chinese people to learn whether the program would be more simple?

It is known very hot discussion topic on almost. Many people who come into contact with programming know "easy language", which is a use Chinese instead of English programming language programming language, the same can implement program functionality. Recently, a Carnegie Mellon University (CMU) senior programming language developed based on classical Chinese, three high school language afraid of classical finally found the programmer.

This project is not a simple program in English characters into the Chinese, but to use some of the techniques of NLP, to convert the classical program syntax to run JavaScript or Python, a certain degree of technical difficulty. As of posting, the project has won praise 5K +, also got a lot of people microblogging forward.

 

Many users have been tested for this project, the project of brain holes, literary talent and creativity really surprising.

If readers want to quickly try, you can also play with online IDE, there are many predefined functions above. Even on the phone, we can edit and run the "classical Code."

                                                                                       (End text has transferred address)

 

How classical programming?

 

Huang Lingdong students should read the "Book of Changes", after all, the I Ching is the first discussion of binary ancient books. He represents the Boolean variables 0 and 1, with the I Ching Yin and Yang.

"I have" series were used for the definition:

I have a number define int variables ;

吾有一爻是定义布尔变量

吾有一言是定义字符串

吾有一术是定义函数

吾有一列是定义数组

……

一般的编程里,循环判断有if、while、for,文言文编程在这件事上更是变化无穷。下面就是一段文言文书写的判断语句:

若三弗大於五者。乃得「「想當然耳」」。若非。乃得「「怪哉」」也。

翻译过来就是:


if(3<=5)
  {return "of course"}
else
  {return "no way"}

也许你会觉得if…else…语句用文言文太啰嗦,但是常用的for循环,用文言文表达却更为简洁。

為是百遍。⋯⋯ 云云。

它的意思是:


for (var i = 0; i < 100; i++)
  { ... }

如果需要判断某个变量human是否在world中,我们一般用for (var human of world),初学者看到for的这种用法可能会很困惑,而文言文的表示更接近普通人的理解。

凡「天地」中之「人」。⋯⋯ 云云。

古有《易经》,今有金庸小说,在展示定义函数的时候,Huang同学又皮了一下:

吾有一術。名之曰「六脈神劍」。欲行是術。必先得六數。曰「甲」。曰「乙」。曰「丙」。曰「丁」。曰「戊」。曰「己」乃行是術曰。⋯⋯是謂「六脈神劍」之術也。

这里Huang同学将函数名定义为“六脉神剑”,这个函数总共有6个输入。


funcion f(a,b,c,d,e,f)
  {…}

看厌了黑底的代码?项目还提供了一个炫酷的「古文代码生成器」,我们可以把自己的文言文代码转换成古书中从右到左,从上到下,没有标点的古文。是不是更有 B 格了?这个生成器还有 SVG 文件,可以将代码再提取出来,重新运行。

以下为项目作者尝试的「图灵机」代码:

 

语法规则

考虑到文言文和其他编程语言的转换有一定的理解难度,作者提供了一些语法转换规则表,供参考。

变量命名

条件/循环

 

数学计算

 

数组(列表)

这里从「1」开始计数。

 

函数

 

他是“何方神圣”?

值得注意的是,这个思路清奇的设计竟然出自一名卡内基梅隆大学的大四学生 Ling Dong Huang。

 

在作者简介中,Ling Dong Huang 表示自己将于 2020 年获得计算机科学学位,此前,他曾在迪士尼研究院、 Antimodular 研究院和《纽约时报》实习,自己也做了项目网站 https://lingdong.works/。目前已经有将近 30 个项目。项目主题丰富多彩,比如用 emoji 做成的小游戏,使用用户提交的涂鸦做成的计算机动画,以及和本文一样对中国下手,把中国表意文字和部首做成可视化动画,等等,并给出了项目的源代码。

他还做了一些很有趣的东西,比比如微信终端版,格律诗编辑程序,真实一个传统文学的爱好者啊!

如果大家想试玩下,可以直接克隆作者的项目,然后按照语法去调试一下即可,macOS、Wondows、Linux的二进制文件将位于./build文件夹中。


Usage: wenyan [options] [input files]

Options:
--eval    -e <string>  : Give a string instead of a file (default: `')
--exec    -x <boolean> : Execute output (default: `false')
--inspect -i <boolean> : Interactive REPL (default: `false')
--lang    -l <string>  : Language: js/py (default: `js')
--log        <string>  : Log file (default: `/dev/null')
--output  -o <string>  : Output file (default: `/dev/stdout')
--roman   -r <boolean> : Romanize identifiers (default: `true')
./build/wenyan.js examples/helloworld.wy -o helloworld.js

作者还有一些其它好玩的项目,例如可以用程序无限生成的中国山水画,错山记(中文翻译哈),格律诗编辑程序,隐士等等,GitHub上都能找到,大家不妨去看一下

  • GitHub链接:https://github.com/LingDong-/wenyan-lang

传送门:

项目代码:

https://github.com/LingDong-/wenyan-lang

项目主页:

http://wenyan-lang.lingdong.works/

线上IDE试玩:

http://wenyan-lang.lingdong.works/ide.html

个人主页:

https://lingdong.works/

赶紧去看看小哥的神创造!

安装与使用

文言文编程只需将repo下载到本地,而且本地已经安装Node,就能立即使用。现在它支持将wenyan lang转换成JavaScript和Python:


./build/wenyan.js examples/helloworld.wy -o helloworld.js

在这段命令中,如果不指定语言,程序将自动转化为JavaScript,若想转化成Python,请加入参数“—lang py”或是“-l py”。

用户也可以自行编译二进制文件。如果你只想尝尝鲜,在线IDE也是个不错的选择。

小编先去玩了!

                                                                                           程序员生活志

                                                                    关注我,不错过任何一件程序员新鲜事儿!

发布了38 篇原创文章 · 获赞 742 · 访问量 3万+

Guess you like

Origin blog.csdn.net/cxyshenghuozhi/article/details/103627436