
Wenyan-lang: Classical Chinese Programming Language - yread
https://spectrum.ieee.org/tech-talk/computing/software/classical-chinese
======
yorwba
The syntax is slightly cumbersome. For example, the function header of the
mandelbrot snippet at [https://wenyan-snippets.netlify.com/](https://wenyan-
snippets.netlify.com/) reads:

吾有一術。名之曰「曼德博」。欲行是術。必先得二數。曰「寬」。曰「高」。乃行是術曰。

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.

~~~
umvi
I'm super glad programming languages were invented in a country with an
alphabet.

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.

~~~
enz
I wouldn’t care so much, actually. After all, I am not even using my native
language to write programs in, but English.

It doesn’t matter as long as I can do my work.

~~~
umvi
Well, my point is that Latin characters are much easier to learn than Chinese.
You only have to memorize 26 characters, half a dozen punctuation symbols, and
a dozen keywords vs. thousands of pictograms.

~~~
chillacy
Chinese characters can be typed on non Latin keyboards like zhuyin. And maybe
only somewhat relatedly, the fastest texters of Japanese I’ve seen don’t use a
Latin keyboard but some crazy 9 button input grid.

------
5-
As others have noted, the choice of both syntax (extremely elaborate, to the
point of reeking of esoteric languages like Shakespeare) and semantics (scalar
imperative language, JavaScript) seem to be a poor match for Classical
Chinese, known for the brevity and tacitness of its texts.

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...](https://github.com/wenyan-
lang/wenyan/blob/master/examples/fibonacci.wy)

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_.

~~~
tvb12
Can you recommend an APL interpreter? I'd like to fiddle with that.

~~~
5-
Dyalog APL is a mature, modern, and well-supported implementation of APL.
[https://www.dyalog.com/](https://www.dyalog.com/)

It's also powering [https://tryapl.org/](https://tryapl.org/) and available on
[https://tio.run/](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://code.kx.com/q/)

~~~
tvb12
It looks like there's a Jupyter kernel for dyalog. I'll give this a try.
Thanks!

------
dang
Two recent related threads:

[https://news.ycombinator.com/item?id=21840924](https://news.ycombinator.com/item?id=21840924)

[https://news.ycombinator.com/item?id=21840101](https://news.ycombinator.com/item?id=21840101)

Also [https://medium.com/syncedreview/cmu-senior-develops-
worlds-f...](https://medium.com/syncedreview/cmu-senior-develops-worlds-first-
classical-chinese-programming-language-7ffe7fca75ad) via
[https://news.ycombinator.com/item?id=21864706](https://news.ycombinator.com/item?id=21864706)
(but no comments there).

------
5-
See also: Perl in Classical Chinese in Perl:
[https://metacpan.org/pod/Lingua::Sinica::PerlYuYan](https://metacpan.org/pod/Lingua::Sinica::PerlYuYan)

------
KhoomeiK
Definitely a cool concept, but I think the core idea is relatively similar to
English-based programming languages because both Chinese and English are
highly analytical languages (they don't inflect/change words based on case,
tense, etc too much).

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.

------
dwohnitmok
There's a fun example in the GitHub repo for calculating the square root of a
number based off of a real algorithm found in a real ancient Chinese text
(九章算術).

[https://github.com/wenyan-
lang/wenyan/blob/master/examples/z...](https://github.com/wenyan-
lang/wenyan/blob/master/examples/zh_sqrt.wy)

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](https://en.m.wikipedia.org/wiki/Rod_calculus)

------
gabordemooij
This is a very cool language. We are working on a generic localized
programming language ([https://citrine-lang.org/](https://citrine-lang.org/))
and we are looking for help with the Chinese language, maybe the creators of
this beautiful language want to help us out with the Chinese version?

~~~
scarmig
FYI, you write that the language is for "every man," which would be off-
putting for some contributors.

~~~
dang
HN has a lot of users (millions, most likely) whose native language is not
English, so it's a good idea to remember that not everyone here is familiar
with the standards that we may take for granted.

~~~
scarmig
Of course. The intention was to provide information so that they could improve
their copy, not to preen.

------
fctorial
The thing that makes english good for computers is the small alphabet size
(smallest of any language I know), and the fact that a phrase is just a
sequence of characters. These characteristics make it easy to get started with
as well. What is the situation with this language?

~~~
thaumasiotes
> The thing that makes english good for computers is the small alphabet size
> (smallest of any language I know)

Compare Greek at a standard 24 characters to English's standard 26.

~~~
GordonS
Scots Gaelic uses only 23 latin letters, or only 18 if you don't count
accented letters (e.g. it uses both "e" and "è").

~~~
thaumasiotes
Hawaiian has 13 (including the ').

------
auvi
Can someone familiar with Chinese language clarify one thing please: What does
"Classical" mean in this case? And are the characters Simplified Chinese or
Traditional Chinese?

~~~
Aperocky
Classical are refined Chinese used in official communication/literary record
in imperial China/Korea/Japan. The grammar etc haven't really changed over 2
millenia, it is much like how Latin is to Italian/French/Spanish.

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.

~~~
auvi
Many thanks. So the characters shown in the IEEE Spectrum article, are they in
Traditional Chinese? I wonder whether the implementation of the programming
language covers both characters or not.

~~~
Aperocky
Those are traditional Chinese characters, I have no idea if simplified
characters are also supported (shouldn't be hard as it would be another symbol
set, so probably) but if you're going to write classical Chinese, might as
well have the full immersion.

------
ur-whale
Kind of reminds me of something I was subjected to in another life, called LSE
(a frenchified BASIC) [1][2].

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

TERMINER

Needless 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)](https://en.wikipedia.org/wiki/LSE_\(programming_language\))

[2]
[https://fr.wikipedia.org/wiki/LSE_(langage)](https://fr.wikipedia.org/wiki/LSE_\(langage\))

------
bmn__
FTA:

> 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](http://p3rl.org/Lingua::Sinica::PerlYuYan)

------
jiyinyiyong
I got a tiny projected inspired by Wenyan [https://github.com/Cirru/jiuzhang-
lang](https://github.com/Cirru/jiuzhang-lang) if anyone is interested.

------
tacheiordache
Looks very interesting but I don’t understand chinse so I’d be curious what
chinese programmers think about it. I think a scheme lisp in chinese would be
quite efficient in terms of visually parsing the code.

~~~
yen223
This is the equivalent of building a programming language in the style of
Mediaeval English. Fairly sure it's not meant to go mainstream.

~~~
Igelau
I like this idea. Where's the Chaucerian English programming language?

~~~
aquadrop
Not directly, but in a same vein, there's language based on rock music texts:
[https://github.com/RockstarLang/rockstar](https://github.com/RockstarLang/rockstar)

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 down

~~~
hhas01
It’s like AppleScript, but with sick guitar licks! Could be the next
Gloryhammer!

------
ngcc_hk
Know chinese (abd currently studied classical text like zhungzi) and doing IT
many years ... come on one is hard enough and joining two. You are crazy.

