2019-06-08

Tclsh and Here document

Here document

之前我只有在 bash 使用過,今天突然間想試看看 tclsh。我發現…… 對,可以使用同樣的手法。下面就是一個測試的例子:
tclsh - << "EOF"
puts "HELLO World"
EOF

再來是另外一個簡單的測試:
tclsh - << "EOF"
puts [expr 99 + 1]
EOF

這樣就可以在命令列執行簡單的 tclsh 命令。

2019-06-02

Functional Programming

Functional Programming (Tcler's Wiki)


Tcl 是個很奇妙的語言,就如同下面說的:

As with many things, Tcl is rather unique in this area. Commands themselves can not be passed as arguments to other commands, but their names can, which provides something very similar to first-class functions. Additionally, apply can be used to interpret a value as a function and evaluate it, providing the equivalent of lambda functions.


Tcl 的表達方式與波蘭表示法 (Polish notation) 一樣,和 Lisp 的 S-expression 的精神十分相像,特點是操作符置於操作數的前面(就是如果是一連串資料所組合成的述句,Tcl 述句的第一個是一個 command,後面是 command 要處理的資料)。

Tcl 也跟 Lisp 一樣,並不是純粹的 Functional Language,而是支援多重典範的語言。