Version 2 of Fun with Chinese Characters

Updated 2005-05-20 17:02:16

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
  用 $子

If you wish, you could hide the "English" commands by renaming them:

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

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.