Wenyan-lang: Classical Chinese Programming Language
spectrum.ieee.org
spectrum.ieee.org
吾有一術。名之曰「曼德博」。欲行是術。必先得二數。曰「寬」。曰「高」。乃行是術曰。
Decomposed:
吾有一術。I have a function.
名之曰「曼德博」。 Named "mandelbrot".
欲行是術。必先得 Who wants to run this function, must first get
二數。two numbers.
曰「寬」。Called "width".
曰「高」。Called "height"
乃行是術曰。 Then run this function as follows:
Essentially, what gets expressed using punctuation in mainstream programming languages is instead described by a short sentence. This would be terribly verbose in English, but it's kind of bearable in Classical Chinese, because each word is only a single character.
> I learned English words like while, for and next from qbasic, for real (it had good help in your local language)
I replaced the word your with the word my in my head without conscious effort. I don't know if it is correct but it is kind of what I expected as I skimmed through the sentence.
There was an article or something saying when we read we can read fast because we don't read every word but rather try to auto complete as we go.
Bear in mind that this is Classical Chinese, not modern Mandarin. For example, as you can see in the helpful gloss a couple levels up, 是 in Classical Chinese is the demonstrative "this". (Whereas in modern Mandarin, 是 is the copula "to be [equating two nouns]", and "this" is 这 or perhaps 本.)
It's amazing how durable some of this stuff is, especially if you look at it from the perspective of recipients of Middle and Classical Chinese culture (such as Japan).
Imagine if the computing revolution were in China instead of USA... we might all be coding using Chinese characters instead of Latin characters right now.
Nah. We would all be using a binary language based on I-Ching trigrams for "octal" representation, and 6-bit (hexagram) "words". A hacker's dream right there.
It doesn’t matter as long as I can do my work.
I would agree that Han characters are a suboptimal technology for everyday written communication due to its large character inventory but this is not a topic where that seems to pose a problem.
Looks like the author decided to make the syntax more concise with their object parser/serializer.
The placed number system without Arabic numerals is weird to me. I get that it's probably not all that efficient decoding long-form Chinese myriadic numbers, but it's still weird to see 「九〇〇」instead of 九百 and 「六一」instead of 六十一; though maybe I'm the weird one for thinking that looks weird.
yup!
https://en.m.wikipedia.org/wiki/Radical_(Chinese_characters)
> For example, the radical 女 appears on the left side in the characters 姐, 媽, 她, 好 and 姓
Notably, in the mnemonic for the character I see another one that has four parts, exceeding my previous experience: 彎.
Also the PDF for the Source Han Sans font, linked in the Wikipedia article, has right under the biángbiángmiàn some other monstrosity, consisting of 18 parts if I'm seeing them right. Of course, it's likely another novelty thing: https://raw.githubusercontent.com/adobe-fonts/source-han-san...
Seems that the latter if ‘Taito’: https://en.wikipedia.org/wiki/Taito_(kanji)
However, once support arrives, it will be as easy as typing "biang", since there's currently no character with that pronunciation. It could be confused with a two-syllable word "bi ang", but there's no such word in Mandarin.
It's not too different from what you'd find in a mathematical proof, or even in actual descriptions of algorithms from old mathematical texts. In that context, usually "word" descriptions are appropriate at the highest structural level of a proof or algorithm, while symbols are handy for the most detailed steps. Of course, this is a claim about what humans are comfortable with; a compiler can deal with any formalized text, whether textual or symbolic.
有術曰「曼德博」。先得數曰「寬」,曰「高」。乃行是術曰。
曼德博術寬高也 (ie. Mandlebrot is a function of width and height.)
In terms of concision, actual keystrokes required to type that are mandeboshukuangaoye (19). Compared to function mandlebrot(width,height){} (35).
1. Ignoring prediction, you need more than three keystrokes to type 事 ("shi"). You type the s, the h, and the i, and then you select the character you want from a menu of suggestions. If you're typing a rarer character (which 事 is not), you'll need additional keystrokes to page through the suggestions.
2. If you're serious about minimizing keystrokes, you'd use double pinyin input, not pinyin input. Two keys per syllable; probably three per character since a lot of repetition means the characters you want are likely to be top suggestions.
Examples: dnxb would input 东南西北.
Then there is learning. While on OSX's pinyin input 曼德波 requires mandebo the first time, it then becomes the first result for all subsequent inputs. We may assume that most multi-character function names would quickly benefit from similar prioritization.
Yes, that's why I started out by saying "ignoring prediction".
However, it's perfectly fair to note that you can and should enter phrases all at once as opposed to one character at a time, which would reduce the double pinyin input from 3 keystrokes per character to two per character plus one per "input unit".
> Then there is learning. While on OSX's pinyin input 曼德波 requires mandebo the first time, it then becomes the first result for all subsequent inputs. We may assume that most multi-character function names would quickly benefit from similar prioritization.
Yes, I noted this specifically:
>> a lot of repetition means the characters you want are likely to be top suggestions
Notably, anything reasonable that lets the user just keep mashing the keys is gonna be faster than selecting stuff on the screen, assuming the user is experienced with typing. Because seeing a wrong predicted character, then looking at the menu, then—crucially—locating the necessary character and then selecting it will be way slower than punching keys in without interaction. Making choices and, separately, selecting stuff on the screen are both slower than just jerking the fingers from muscle memory. More so if the user is a touch-typist.
If you know that your ‘事’ is something like ‘shi down-down-enter’, it would still be faster than the same thing with unfamiliar choices in the menu—or if the prediction and the choices change between invocations. Though this handicap would diminish after the choices settle on the user's typical most-used characters and the user in turn gets used to them.
術means something closer to "method," "procedure," or "way to do something." It's not a function or something that takes arguments in the modern sense.
This programming language is following the style of ancient Chinese mathematical treatises very closely, which are all of the form
X术曰:……
Now there is a way to make your construction work with a wider context, for example in one where you've established 术 as the notion of a function.
Your general impression is correct that earlier texts tend to get more concise and that Classical Chinese is quite grammatically flexible. But there's still limits.
Moreover ancient mathematical texts tended to be far more explicit and written in a far more direct style. Ending particles such as 也 are actually fairly rare in such texts.
The equivalent in English is like if someone wrote a programming language with Shakespearean english syntax and keywords:
I have a function, thou named "mandelbrot".
etc =)Arguably a bit more subtle than your sample code.
Wenyan-lang does this, but it's not really common in normal texts. The reader is just expected to figure it out themselves.
Also note that màn dé bó is the Pinyin transcription of 曼德博 and only reflects the Mandarin pronunciation. In Zhengzhang Shangfang's reconstructed Old Chinese pronunciation, it would be more like moːn tɯːɡ paːɡ. Those syllable-final consonants are preserved in many other Sinitic languages, like Cantonese (that's how they were reconstructed) so Mandarin-based transliterations don't work well for those. As an alternative, 勃 (also Mandarin bó) has the reconstructed Old Chinese pronunciation bɯːd, which is a closer approximation of the "brot" in "mandelbrot".
曼德博 sounds like man de bwo (man4de2bo2 in pinyin). 迈克 (Mike) sounds like my ke
I always thought that if for some reason one wanted to map an existing programming language into Classical Chinese (instead of coming up with something semantically closer resembling the latter), one could do worse than start with the likes of APL.
Consider the Fibonacci example: https://github.com/wenyan-lang/wenyan/blob/master/examples/f...
Is this really how you would like to use Classical Chinese to convey the idea of a Fibonacci number? Indeed, this form maximises the number of words one can use in a single definition; is there anything else for which it is good?
Here's an equivalent program in APL (also naively recursive, that's not necessary how I'd implement Fibonacci sequence):
{⍵<2:⍵⋄+/∇¨⍵-1 2}
If the argument is below 2, that's the answer; otherwise, compute sum of the function applied, in turn, to the argument less 1 and 2.
It's also powering https://tryapl.org/ and available on https://tio.run/
You might also find K interesting -- an APL descendant with somewhat different aesthetics, though Dyalog has recently done a lot of catching up to it. https://code.kx.com/q/
https://news.ycombinator.com/item?id=21840924
https://news.ycombinator.com/item?id=21840101
Also https://medium.com/syncedreview/cmu-senior-develops-worlds-f... via https://news.ycombinator.com/item?id=21864706 (but no comments there).
I'm working on an "inflectional" programming language at the moment, where word order and a whole bunch of other "traditional" features of analytical-language-based programming languages are discarded in favor of word inflection. For example, rather than expressing variable assignment with the '=', we use the ablative case for the source expression and the nominative for the target variable.
Traditional: foo = bar
Inflectional: foo barFrom
I'm not sure whether it would be useful, but it's just an interesting idea to play around with. There's already perligata (Latin) but it doesn't use a lot of the constructs in Latin and doesn't take the inflectional idea too far, so I'm implementing this in Classical Sanskrit. The core idea could be applied to pretty much any highly inflectional language though, like Arabic or Finnish.
https://github.com/wenyan-lang/wenyan/blob/master/examples/z...
I don't have the time to translate at the moment but I'll just leave the two here for others to see just how different they read (and for those who can read Chinese, what similarities they have).
The Wenyan language:
吾有一術。名之曰「增乘開平方」。欲行是術。必先得一數。曰「實」。乃行是術曰。 注曰。『增乘開平方法,以商數乘下法遞增求之。』。 吾有四數。名之曰「果」曰「商」曰「餘」曰「廉」。有數一。名之曰「法」。 恆為是。施「取底除」於「實」於「法」。若其之『商』小於百者乃止也。 乘「法」以百。昔之「法」者。今其是矣云云。 恆為是。若「法」不大於零者乃止也。 乘「果」以十。昔之「果」者。今其是矣。 加「廉」以「商」。乘其以十。昔之「廉」者。今其是矣。 施「取底除」於「實」於「法」。名之曰「甲」。 昔之「實」者。今「甲」之『商』是矣。 昔之「餘」者。今「甲」之『餘』是矣。 昔之「商」者。今零是矣。 恆為是。加「廉」以「商」。乘其以「商」。若其不小於「實」者乃止也。 加「商」以一。昔之「商」者。今其是矣云云。 加「廉」以「商」。乘其以「商」。若其大於「實」者。 減「商」以一。昔之「商」者。今其是矣云云。 加「廉」以「商」。昔之「廉」者。今其是矣。 加「果」以「商」。昔之「果」者。今其是矣。 乘「商」以「廉」。減「實」以其。乘其以「法」。加其以「餘」。昔之「實」者。今其是矣。 施「取底除」於「法」於百。昔之「法」者。今其之『商』是矣云云。 注曰。『商第一位。上商得數以乘下法為乘方。命上商除實。上商得數以乘下法入乘方。一退為廉,下法再退。』。 注曰。『商第二位。商得數以乘下法為隅。命上商除實訖。以上商乘下法入隅,皆名曰廉。一退,下法再退,以求第三位商。』。 注曰。『商第三位。用法如第二位求之。』。 乃得 「果」。 是謂「增乘開平方」之術也。
The original Chinese:
開方術曰:置積為實。借一算步之,超一等。議所得,以一乘所借一算為法,而以除。除已,倍法為定法。其復除。折法而下。復置借算步之如初,以復議一乘之,所得副,以加定法,以除。以所得副從定法。復除折下如前。若開之不盡者為不可開,當以面命之。若實有分者,通分內子為定實。乃開之,訖,開其母報除。若母不可開者,又以母乘定實,乃開之,訖,令如母而一。
Note the original Chinese is based off the rod calculus. https://en.m.wikipedia.org/wiki/Rod_calculus
Such thoughtless dismissal of half the human race is not a good look for a product claiming to improve accessibility.
Compare Greek at a standard 24 characters to English's standard 26.
Historically, they are all obviously written in traditional Chinese characters, However, you can write it in Simplified Chinese since there's usually a 1-1 mapping between Simplified Chinese / Traditional Chinese characters.
Latin grammar isn't all that different from English grammar. It's usually possible to translate a sentence from Latin into English in a way that simultaneously preserves both the meaning and the grammatical structure of the original.
Attempting to do that between unrelated languages is vastly more difficult; in such cases, a translation that tries to preserve the source grammar will usually end up being hopelessly ungrammatical in the target language.
I think you're overestimating, or at least overselling, the degree to which modern Chinese people can read classical text without training.
This is especially evident if you ever read contemporary Chinese works about Chinese history. Large tracts of Classical Chinese are discussed without translation assuming the reader understands the text in question and often the contemporary work itself can read very classically.
Modern literature can also occasionally lapse into Classical Chinese constructions for a sentence or two.
And anecdotally I don't think I've ever met a Chinese high school graduate who didn't have some proficiency with Classical Chinese.
I've said this before elsewhere, sometimes it's useful to think of Classical Chinese as a separate language from modern Chinese, sometimes it's useful to think of it as an extremely elevated register of modern Chinese. Modern literary works can be more or less "classical" in nature depending on the whims of the author.
> This is especially evident if you ever read contemporary Chinese works about Chinese history. Large tracts of Classical Chinese are discussed without translation assuming the reader understands the text in question and often the contemporary work itself can read very classically.
If you read some non-contemporary early modern English literature, you may find Latin, classical Greek, or French discussed or used without translation in the expectation that the reader will be able to understand it directly.
But this is evidence that the reader is expected to have undergone significant training, not that English speakers can understand ancient Greek without training.
> And anecdotally I don't think I've ever met a Chinese high school graduate who didn't have some proficiency with Classical Chinese.
We can be even more definite here: this is because Chinese high school graduates have all received training in Classical Chinese.
Even within Classical Chinese you can be more or less "Classical."
他的名字叫约翰。
其名为约翰。
其名约翰。
其名约翰也。
Moving away from examples in the language itself, high-level programs of advanced modern Mandarin comprehension, both for foreign speakers and native speakers test for some knowledge of Classical Chinese.
Every modern Chinese language for foreign speakers learning program I know of dedicates at least one (if not multiple) module at the advanced level to Classical Chinese (this is separate from a dedicated Classical Chinese course that goes in more detail) with Classical Chinese readings.
For ILR level 5 modern Mandarin fluency the U.S. State Department explicitly lists knowledge of Classical Chinese (to the level of a native speaker) as a prerequisite (and in fact Classical Chinese shows up on a sample test I cannot find at the moment).
It is also a component of the HSK level 6, which suggestively calls it “能读懂略带文言色彩的文章“, that is "can read articles with a slight amount of Classical Chinese flavor" hinting again at a register-like relationship.
And of course Chinese comprehension tests for native speakers in China and Taiwan have a Classical Chinese component.
I would be very surprised to find any similar standard for Latin and English or Latin and French. What ESL program teaches Latin?
Note this isn't just cultural pride from China. These are foreign institutions that have deemed a certain amount of Classical Chinese necessary to understand the modern Mandarin corpus (more so than just set phrases such as sine qua non in English, but true grammar and independent vocabulary).
Sure everyone receives training in Classical Chinese, but that's because it's a symbiotic relationship. Because everyone knows Classical Chinese it influences the modern language. Because it influences the modern language it becomes a prerequisite for Chinese language programs (even those for foreign speakers).
> I would be very surprised to find any similar standard for Latin and English or Latin and French. What ESL program teaches Latin?
> Note this isn't just cultural pride from China. These are foreign institutions that have deemed a certain amount of Classical Chinese necessary to understand the modern Mandarin corpus (more so than just set phrases such as sine qua non in English, but true grammar and independent vocabulary).
It is just cultural pride from China, but cultural pride with many ramifications.
Literacy standards including Latin for high registers of English don't exist now. But they used to. And standards of Latin for high registers of French are of course even more historically normal -- there was a long period where Latin was the highest register of French (exclusively in writing).
You're making the point that Chinese people receive extensive training in Classical Chinese and are therefore familiar with it to differing degrees. But you know what they're not familiar with to differing degrees? Their modern language, which they all know natively. The fact that they can read some Classical Chinese after being trained in it just isn't evidence that they could read it before being trained in it.
Can you show me a sentence that is both Latin and English or both Latin and French? There are plenty of such examples for Classical Chinese and modern Chinese.
At times there's a blurry line between Classical Chinese and modern Chinese. It's a false dichotomy to say that you can train in advanced modern Chinese without training in some Classical Chinese.
Here's a non-exhaustive list of things in Classical Chinese you'll be exposed to because they're still widely used in modern Mandarin.
Its most common pronouns (especially first and third person): 我、其、之 etc.
Its connectives: 为、于、乃、因、与etc.
Its lack of 是 as "to be" and instead leaving "to be" implicit between verbs and nouns: take e.g. the PRC's constitution. Many paragraphs use 是 as "to be" zero times. Few use it more than once or twice.
On a similar note its demonstratives: 此、彼、兹、indeed even 是 again.
And when it comes to standard vocabulary, most of the time a classical meaning of a character remains productive in modern Chinese.
There's certain Classical Chinese works I'd be comfortable using to assess a foreign speaker's modern Mandarin comprehension. For example if a speaker cannot read the 2nd century poem 凤求凰 (especially the first part), they almost certainly cannot read a modern newspaper article. It reads almost exactly like how a modern angsty teenager might try to write a modern Mandarin love poem.
Just about the only category of things you won't see in modern Chinese from classical Chinese are its interjective particles (兮、也、矣、etc) which have no semantic meaning.
What makes Classical Chinese difficult to read for a modern Chinese reader is its extreme concision and its grammatical flexibility. Its vocabulary is only a secondary concern. I would say if you know modern Mandarin, you know probably around 70% to 80% (depending on the text) of the words you'll see in a classical Chinese text, especially for texts after the Warring States period. You're definitely not going to totally understand the text and it's going to be feel laborious picking over each paragraph, but you will understand the gist of what's going on, just based on your modern Mandarin knowledge.
> English represents a strange Romantic-Germanic hybrid (Germanic by linguistic classification but with a tremendous/predominant vocabulary of Romantic origin). A more appropriate comparison would be with respect to a French/Italian/Spanish bibliophile.
L'Inglese rappresenta uno strano ibrido Romantico-Germanico (Germanico come classificazione linguistica ma con un vocabolario tremendamente predominante di origine Romantica). Una più appropriata comparazione sarebbe rispetto ad un bibliofilo Francese/Italiano/Spagnolo.
I have noticed that (in my experience) when you use in English the Latin-originated synonyms of more commonly used English (possibly Germanic originated) words you are perceived as having a higher level of education (and also as being a tad bit snob).
Example, a 9 traditional : 1 simplified map
斗 ⇄ 鬥斗鬪鬦鬭鬬闘閗逗
Here's a list that probably is mostly complete
https://en.wikipedia.org/wiki/Ambiguities_in_Chinese_charact...
"modern" chinese was developed around the 1910s as a push for modernization/literacy as influenced by western imperialism/thought spreading into china. tldr they advocated for readability/accessibility, which meant a stylistic reform of the language.
if you can read modern chinese well enough, you can kinda understand about 30-80% of the meaning, depending how obtuse the text is and or when it was composed, but early chinese education (elementary school) includes some Tang poems from 600-900 AD, but is still quite readable. compared to something like middle english, which modern readers cannot read at all, you can see that the chinese language hasn't changed all that much
cf:
https://en.wikipedia.org/wiki/Classical_Chinese#Grammar_and_...
It helps that ancient texts are usually not presented in the original handwriting (which has changed a lot over the millenia) and of course the writing system masks changes in pronunciation. If you speak Mandarin, try reading a text in another Sinitic language using an alphabetic writing system, e.g. a random article of the Hakka Wikipedia: https://hak.wikipedia.org/ Then consider how different the last common ancestor of both languages must have been.
This is nonsense. Here's some middle english (taken from https://www.chaucermss.org/?manuscript=Dd&tale=GP&version=si... ):
A Millere was there / dwellyng many a day
As any Pecok / he was proud and gay
Pipe he coude and fisshe / and nettes bete
And trne cuppes / & wel wrestel and shete
Ay by his belt / he bar a long panade
And of a swerd / ful trenchaūt was the blade
Middle English is much more similar to modern English than Classical Chinese is to modern Chinese (of any variety), for the obvious reason that Middle English is separated from modern English by less than half the period separating Classical Chinese from modern Chinese.>Middle English is much more similar to modern English than Classical Chinese is to modern Chinese (of any variety), for the obvious reason that Middle English is separated from modern English by less than half the period separating Classical Chinese from modern Chinese.
i think it depends on the specific text in question, but i'm drawing blanks because im not very informed on old lit in general. again tang poems are taught at an early age, but perhaps most text would be harder to read
Hwæt. We Gardena in geardagum,
þeodcyninga, þrym gefrunon,
hu ða æþelingas ellen fremedon.
Oft Scyld Scefing sceaþena þreatum,
monegum mægþum, meodosetla ofteah,
egsode eorlas. Syððan ærest wearð
feasceaft funden, he þæs frofre gebad,
weox under wolcnum, weorðmyndum þah,
oðþæt him æghwylc þara ymbsittendra
ofer hronrade hyran scolde,
gomban gyldan. þæt wæs god cyning.
[1] There are good reasons for this; since Chinese writing bears very little phonetic information, we have only limited knowledge of what Old Chinese sounded like in the first place.
What. We gar-danes' in yore days
thede kings', thrym frained,
how the athelings ellen framed.
Often Shield Sheafing scathers' threats
many maidens, mead-seats' off-towed
eysed Eorlas. Since erst was
few-shaft found, he that frother bode,
waxed under welkin, worth-minds theed,
othat him each there umsittings'
over whale-road hear should
change yielded, that was good king.
Since WenYan is created specifically for written and rarely used for speaking, there is a unique phenomenon in Chinese called "文白分离(Wen Bai Fen Li)", means the 'the Separation of Written and Spoken Chinese'. For nowadays Chinese people, it still requires intensive learning in order to read WenYan text from the ancient time as if it is a foreign language.
This is true for everyone trying to read texts written in a form of their language as it existed more than 2000 years ago. You get a lot of language change in that amount of time.
Here's an example:
* Quelques déclarations
* Suivies d'une boucle
BOOLEEN A←.VRAI.,B←.FAUX.
ENTIER U,W,X←200
NOMBRE PI←3.14159
CHAINE CHN
TABLEAU DE ENTIER TBL[3,3]
QUEUE DE CHAINE Q[8]
ENSEMBLE DE NOMBRE NPREMIER←{1.0,2.0,3.0,7.0}
CHN←'Salut'
X ← SELON X ALORS 1,2,3,7,11 SINON 0
POUR U←0 JUSQUA 2 FAIRE
POUR W←0 JUSQUA 2 FAIRE
TBL[U,W]←X
BOUCLER
BOUCLER
TERMINERNeedless to say, the thing was an absolute dead-end.
The only thing I still feel it had going for it is that assignment to variables were done via the ← sign and not the dreaded '=' so common to modern languages.
[1] https://en.wikipedia.org/wiki/LSE_(programming_language)
> World's First Classical Chinese Programming Language
This is false. There is at least one prior art, first published 18 years ago: http://p3rl.org/Lingua::Sinica::PerlYuYan
It will always be just a hobby like the latin perl script.
Example of the code:
Evil Energy is death
The Legend says doo
Spirit takes Will
Give back Will plus The Legend
Put The Legend into my perspective
my dream was spellbound
While Evil Energy is stronger than my dream
Put Spirit taking my perspective into my perspective
Knock Evil Energy downPlay also has the advantage of being utterly unconstrained by any need to “be serious”, and in having no fear in failures. Can you imagine silly fun design risks being taken while crafting the next “Ada”? Or even the next Python or Swift?
At “worst”, the exercise runs its course having demonstrated pictographic writing systems impractical for real-world software development. (And, for my money, voice is really the next way to go.) Still, with a potential ready-made audience of 1.4 BILLION, I think such exploratory work is not a wasted investment.