Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
の コ コ 本   註   こ シ カ こ そ サ カ カ 加   註
事 タ タ と       と ン ズ の う ム ズ ズ え
で エ エ は   主   で サ ・ ノ で で 達 達 る   再
す を は     プ   す ム ...
About the name
●
I call the language 'haku' because I like the
sound of it, and also because that word
can be written in m...
Haku from Spirited Away
珀
His name would be written
邇芸速水琥珀主
... or in full ...
魄
but I prefer to write it
soul, spirit
because that means
Literary Japanese
の コ コ 本   註   こ シ カ こ そ サ カ カ 加   註
事 タ タ と       と ン ズ の う ム ズ ズ え
で エ エ は   主   で サ ・ ノ で で 達 達 る   再
す を は     プ   す ム ...
の コ コ 本   註   こ シ カ こ そ サ カ カ 加   註
事 タ タ と       と ン ズ の う ム ズ ズ え
で エ エ は   主   で サ ・ ノ で で 達 達 る   再
す を は     プ   す ム ...
Motivation
●
There are several practical programming
languages based on Japanese. So why make
another one?
●
Short answer:...
Motivation
●
I don't want to create a practical language.
●
I want to explore what the result is of creating a
programming...
Motivation: syntax
●
I also want the language to be closer, at least
visually, to literary Japanese.
●
So Haku uses the Ja...
Motivation: grammar
●
Japanese grammar is very different from most Indo-
European languages. In particular, it has subject...
Motivation: giving meaning
●
In principle, a programming language does not need to be
based on natural language at all.
●
...
Parsing
●
Japanese does not use spaces. So how do we
tokenise a string of Japanese?
●
There are three writing systems:
– k...
Parsing
●
Katakana is used in a similar way as italics
●
Nouns, verb, adjectives and adverbs normally
start with a kanji
●...
Parsing
●
So we have some simple tokenisation rules:
– a sequence of katakana
– a kanji followed by more kanji or hiragana...
Tokenisation example
ラムダは或エクスでエクス掛けるエクスです。
Tokenisation example
ラムダは或エクスでエクス掛けるエクスです。
Tokenisation example
ラムダは
或エクスで
エクス掛けるエクス
です。
Tokenisation example
ラムダ , エクス : katakana word
は , で : (hiragana) particle
或 : (kanji) pre-noun adjective
掛ける : verb (kanj...
A more complete example
試すとはサイとワイで
【このエクス割るサイに
ワが四十二で御座います、
エクスがワ足すワイで御座います】
と弐を掛けて下さい
と言う事で御座います。
Semantics
●
Haku is a simple, mostly-pure, implicitly typed,
strict functional language.
●
Think Scheme with a sprinkling ...
Core constructs
●
numeric and string constants
●
named functions
●
lambdas
●
let-bindings
●
lists and maps
●
conditional e...
A Haku example
註 例のはくのプログラム。
本とは
ラムダは或エクスでエクス掛けるエクスです、
カズ達は八十八と七千百と五十五で、
イ・ロ・ハ・空はカズ達で、
シンカズはイとロの和で、
シンカズを見せる、
ケッカは〈七百四十壱をラ...
Compiled to Scheme
; 例のはくのプログラム
(define (hon)
(let* (
(RAMUDA (lambda (EKUSU) (* EKUSU EKUSU )))
(KAZUTACHI (list 88 7100 ...
The main program
●
註 ... 。 is a comment.
●
The main program (called 本 , hon) has a fixed begin and end string:
本とは ... の事で...
Assignments and lambdas
●
In the example we have an number of different types of assignments:
ラムダは或エクスでエクス掛けるエクスです、
"RAMUD...
Numbers and lists
●
Next we have an assignment to a list of number constants:
カズ達は八十八と七千百と五十五です、
"KAZUTachi wa 88 to 7100 ...
Iroha
●
Next we have a bit of syntactic sugar borrowed from Haskell (cons):
イ・ロ・ハ・空はカズ達です、
"I:RO:HA:Kuu wa KAZUTachi desu,...
Arithmetic operations
●
The next assignment,
シンカズはイとロの和で、
"SHINKAZU wa I to RO no Wa de"
●
This means
"SHINKAZU is the sum...
Printing
●
Then we have a print function:
シンカズを見せる、
"SHINKAZU wo Miseru"
"To show SHINKAZU"
●
In Scheme:
(displayln SHINKA...
Calling a bound lambda
●
Then follows another assignment:
ケッカは〈七百四十壱をラムダする〉足す九百十九、
●
The 〈 ... 〉 are one form of parenthes...
More parentheses
●
And finally we show the result of an expression:
【ケッカとシンカズの和】を見せる
●
The 【 ... 】 are another form of par...
TMTOWDI
●
Haku offers variants for many constructs:
– Identifiers (verb, noun, katakana-word)
– Function calls (verb, noun...
Haku registers
●
Plain Haku
メッセージを送る。
“To send a message”
●
Polite Haku
メッセージを送って下さい。
“Please send the message”
●
And ther...
Implementation
●
Haku is implemented in Raku, a gradually-typed multi-paradigm
language.
●
The parser uses Raku’s Grammars...
If you don’t know Japanese
●
Haku requires some knowledge of Japanese.
●
But most programmers outside of Japan don’t
have ...
Roku
●
A version of Haku without kanji or kana.
●
It uses Romaji (latin alphabet) and some ASCII
symbols instead.
●
It sti...
Roku example
# Example Roku program.
Main{
LL=X->XtimesX;
NRS=77,7100,55;
X:Y:Z:[]=NRS;
NNR=X,Y|>sum;
NNR|>show;
RES=(741|...
Current status
●
Haku is available to play around with but it
is not feature-complete or robust.
●
Roku is in the design p...
Thank you!
どうも有難う御座います!
Questions?
質問?
Haku, a toy functional language  based on literary Japanese
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
What to Upload to SlideShare
Next
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

0

Share

Haku, a toy functional language based on literary Japanese

Download to read offline

Haku is a natural language functional programming language based on literary Japanese. This talk is discusses the motivation behind Haku and explains the language by example. You don't need to know Japanese or have read the Haku documentation.

https://codeberg.org/wimvanderbauwhede/haku

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Haku, a toy functional language based on literary Japanese

  1. 1. の コ コ 本   註   こ シ カ こ そ サ カ カ 加   註 事 タ タ と       と ン ズ の う ム ズ ズ え で エ エ は   主   で サ ・ ノ で で 達 達 る   再 す を は     プ   す ム ノ コ な す の と と   帰 。 見 三     ロ   。 が コ カ い け 長 サ は   関   せ 十     グ     サ カ ズ 場 れ さ ム     数   る 四     ラ     ム ズ 達 合 ど が で     の     と     ム     に 達 と は 、 零       例     八     。     カ が シ 、   に       の     を           ズ カ ン     等       ﹁     加           を ズ サ     し       加     え           足 達 ム     い       え     る           す で を     場       る     で           る 、 加     合       ﹂ Haku A toy functional language based on literary Japanese Wim Vanderbauwhede 2021
  2. 2. About the name ● I call the language '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.
  3. 3. Haku from Spirited Away
  4. 4. 珀 His name would be written
  5. 5. 邇芸速水琥珀主 ... or in full ...
  6. 6. 魄 but I prefer to write it
  7. 7. soul, spirit because that means
  8. 8. Literary Japanese
  9. 9. の コ コ 本   註   こ シ カ こ そ サ カ カ 加   註 事 タ タ と       と ン ズ の う ム ズ ズ え で エ エ は   主   で サ ・ ノ で で 達 達 る   再 す を は     プ   す ム ノ コ な す の と と   帰 。 見 三     ロ   。 が コ カ い け 長 サ は   関   せ 十     グ     サ カ ズ 場 れ さ ム     数   る 四     ラ     ム ズ 達 合 ど が で     の     と     ム     に 達 と は 、 零       例     八     。     カ が シ 、   に       の     を           ズ カ ン     等       ﹁     加           を ズ サ     し       加     え           足 達 ム     い       え     る           す で を     場       る     で           る 、 加     合       ﹂     、               え     は       。                     る                     に                     、 A Haku program の コ コ 本   註   こ シ カ こ そ サ カ カ 加   註 事 タ タ と       と ン ズ の う ム ズ ズ え で エ エ は   主   で サ ・ ノ で で 達 達 る   再 す を は     プ   す ム ノ コ な す の と と   帰 。 見 三     ロ   。 が コ カ い け 長 サ は   関   せ 十     グ     サ カ ズ 場 れ さ ム     数   る 四     ラ     ム ズ 達 合 ど が で     の     と     ム     に 達 と は 、 零       例     八     。     カ が シ 、   に       の     を           ズ カ ン     等       ﹁     加           を ズ サ     し       加     え           足 達 ム     い       え     る           す で を     場       る     で           る 、 加     合       ﹂     、               え     は       。                     る                     に                     、
  10. 10. の コ コ 本   註   こ シ カ こ そ サ カ カ 加   註 事 タ タ と       と ン ズ の う ム ズ ズ え で エ エ は   主   で サ ・ ノ で で 達 達 る   再 す を は     プ   す ム ノ コ な す の と と   帰 。 見 三     ロ   。 が コ カ い け 長 サ は   関   せ 十     グ     サ カ ズ 場 れ さ ム     数   る 四     ラ     ム ズ 達 合 ど が で     の     と     ム     に 達 と は 、 零       例     八     。     カ が シ 、   に       の     を           ズ カ ン     等       ﹁     加           を ズ サ     し       加     え           足 達 ム     い       え     る           す で を     場       る     で           る 、 加     合       ﹂     、               え     は       。                     る                     に                     、 A Haku program
  11. 11. Motivation ● There are several practical programming languages based on Japanese. So why make another one? ● Short answer: to see what I would end up with. ● Slightly longer answer: the existing languages serve a practical purpose. They want to make programming easier for Japanese native speakers, and most of them target education.
  12. 12. Motivation ● I don't want to create a practical language. ● I want to explore what the result is of creating a programming language based on a non-English language, in terms of syntax, grammar and vocabulary. ● In particular, I want to allow the programmer some control over the register of the language.
  13. 13. Motivation: syntax ● I also want the language to be closer, at least visually, to literary Japanese. ● So Haku uses the Japanese writing system. ● It does not use Roman letters, Arabic digits or common arithmetic or logical operators. ● And it supports top-to-bottom, right-to-left writing.
  14. 14. Motivation: grammar ● Japanese grammar is very different from most Indo- European languages. In particular, it has subject-object- verb order. This makes familiar constructs quite different. ● From a poll about how coders perceive function calls, 3/4 of respondents answered "imperative" (other choices: infinitive, noun, -ing form). In Japanese, the imperative is rarely used. ● In Haku, a function can be a verb or a noun, and the difference is clear from the syntax and the grammar. You can conjugate the verb forms.
  15. 15. Motivation: giving meaning ● In principle, a programming language does not need to be based on natural language at all. ● E.g. APL, uses symbols for everything. Agda programmers also use many mathematical symbols. ● It works because of familiarity with the symbols. ● Can an experienced programmer who does not know Japanese understand a Haku program? ● If not, what are the minimal changes needed to make it understandable?
  16. 16. Parsing ● Japanese does not use spaces. So how do we tokenise a string of Japanese? ● There are three writing systems: – katakana (angular): カタカナ – hiragana (squigly): ひらがな – kanji (Chinese character, complicated): 漢字
  17. 17. Parsing ● Katakana is used in a similar way as italics ● Nouns, verb, adjectives and adverbs normally start with a kanji ● Hiragana is used for verb/adjective/adverb endings and "particles", small words or suffixes that help identify the words in a sentence. ● A verb/adjective/adverb can't end with a hiragana character that represents a particle.
  18. 18. Parsing ● So we have some simple tokenisation rules: – a sequence of katakana – a kanji followed by more kanji or hiragana that do not represent particles – hiragana that represent particles ● Where that fails, we can introduce parentheses. ● In practice, only specific adverbs and adjectives are used in Haku.
  19. 19. Tokenisation example ラムダは或エクスでエクス掛けるエクスです。
  20. 20. Tokenisation example ラムダは或エクスでエクス掛けるエクスです。
  21. 21. Tokenisation example ラムダは 或エクスで エクス掛けるエクス です。
  22. 22. Tokenisation example ラムダ , エクス : katakana word は , で : (hiragana) particle 或 : (kanji) pre-noun adjective 掛ける : verb (kanji followed by hiragana) です : copula (hiragana)
  23. 23. A more complete example 試すとはサイとワイで 【このエクス割るサイに ワが四十二で御座います、 エクスがワ足すワイで御座います】 と弐を掛けて下さい と言う事で御座います。
  24. 24. Semantics ● Haku is a simple, mostly-pure, implicitly typed, strict functional language. ● Think Scheme with a sprinkling of Haskell
  25. 25. Core constructs ● numeric and string constants ● named functions ● lambdas ● let-bindings ● lists and maps ● conditional expressions
  26. 26. A Haku example 註 例のはくのプログラム。 本とは ラムダは或エクスでエクス掛けるエクスです、 カズ達は八十八と七千百と五十五で、 イ・ロ・ハ・空はカズ達で、 シンカズはイとロの和で、 シンカズを見せる、 ケッカは〈七百四十壱をラムダする〉足す九百十九、 【ケッカとシンカズの和】を見せる のことです。
  27. 27. Compiled to Scheme ; 例のはくのプログラム (define (hon) (let* ( (RAMUDA (lambda (EKUSU) (* EKUSU EKUSU ))) (KAZUTACHI (list 88 7100 55)) (I (car KAZUTACHI)) (RO (cadr KAZUTACHI)) (HA (caddr KAZUTACHI)) (SHINKAZU (+ I RO )) (KEKKA (+ (RAMUDA 741) 919 )) ) (displayln SHINKAZU) (displayln (+ KEKKA SHINKAZU )) ) ) (hon)
  28. 28. The main program ● 註 ... 。 is a comment. ● The main program (called 本 , hon) has a fixed begin and end string: 本とは ... の事です。 ● In Romaji this reads: "Hon to wa ... no koto desu." ● This roughly translates as "Main is the following thing(s): ...". ● In Scheme I emit Hon as a function with as body a let*-binding (i.e. binding is sequential): (define (hon) (let* ( … ) … ))
  29. 29. Assignments and lambdas ● In the example we have an number of different types of assignments: ラムダは或エクスでエクス掛けるエクスです、 "RAMUDA wa aru EKSU de EKSU Kakeru EKSU desu" ● Katakana is for variables, kanji for functions and keywords, hiragana for keywords and verb endings (e.g. in 掛ける and 見せる ). ● This means "as for RAMUDA, with a given X it is X times X", so RAMUDA binds to a lambda function. The 或 is like in Haskell. ● In Scheme this becomes: (RAMUDA (lambda (EKUSU) (* EKUSU EKUSU )))
  30. 30. Numbers and lists ● Next we have an assignment to a list of number constants: カズ達は八十八と七千百と五十五です、 "KAZUTachi wa 88 to 7100 to 55 desu," ● Numbers are written in kanji using the Japanese system. ● The particle to is the list separator. ● You can use 達 tachi to show that a variable name is plural. ● In Scheme this becomes: (KAZUTACHI (list 88 7100 55))
  31. 31. Iroha ● Next we have a bit of syntactic sugar borrowed from Haskell (cons): イ・ロ・ハ・空はカズ達です、 "I:RO:HA:Kuu wa KAZUTachi desu," ● 空 kuu means "empty". ● This means that the list is deconstructed into elements I, RO, HA and and empty list. ● Scheme does not have this kind of pattern matching so each assignment is generated separately using car, cadr and friends.
  32. 32. Arithmetic operations ● The next assignment, シンカズはイとロの和で、 "SHINKAZU wa I to RO no Wa de" ● This means "SHINKAZU is the sum of I and RO" ● There is also - ( 差 ), * ( 積 ) and / ( 除 ) ● In Scheme (SHINKAZU (+ I RO ))
  33. 33. Printing ● Then we have a print function: シンカズを見せる、 "SHINKAZU wo Miseru" "To show SHINKAZU" ● In Scheme: (displayln SHINKAZU)
  34. 34. Calling a bound lambda ● Then follows another assignment: ケッカは〈七百四十壱をラムダする〉足す九百十九、 ● The 〈 ... 〉 are one form of parentheses "KEKKA wa (741 wo RAMUDA suru) Tasu 919" "KEKKA is (RAMUDA of 741) plus 919" (KEKKA (+ (RAMUDA 741) 919 ))
  35. 35. More parentheses ● And finally we show the result of an expression: 【ケッカとシンカズの和】を見せる ● The 【 ... 】 are another form of parentheses "(KEKKA to SHINKAZU no Wa) wo Miseru" "To show the sum of KEKKA and SHINKAZU" (displayln (+ KEKKA SHINKAZU ))
  36. 36. TMTOWDI ● Haku offers variants for many constructs: – Identifiers (verb, noun, katakana-word) – Function calls (verb, noun, adjectival) – Conditionals – Let-bindings ● And Haku allows verb conjugation
  37. 37. Haku registers ● Plain Haku メッセージを送る。 “To send a message” ● Polite Haku メッセージを送って下さい。 “Please send the message” ● And there are many more forms ● Insistent Haku メッセージを送なさい。 “Do send the message” ● Adverbial 送ったメッセージ。 “The sent message” ● Given a function send: 送るとは ... and an argument message: メッセージ ● In Scheme: (send message)
  38. 38. Implementation ● Haku is implemented in Raku, a gradually-typed multi-paradigm language. ● The parser uses Raku’s Grammars. It is a recursive descent, longest token match parser. ● The parser populates an AST using Haku’s Actions. ● The AST is an algebraic datatype implemented using Haku’s Roles. ● The emitter generates Raku code which is executed via dynamic module loading. ● Currently all type checking is delegated to Raku.
  39. 39. If you don’t know Japanese ● Haku requires some knowledge of Japanese. ● But most programmers outside of Japan don’t have this. ● How can they still experience Haku? ● Enter Roku!
  40. 40. Roku ● A version of Haku without kanji or kana. ● It uses Romaji (latin alphabet) and some ASCII symbols instead. ● It still keeps Haku's "no whitespace" idea and the grammatical order, and the case reflects the kana/kanji.
  41. 41. Roku example # Example Roku program. Main{ LL=X->XtimesX; NRS=77,7100,55; X:Y:Z:[]=NRS; NNR=X,Y|>sum; NNR|>show; RES=(741|>LL)add919; (RES,NNR|>sum)|>show }
  42. 42. Current status ● Haku is available to play around with but it is not feature-complete or robust. ● Roku is in the design phase. ● You can find Haku at codeberg.org/wimvanderbauwhede/haku
  43. 43. Thank you! どうも有難う御座います!
  44. 44. Questions? 質問?

Haku is a natural language functional programming language based on literary Japanese. This talk is discusses the motivation behind Haku and explains the language by example. You don't need to know Japanese or have read the Haku documentation. https://codeberg.org/wimvanderbauwhede/haku

Views

Total views

2,152

On Slideshare

0

From embeds

0

Number of embeds

32

Actions

Downloads

2

Shares

0

Comments

0

Likes

0

×