Code Monkey home page Code Monkey logo

book's Introduction

文言 wenyan-lang

npm build Netlify Status

English | 简体中文 | 繁體中文

文言文編程語言。A programming language for the ancient Chinese. Try it online.

CHANGELOG

之世,結繩而足治,屈指而足算。是時豈料百代之後,計算機械之巧,精於公輸木鳶,善於武侯流馬;程式語言之多,繁若《天官》之星宿,奇勝《山經》之走獸。,或以速稱。,各爭文采。方知鬼之所以夜哭,天之所以雨粟。然以文言編程者 ,似所未有。此誠非文脈之所以傳,文心之所以保。嗟予小子,遂有斯志。然則數寸之烏絲猶覆於頭,萬卷之素書未破於手;一身長羈於遠邦,兩耳久曠于雅言。然夫文章者吾之所宿好,程式者偶承時人之謬譽。故希孟不慚年少,莊生不望無涯。乃作斯言。誠未能嘔瀝長吉心血,亦庶幾免於義山流沫。既成之後,復學干將鑄劍而自飼,越王嚐糞而當先。自謂偶追《十書》之筆意,但恨少八家之淋漓。此子山所謂士衡撫掌而甘心,平子見陋而固宜。然則雖實覆甕之質,尚存斧正之望;雖乏呂相之金,易字之渴蓋同。此亦開源之大義,吾輩之所以勉勵也。一笑。

Helloworld

Wenyan:

吾有一數。曰三。名之曰「甲」。
為是「甲」遍。
	吾有一言。曰「「問天地好在。」」。書之。
云云。

Equivalent JavaScript:

var n = 3;
for (var i = 0; i < n; i++) {
	console.log("問天地好在。");
}

Output:

問天地好在。
問天地好在。
問天地好在。

Punctuations and newlines are completely optional (just like they are in Classical Chinese), so the above code is equivalent to:

吾有一數曰三名之曰「甲」為是「甲」遍吾有一言曰「「問天地好在」」書之云云

More sophisticated examples, such as the Sieve of Eratosthenes, Quicksort, Mandelbrot set, and Tower of Hanoi, can be found in the ./examples folder.

Features

Try it out

Text Editor Plugins

Command Line Compiler

Install the compiler by

npm install -g @wenyan/cli

Try run the included examples, e.g.:

wenyan examples/helloworld.wy
# will output: 問天地好在。

You can now translate JavaScript to wenyan-lang using the wenyanizer by zxch3n.

3rd Party Compilers

Documentation

Check out our Wiki pages

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

book's People

Contributors

dbvc avatar glanguage avatar lingdong- avatar nfls-1963 avatar puzzlet avatar sozysozbot avatar splitline avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

book's Issues

08 方術第八中若干问题反馈

其一:函數定義中的傳参命名,『名之曰』則不可編譯通過,『曰』可正常編譯。
如:
吾有一術。名之曰「論戰」。欲行是術。必先得一言。名之曰「恃」。乃行是術曰。則編譯出錯。
吾有一術。名之曰「論戰」。欲行是術。必先得一言。曰「恃」。乃行是術曰。則正常運行。

其二:循環體與判斷語句重疊時,易產生多收尾或少收尾現象。

如:

恆為是。
若「藏」之長大於「層」者。乃止也。
吾有一列。充「藏」以其也。
注曰。『其它正常循環體中邏輯語句』
云云。

編譯正常,但邏輯異常。

恆為是。
若「藏」之長大於「層」者。乃止也。
吾有一列。充「藏」以其矣。
注曰。『其它正常循環體中邏輯語句』
云云。

則一切正常。
特別是循環體中包含『若非……也』、『若非……云云』的語句,更容易出錯(漏寫或多寫也/云云)。

其三:『篩剔』例中調用例子函數名誤寫爲『濾』。

第十一至第十三用字疑義

