Monolune

Lisp programming language in Chinese

I was reading about the history of programming languages based on Chinese characters when I had an idea. With a Lisp implementation that supports Unicode, it should be possible to create Chinese aliases of Lisp special forms using Lisp macros. Here's a Chinese programming language I made using Racket:

#lang racket
;;;; 華文编程语言。

;;; 巨集。
(define-syntax 定 (make-rename-transformer #'define))
(define-syntax 如 (make-rename-transformer #'if))
(define-syntax 條件 (make-rename-transformer #'cond))
(define-syntax 單 (make-rename-transformer #'list))
(define-syntax 建 (make-rename-transformer #'cons))
(define-syntax 一 (make-rename-transformer #'car))
(define-syntax 二 (make-rename-transformer #'cadr))
(define-syntax 三 (make-rename-transformer #'caddr))
(define-syntax 別 (make-rename-transformer #'cdr))
(define-syntax 出 (make-rename-transformer #'display))
(define-syntax 出行 (make-rename-transformer #'displayln))
(define-syntax 新行 (make-rename-transformer #'newline))
(define-syntax 真 (make-rename-transformer #'true))
(define-syntax 假 (make-rename-transformer #'false))
(define-syntax 和 (make-rename-transformer #'and))
(define-syntax 或 (make-rename-transformer #'or))
(define-syntax 不 (make-rename-transformer #'not))

;;; 開始!

;;; 一。
(出 "我叫小明。")
(出行 "我今年八歲。")
(新行)

;;; 二。
(定 宀 (單 1 2 3 4 5))
(一 宀)  ; 1
(二 宀)  ; 2
(三 宀)  ; 3
(別 宀)  ; '(4 5)

(一 (建 "龍" "鳳"))  ; "龍"

;;; 三。
(定 (乘二 卜)
  (* 2 卜))

(定 (乘四 卜)
  (乘二 (乘二 卜)))

(定 號碼 5)

(如 (= 號碼 1)
  (出行 "號碼是一。")
  (出行 "號碼不是一。"))

(條件 ((> 號碼 0)
       (出行 "號碼比零大。"))
      ((< 號碼 0)
       (出行 "號碼比零小。"))
      (真
       (出行 "號碼是零。")))

(出 "乘了四侯: ")
(出行 (乘四 號碼))

;;; 四。
(或 真 假)
(和 (不 真) (不 假))

Note that some of these keywords may have been translated incorrectly into Chinese because of my limited Chinese.

Interesting observations

  • One immediately notices that most of the keywords have the same length. This is unlike English programming languages where keywords have greater differences in lengths (e.g. cons, display vs. ). I do not think this will be a serious readability problem, because even without syntax highlighting, the code above looks very clear to me. This is probably going to be a matter of personal taste.
  • The code is compact, as the keywords are one or two characters long.
  • I am unable to judge the efficiency of typing out the Chinese characters relative to English letters, because I only started typing Chinese recently.
  • When typing out the code above, I did not have the help of autocomplete suggestions that I normally have when writing code. Notice that since most keywords are one character long, there is nothing left to complete after the first character is entered. I'm not exactly sure how Chinese keyword completions are going to work in the future. Perhaps Chinese autosuggestions can show a list of suggestions before anything is typed.
  • The code above is written in traditional Chinese characters. Small font sizes make it difficult to discern the strokes of the characters. Also, it's possible to mix up two characters that look almost the same. Solution: increase the font size, or use simplified characters. Maybe I'm just overthinking this problem.

Conclusion

The example above could conceivably be turned into a toy Racket language (e.g. #lang chinese or even #lang 華文) that others can use to program using Chinese keywords. At the moment, my knowledge of Scheme, Racket, and Chinese are too limited implement this idea. Is there anyone who's up for the challenge of creating a Chinese Lisp language for Racket?