wenyan-lang / wenyan

文言文編程語言 A programming language for the ancient Chinese.
https://wy-lang.org/
MIT License
19.76k stars 1.1k forks source link

Alan J. Perlis : "Chinese should adore APL" #237

Open zhao-huang opened 4 years ago

zhao-huang commented 4 years ago

Classical Chinese has some characteristics shared with combinatory logic. If a programming language's basic syntax is a sequent of composable functions, it will show a unique aesthetic with point-free style (aka tacit programming paradigm).

Some programming languages such as APL and J were designed in this style. But at the time, people felt that this programming paradigm was too weird, and for other sake, cause they are not popular.

Recently, some people have started using point-free style in common functional languages (such as Haskell, OCaml, Scala etc). Due to the syntax of these languages is not designed for this style, it led to a need to use the tedious compose operator and bracket. However, it's undeniable that proper use of this design pattern can make the code more elegant.

文言文的組合方式有不少能反映函數式編程的結構,尤其是 point-free 風格的函數式編程。 例如:「勾股個自乘並之。」 個、自乘、並 都是可組合的函數, 就是 map/foreach 就是 fold/reduce

// 雖然函數式語言如 Haskell, Idris 寫這類代碼更友好
// 因為會 JS 的人比較多,稍微用 JS 表示一下意思
// 其實下列是 chaining 風格的代碼,而非 point-free
// 但意圖相似

let sum = (acc, n) => acc + n;

// 勾股個自乘並之
let a = 3, b = 4;
[a,b].map(x => x * x).reduce(sum);

雖然 《九章算術》以及許多算術書所描述的是算籌的操作過程,即是過程式的算法描述。但在小粒度的數學用語中,卻有很多是這種偏向函數式風格的語言。

如果對這種風格的中文編程語言有興趣,可以考慮一下如何結合這方面的設計思想,如果設計得當應該能使代碼更有漢語文法的特色 :) 但要用這種風格做好語言的設計與實現,必然會是個困難的工作,也許甚至無法達成。

UltimatePea commented 4 years ago

您好,请问是否有兴趣具体整理一下古书中出现的关于现今函数式编程中常用函数的翻译?例如 map fold reduce之类的?

Cyvadra commented 4 years ago

同求,working on a similar proj, 但是保留字和函數名太麻煩了,實際應用有很多用到的功能,不是加減乘除就完事的

nobodxbodon commented 3 months ago

尝试翻译了apl符号:https://aplwiki.com/wiki/Chinese_terminology