夫上蔡臨市而嘆黃。杜陵望雲而感蒼。括母劾子竟免於族。俶父效之猶見於誅。宣子以立瑤亡智。輔果改氏而逭之。北海以譏曹取死。二子琢釘而待之。天道幽遠以降禍。或速或遲。世人處之乃顯志。有得有失。又麋子仲婦人之私。火燒其室。諸葛恪腥狗之讖。兵加其身。眾君子謀社宮以亡曹。諸小人戲池陽而覆莽。永嘉狗語而天下飢。太安牛言而天下亂。吾人既不得其徵。唯綢繆於未雨。徙薪於未焚。補羊牢於未亡。避南牆於未撞。故韓非子曰。夫事之祸福亦有腠理之地。圣人蚤從事焉。

  • 上蔡云云臆當李斯其事矣,而杜陵云云未能明其所指。是必吾寡識也,懇請垂示。
  • 夫事之祸福亦有腠理之地。圣人蚤從事焉。 似簡字誤入也。

子曰。游於藝。昔庖犧作卦。史皇作圖。乃有鳥鼎鸞旂。琱戈黼黻。輿圖絺繡。九州十服。屈子謁廟厥有天問。荀卿屬文以為養目。雲臺畫壁以旌功臣。洛陽鑿磚以紀射馳。毛寫昭君。至於棄市。顧描鄰女。竟得悅之。弗興畫龍。百年祝雨。僧繇點睛。一時飛去。曹為梵象。其衣出水。吳寫神仙。其帶當風。李將軍富貴入畫。雍容金碧。王右丞以畫為詩。幽雅超逸。凌煙功臣。太宗得諸立本。御園駿馬。子美觀諸曹霸。韓幹馬。韩滉牛。宣和鶴。元吉猴。徐熙野筆。黃荃精勾。荊關山峻。米家雲悠。雲林蕭索。松雪俊秀。老蓮高古。桃庵風流。理論董九友。工細仇十洲。有清以降。丹青傳世者不計其數。吾曹先人之苗裔兮。宜乎哉其畫脈之繼武。

  • 韓幹馬。韩滉牛。亦似簡字也。

昔秦王既掃六合。入海求藥為鯨所阻。乃連弩射殺之。漢武亦好神仙之術。而徒誅文成樂通。卒無所獲。後世煉丹餌朮之徒。未嘗絕於世。彼金丹大道者。有內丹。有外丹。內丹者。吐氣納神也。外丹者。燒鼎煉金也。其術多玄奧莫解。周易叄同契。抱朴子載焉。今信之者鮮矣。然近有奇術。投諸機器。可以告往知來。聞一識十。人不之預而智每敵於人者。號曰深度學習。然趨之者若鶩。窮其理者寥寥。比其煉也。每每耗時經日。乃至於月。比其成也。或神機如響。或闇昧無覩。得其方者著之。洋洋然誇諸天下。失之者易之。營營然冀有所得。吾儕每戲言。此誠當代之煉金術也。

  • 此段多用「煉」字,而皆非體於頁面也。直為「燻」字也。
    image

夫編程之奧義也無涯。而一山之竹也有涯。況以學術之盛代。世術日新。法門月異。每有昨之驪珠。今之敝屣。然其為礎礩者。十世弗易。萬變靡離。是書所錄者是矣。其餘不能盡美者。唯待博雅君子。既詳覽其書而熟習其術。靡不能觸類而長之。則雖幽遐詭伏。無所不入。告其往而知其來。舉一隅而反其三。聞一而知十者皆適。然後乃置之尋常而不塞。布之天下而不窕也。

  • 字於頁面猶如「蹝」字。兩字義同而形殊,不知奈何。
    image

关于pr #29

不知道怎么在 book.wy-lang.org 上改。知道的大佬请帮忙再交个pr。

求字体

请问仿古的封面是怎么制作的呀?太精美了!
还有,请问文言阴符四个字的字体是什么字体呀?

第七第八用字疑義

維天地生人之初。茹毛飲血而衣皮葦。所以異於禽獸者幾稀。而自三代以降。其去禽獸之日遠。其文明之愈盛。何邪。得無言語之益乎。夫嗚嗚然。啾啾然。狺狺然。奔走而吿其黨者。此禽獸之言語也。然上治萬乘之國。牧天下之民。下鑄析革之兵。造罟耨之具。皆非其嗚嗚然。啾啾然。狺狺然可以傳也。不能傳者。父偶得之。子偶失之。子偶知之。孫偶忘之。是故智巧之萌。自言語始。倉頡造字。天雨粟。鬼夜哭。所泣者何。洩天地之機也。先賢言語既見於書。後人欲有所建。豈必起於平地。但添一瓦於鴻基。而郁郁乎廣廈日成矣。西哲牛頓曰。或有異吾之遠見者。無他。但立巨人肩耳。是理也。故易繫辭曰。上古結繩而治。後世聖人易之以書契。百官以治。萬民以察。

