Version 6 of Fun with Chinese Characters

Updated 2006-11-18 17:21:12

JimG 20050425

I am just starting to learn Tcl. Find it's fun when using Chinese Characters.

     puts "The next line is in Chinese. Since we don't
           use blank space to separate words, {}s and \"s are not needed!"
     puts 中文不用空格来分词,所以句子不需要用引号或者大括号。
      set cs 白日依山尽,黄河入海流。欲穷千里目,更上一层楼。
      puts [string replace $cs end-5 中文更自由。]

It's interesting.

There're others to come...

KJN 2005-05-20

Non-ASCII characters are first-class citizens in Tcl (unlike other languages which "support" Unicode as a kind of optional extra). Tcl is therefore a very good foundation for programming in languages other than English. Variables and commands can be named with non-ASCII characters, for example:

  set 子 需要用
  puts $子

works just fine. Tcl lets you rename and alias commands, so you can also say

  interp alias {} 用 {} puts
  用 $子

or

  rename puts 用
  用 $子

If you wish, you can keep the "English" commands in a different place by renaming them:

  rename puts en_puts
  interp alias {} 用 {} en_puts
  用 $子

You can do this in a systematic way, by moving the English commands into a namespace.

With just an hour's work, it would be possible to translate every Tcl command into a different natural language. Command options are more difficult, but could be translated in a substitute command that then calls the "real" command. The most difficult problem is with error messages: is there an easy way to modify the error messages that Tcl sends? If so, English could be completely replaced with an arbitrary natural language.


It is doubtlessly big fun to nationalise via rename ... but a drawback remains: you cannot do the same to the sub commands, e.g. string is integer ...