Haku: A toy functional programming language based on literary Japanese
codeberg.org
codeberg.org
The book is
Lambda is x times x times x.
Numbers are 88, 7100 and 55.
A, B, C and null are Numbers.
NewNumber is the sum of A and B.
Display NewNumber.
Result is <apply Lambda to 741> plus 919.
Display [sum of Result and NewNumber].
End.
If it feels to you like a riddle poem, it's exactly what the
original program sounds like in Japanese.In case anyone is wondering, here is an equivalent Python code:
def main():
f = lambda x: x * x * x
numbers = [88, 7100, 55]
a, b, c = numbers
new_number = a + b
print(new_number)
result = f(741) + 919
print(result + new_number)A lambda of x is x times x.
(X de X kakeru X desu)
NewNumber is shown
(Also gets the word order closer to the original)https://nadesi.com/v3/doc/index.php?%E3%83%81%E3%83%A5%E3%83...
「こんにちは」と表示
Display 「Konnichiwa」
5に6を掛けて5を足して7で割って表示。
Multiply 5 by 6, then add 5, then divide by 7, then display it.
Sample program: 「身長は何センチですか」と尋ねる。
Ask "What is your height in cm?"
身長Mはそれ÷100
heightM is that divided by 100.
標準体重は22×身長M×身長M
optimalWeight is 22 x heightM x heightM.
「標準体重は、{標準体重}kgです。」と表示。
Display "Your optimal weight is {optimalWeight} kg."
Since it's basically natural language, it's a really nice language for introducing Japanese speakers to programming!====
There's also this language, Wenyan-lang, that imitates classical Chinese: https://github.com/LingDong-/wenyan-lang Sample:
Wenyan:
吾有一數。曰三。名之曰「甲」。
We have a number. It is 3. Its name is n.
為是「甲」遍。
Done n times:
吾有一言。曰「「問天地好在。」」。書之。
We have a phrase. It is "問天地好在". Write it.
云云。
End.
Equivalent JavaScript: var n = 3;
for (var i = 0; i < n; i++) {
console.log("問天地好在。");
}This was driving me nuts because I could see 740 in it, but not 741 like the translation.
It turns out that 壱, 弌 and 壹 are used as 'one' in legal documents instead of the more common 一.
I've still got a long way to go learning Japanese.
It isn't. Few people in the world are unfamiliar with the Latin alphabet, definitely not the Japanese or any other wealthy nation. And since most really poor countries use the Latin alphabet, often for colonial reasons, I don't really think there is any large group of people that aren't familiar with it.
But yeah, programming will be slightly harder for them than for you or me.
In Haiku parse tree
The oroboros told me
"In Haiku parse tree..."Although I’m not sure what meaningful function it would have.
Maybe some async system? Or lazy vs eager eval? E.g
x = got_val(x)
Would evaluate before assignment, while x = get_val(x)
Would evaluate lazily.At the end of the readme the author says it’s partly from the male protagonist in Spirited away, who is also named Haku.
So if Ghibli can get away with it …
"Haku" is an unusual string in Anglophone culture, so it makes sense that people would mentally associate it strongly with the first (or most frequent, or most recent) meaning they encounter. For a native Japanese speaker, I imagine that it would be viewed as any common prefix or two-letter word would be in English — if not as even more generic, because Japanese seems to have so many more homophones than English (based on my very limited knowledge of the language).
Both of the reasons for the many homophones in Japanese are related to Chinese:
1. Japanese use both native Japanese words, like はく (ha-ku), and Chinese loanwords, like 白 (HAKU). Due to the very limited phonology of Japanese, these often coincide.
2. Again due to the limited phonology, a lot of sounds that in Chinese sounded different will coincide in Japanese.
By the way, HAKU and all other single character sounds that come from Chinese were originally single syllables, but since a syllable can't end in K in Japanese they add a U to it.
People might object that Mandarin also doesn't allow syllables that end in K, but the Chinese spoken when these words were borrowed did, just like Cantonese still does.
HAKU in Japanese is BAI in Mandarin and BAAK in Cantonese.
Mandarin really feels like a streamlined variant of Chinese, probably the classic lingua franca affliction. The tone system is also impoverished.
Hakka preserves some archaic features though, would be interesting to learn more about that.
Hakka retains the -m final, instead of merging it to -n. It retains distinct 'round' and 'sharp' (velar and dental) onsets in positions where some Mandarin varieties (including Standard) merge them to the new palatal j/q/x.
The Middle Chinese palatal ny- is lost in Hakka as it is almost everywhere. It merged with r- in Mandarin, y- in Yue, and ng- in Hakka. So you can't read the archaic form directly off any one of those varieties, but you can detect it by comparing any two.
Hakka tonal developments are middle-of-the-road. Like every variety of Chinese, it had the four Middle Chinese tones altered by the voicing feature of the syllable onset, and like every variety outside of Wu/Shanghainese, it then lost the voicing feature itself.
Hakka splits the ping/level tone in two by voicing, like almost every variety does. It splits the ru/entering 'tone' (the syllables with final stops) by voicing, like almost every non-Mandarin variety does, instead of disintegrating it like Mandarin.
In the shang/rising tone, Hakka agrees with Mandarin against Wu and Yue that you don't just split the tone down the middle by voicing; you split off voiced obstruent onsets and leave voiced sonorant onsets alone. It agrees with Mandarin and Wu against Yue that the split-off voiced onsets (whether all of them or just the obstruents) merge into the qu/departing tone.
Hakka agrees with Mandarin against almost everybody else that the qu/departing tone does not split.
The spoken language encodes hints in tones so homophones aren’t necessarily “homo” phones - Haku used as verb and as a name, or kuma as in bears and as in black spots under eyes, are pronounced slightly differently. If you listen really closely you might notice “ha” in Hali’s name is pronounced slightly stronger.
I think I would have said "送りなさい" and "読む為に". Hopefully, Haku is or can be made flexible enough to handle that.
A more natural form of those sentences would be "メッセージ/文書を送信(Send message/text)" and "書類を開いて読む(open and read document)" or "書類を読み込む(read-ingest document)", than implied imperative "[You] must send message" or "[You] open document for the purpose of reading" which don't feel to me that they follow this topic-comment logical structures.
This topic-comment model is also seen in Nadesiko Japanese programming language, as quoted below from "open file" function reference page:
> 「ファイル.txt」を開いて、Sに代入。
> Sを表示。
(my attempt at translation:)
> "file.txt" be opened, S it assign to.
> S be displayed.
As clearly seen, the object such as filename or variable are brought up first, then subsequently augmented, with subject simply missing.
1: https://en.wikipedia.org/wiki/Japanese_grammar
2: https://nadesi.com/v3/doc/index.php?plugin_node%2F%E9%96%8B&...
You can’t have suru work on a verb, so the author turns the verb “to read” into a noun by adding the no.
The kanji for suru and the lack of a wo kinda hides what is going on.
読むのをする→読むのをしに→読むのを為に→読むの為に
For the other one, I agree with you. Basically the only real looking result on google for “送なさい” is this thread and haku’s homepage….
https://docs.raku.org/language/grammars
https://codeberg.org/wimvanderbauwhede/haku/src/branch/main/...
"I call it 'haku' because I like the sound of it, and also because that word can be written in many ways and mean many things in Japanese. I was definitely thinking about Haku from Spirited Away. Also, I like the resemblance with Raku, the implementation language. I would write it 珀 (amber) or 魄 (soul, spirit)."