竊未嘗聞析革一詞,檢之於經典中不得,纔見「金革」義稍近。子其知是詞何謂乎?

回文者。順逆讀之皆成韻文者也。漢有鏡銘。蘇蕙有璇璣圖。晉以降作者甚眾。而東坡尤工之。今作是程序。因其順而得其逆。因其逆而得其順。以示諸法之用。

程序一詞初見焉,以後或與程式混用。此二者便有何異同?

抱朴。參同。萬畢。古之方術書也。周髀。九章。海島。古之算術書也。孫吳。三略。六韜。古之兵術書也。術者竟何。成法也。夫人之初任一事。有成有敗。或得或失。卒不知孰為可法。君子仰觀前人之殷鑒。俯羅不易之步驟。法象萬物。為法為道。名之曰術。後人循之遵之。成事因之。故韓非子曰。人主之所执也。

文本首句為抱朴,成書乃作「樸」。尾句曰所执也,亦形「執」。皆似字模訛舛也。而按前者原文「朴」通「樸」,猶可也。後者「执」唯今世之簡字,當改耳。

image image

又凡循環皆可作遞歸解。遞歸皆可作循環解。但擇其易敘者而為之也。譬客有問行百步之法者。一曰。百遍為之而行一步。是行百步也。此循環也。一曰。先行一步。復行其餘九十九也。若問何以行其九十九耶。則先行一步。復行其九十八步也。此遞歸也。例曰。莊子云。一尺之錘。日取其半。萬世不竭。今既十日。問其錘長。

一尺之錘,按應作「棰」字,今本『莊子』如此。棰,木杖也。錘,金棒也。斷錘為半,不知其難何如。後復有一處並同。

吾學甚淺,不免有蜀犬吠日之非,請君恕諒。

第九代碼疑義

book/09 府庫第九.md

Lines 73 to 78 in a56c27e

吾有一術。名之曰「比」。欲行是術。必先得二數。名之曰「甲」。曰「乙」。乃行是術曰。
若「甲」小於「乙」者。乃得負一也。
若「甲」大於「乙」者。乃得一也。
乃得零。
注曰「「或云「減甲以乙乃得矣」亦可」」
是謂「合」之術也。

此術已名「比」於跋,猶當結以是謂「比」之術也。

明义第一里面最后压缩过的程序不对

吾有一數曰三名之曰「甲」為是「甲」遍吾有一言曰「「問天地好在」」書之云云

虽然说句号可以省略,但是string literal里面的句号不能随便省吧,双引号里面应该还要有个句号

The code following 易首句 does not change the 首句

As mentioned in #15 (comment) (which I definitely should have made a separate issue), clicking the code snippet after 但易首句可矣。 in the https://book.wy-lang.org/ opens up an online editor window with the following source code:

吾有二數。曰五百七十九。曰二千二百八十三。名之曰「頭」曰「足」。
吾有二數。曰三十五。曰九十四。名之曰「頭」曰「足」。
除「足」以二。減其以「頭」。名之曰「兔」。
減「頭」以「兔」。名之曰「雉」。
夫「雉」夫「兔」。書之。

which uses the old number of 頭 and 足.

The exact same problem exists in 循環第五: following 試易首句如是,

有數九百九十九。名之曰「始」。
有數九。名之曰「始」。
有數「始」。名之曰「戊」
為是「始」遍。
 有數「戊」。名之曰「戌」。
 為是「戊」遍。
  乘「戊」以「戌」。名之曰「甲」。
   若「甲」小於十者。
    吾有四言。曰「戌」曰「戊」曰「「如」」曰「甲」。書之。
   若非
    吾有三言。曰「戌」曰「戊」曰「甲」。書之也。
   減「戌」以一。昔之「戌」者。今其是矣。
 云云。
 減「戊」以一。昔之「戊」者。今其是矣。
