Version 2 of duck typing

Updated 2010-06-29 19:58:04 by AMG

AMG: In Tcl, each value's data type is implicitly determined by the operations performed on the value. This is called "duck typing" [L1 ].

set data {1 2 3 4}     ;# $data is a string
llength $data          ;# $data is a list
dict size $data        ;# $data is a dict
set data 42            ;# $data is a string
expr $data             ;# $data is an expression
expr {$data}           ;# $data is an integer
regexp $data 4242      ;# $data is a regexp
set data expr 99     ;# $data is an integer
string length $data    ;# $data is a string

and so on.

Beware of shimmering!