5 ms·
Haku: A toy functional programming language based on literary Japanese
- cloudbonsai 5y agoIf you're not familiar with Japanese language, here is a rough English translation of the first code example: 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)
- Arnavion 5y ago>Lambda is x times x times x. A lambda of x is x times x. (X de X kakeru X desu)
- wodenokoto 5y agoThe author makes a note of function names not being imperative, so the display lines would perhaps be better translated as: NewNumber is shown (Also gets the word order closer to the original)
- trasz 5y agoIe it’s a Japanese COBOL?
- CraneWorm 5y agoWeird name choice, as one of more used homonyms that read as はく means "to vomit".
- davecahill 5y agoThat was the first thing that came to mind for me too. :) I imagine it's intended to be a mix of Raku (the language it compiles to) and ハック (hack).
- wodenokoto 5y agoI thought the same at first. 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 …
- glandium 5y agoThanks to homonyms, haku is a lot of things. - 吐く is to vomit, but also to emit, confess, etc. - 履く is to wear - 掃く is to sweep - 拍 is a beat or a mora and there are plenty more.
- buu700 5y agoAnother I know offhand is that "haku" is a reading of the kanji for "white" (白). What might not be apparent to most English-speakers is that "haku" is just two characters in Japanese (はく), which seems like it could mean practically anything in different contexts. "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).
- Grustaf 5y agoIt's not that it's generic, it's that it has several different, partly unrelated meanings, just like some short English roots that may coincide with some Latin, Greek or Old Norse loan. 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.
- wodenokoto 5y agoShame that conjugation doesn’t affect the program. That would be really cool. 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.
- Rounin 5y agoSome of the examples use grammar I don't quite recognize: "メッセージを送なさい。" "書類を読むの為に開ける" I think I would have said "送りなさい" and "読む為に". Hopefully, Haku is or can be made flexible enough to handle that.
- numpad0 5y ago"書類を読むために開ける" sound to me that it follows subject-object-verb model. When I was taught English, early learner materials would contrast the grammatical difference from Japanese as one is SOV and the other is SVO with subjects frequently omitted, but Wikipedia article[1] today mentions Japanese language has "topic-comment" sentence structure, which seems to make sense to me. 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 https://en.wikipedia.org/wiki/Japanese_grammar 2: https://nadesi.com/v3/doc/index.php?plugin_node%2F%E9%96%8B&show https://nadesi.com/v3/doc/index.php?plugin_node%2F%E9%96%8B&...
- wodenokoto 5y ago> "読む為に" 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….
- junon 5y agoSomewhat tangential, can anyone speak to Codeberg? How does it compare to GitHub/Gitlab/Sourcehut? I've never see it before.
- cestith 5y agoI was wondering the same. I'll also note I went to the page to contribute and be a member since it looks like a non-profit supporting F/OSS. If they check out, I'd like to support them. Unfortunately in order to pay for a membership outside of the Eurozone it takes some extra steps.
- vincentmarle 5y agoAs a non-Japanese speaker I can’t make much sense of this, but this looks super cool! At the same time I can’t stop wondering if this is how English-dominant programming is perceived by “non-roman-alphabet” speakers. Imagine if the Japanese dominated the invention of programming languages, and we all had to learn Japanese to be productive at our jobs.. we’re lucky that ruby was written in English
- Grustaf 5y ago> At the same time I can’t stop wondering if this is how English-dominant programming is perceived by “non-roman-alphabet” speakers. 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.
- retrac 5y agoThere are varying degrees of familiarity. I can technically read Japanese kana, for example. Only a few dozen to memorize, after all. But using a programming language with all its keywords in Japanese is a rather daunting prospect. I still tend to mix up some of the kana visually, for example. And I don't know much Japanese vocabulary so most or all of the terms would be opaque to me. It seems it would be a lot more mental heavy lifting than programming in my native English, especially at the start.
- Grustaf 5y agoSure, my point was that this is not the case for Japanese, probably not for anyone. They are vastly more familiar with Latin characters and English words than you are with Japanese. But yeah, programming will be slightly harder for them than for you or me.
- bntyhntr 5y agoAn old Japanese programmer told me that when he started out, they attempted to translate everything into Japanese. My memory is fuzzy (this conversation was 8 years ago) so take this as more of an example then exactly what he said. For example, "string" was translated by its rope-like meaning, you used that kanji to write it in comments/docs, and when talking to other programmers you'd use the Japanese word. Anyway they gave up on that for the most part.
- ummwhat 5y agoIn Haiku parse tree The oroboros told me "In Haiku parse tree..."
- wccrawford 5y ago>ケッカは〈七百四十壱をラムダする〉足す九百十九、 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.
- retrac 5y agoAll the numbers have secondary forms with extra strokes. (In Chinese too.) It's originally an anti-fraud/legibility technique. But they sometimes get used in formal/legal contexts just because. (One stroke turns 十 10 into 千 1000 otherwise, which is problematic on something like a cheque.)
- wccrawford 5y agoBrilliant. Thanks!
- creamyhorror 5y agoThere's actually a Japanese programming language (created around 2005) that is highly readable and natural - Nadesiko. Here's the first tutorial in Japanese, with executable snippets: https://nadesi.com/v3/doc/index.php?%E3%83%81%E3%83%A5%E3%83%BC%E3%83%88%E3%83%AA%E3%82%A2%E3%83%AB%2F%E6%9C%80%E5%88%9D%E3%81%AE%E4%B8%80%E6%AD%A9&show 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 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("問天地好在。"); }
- earthboundkid 5y agoWhy would you name a programming language "vomit"?
- wodenokoto 5y ago"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)."
- tomhunters 5y agoIf you guys didn't read the readme then here's the reason why did the author named it "Haku". "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)."
- jjice 5y agoOne thing that I find really interesting about Raku (the implementation language) is that grammars are a built in structure (?) of the language. https://docs.raku.org/language/grammars https://docs.raku.org/language/grammars https://codeberg.org/wimvanderbauwhede/haku/src/branch/main/Haku.rakumod#L759 https://codeberg.org/wimvanderbauwhede/haku/src/branch/main/...