云云。

uses the old number of 「始」.

Mistakes in「算術第三」and「行列第六」

There seem to be some mistakes in「算術第三」and「行列第六」:

「大數之類。一。十。十一曰百。十百曰千。」

「十一曰百」should be「十十曰百」

「萬萬曰億。萬億曰兆。萬京曰陔。」

Missing「萬兆曰京。」

戴九履一。左三右七。二四為肩。六八為足。

Missing 「五居**。」(maybe)

Missing "吾有一言" in 決策第四

这里:

又有若其然者若其不然者。以資爻策。故是二句同。

夫「甲」「乙」中無陰乎。名之曰「丙」。若「丙」者。曰「「古之人誠不我欺。」」書之也。
夫「甲」「乙」中無陰乎。若其然者。曰「「古之人誠不我欺。」」書之也。

是二句亦同。

夫「甲」「乙」中有陽乎。名之曰「丙」。變「丙」。名之曰「丁」。若「丁」者。曰「「古之人誠不我欺。」」書之也。
夫「甲」「乙」中有陽乎。若其不然者。曰「「古之人誠不我欺。」」書之也。

曰「「古之人誠不我欺。」」書之 可改为 夫「「古之人誠不我欺。」」書之

Array-copying algorithm fails

The code given in the book,

吾有一列。名之曰「甲」。充「甲」以三。充「甲」以五。

吾有一列。名之曰「乙」。
凡「甲」中之「元」。充「乙」以其也。

compiles to

var 甲 = [];
甲.push(3);
甲.push(5);
var 乙 = [];
for (let 元 of 甲) {
  乙.push();
};

in both the online IDE and wenyan -c.

Contrary to what is claimed in the book (欲令其實亦二。互不相干。當如何。曰。當如是), this code does not make a copy of an array, since no element is pushed to 「乙」. Though

吾有一列。名之曰「甲」。充「甲」以三。充「甲」以五。

吾有一列。名之曰「乙」。
凡「甲」中之「元」。充「乙」以「元」也。

would fix the problem, it might be that the failure of 其 to point to 「元」 is a regression introduced somewhere within the long history of wenyan-lang.

Wow!

This definitely desires to open an issue to say Wow! You are so talented on this!

I already love your prologue so much and now this comes up!

It's a shame that I can help little about the content itself. But I think I can help with the building system. Wuepress may not be very suitable for this and can be overkill. I think we can build our own tools for this. Anyway, that's something to be taken up later. :)

Awesome job! I will try to read them more thoroughly then. 👍

A brilliant idea

Can I ask how you generated the "authentic relic" edition? Just interested for my own purposes haha.

Typo?

格物一篇中有言『欲行是術。必先得言』於九十頁。似為筆誤。望改之。

Typo in 算術第三?

又除法者。有除數與被除數之別。是謂除法無交換也。
又除法者。有除數與被除數之別。是謂除法無交換也。

二千二百八十三 → 二千二百八十四 in 算術第三

吾有二數。曰五百七十九。曰二千二百八十三。名之曰「頭」曰「足」。
除「足」以二。減其以「頭」。名之曰「兔」。
減「頭」以「兔」。名之曰「雉」。
夫「雉」夫「兔」。書之。

gives

一十六又五分 五百六十二又五分

Also, clicking the code snipped after 曰。但易首句可矣。 in the https://book.wy-lang.org/ opens up

吾有二數。曰五百七十九。曰二千二百八十三。名之曰「頭」曰「足」。
吾有二數。曰三十五。曰九十四。名之曰「頭」曰「足」。
除「足」以二。減其以「頭」。名之曰「兔」。
減「頭」以「兔」。名之曰「雉」。
夫「雉」夫「兔」。書之。

which uses the old number of 頭 and 足.

圖畫第十二 程序错误

「青圖」程序

吾有一術。曰二百。名之曰「廣」。注曰「「紙之長寬也」」。

应该是

吾有一數。曰二百。名之曰「廣」。注曰「「紙之長寬也」」。

A wrong character in Calculation The Third

I think the character "率" in the word "除法無交換率" from Calculation The Third (算術第三) should be replaced with "律." In Chinese, "率" usually means "rate" while "律" means "law."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.