'''Wikipedia''' [http://wikipedia.org/] is an ambitious attempt to collect much of the world's wisdom in a Wiki. ---- [AMG]: I just noticed that the Wikipedia page on Duck Typing [http://en.wikipedia.org/wiki/Duck_typing] completely fails to mention Tcl. This needs to change, seeing as how Tcl pretty much wrote the book on duck typing. [PYK] 2014-05-28: I sorta thought [Python] wrote the book on duck typing. I think expanding the presence of [Tcl] on Wikipedia is a very useful activity, and hope someone finds the time to expand the duck typing article there. [AMG]: Not at all. In Python, types are intrinsic in values, whereas in Tcl, types exist only within the program's interpretation of values. Python sees `"2"` and `2` as distinct, and they cannot be +'ed (added or concatenated) without the programmer explicitly begging that one be converted from str to int, or vice versa. Tcl sees no distinction between the two. The determination between adding or concatenation is made not by the inherent type (a concept foreign to Tcl), but rather by having adding and concatenation being distinct operators. With Tcl, the type is inferred according to the operations being performed on the value, and the type can freely change from moment to moment with no need for explicit conversions. The interpreter figures out the type based on what the programmer is trying to do. With Python, the type is explicitly declared according to how the value was constructed. Surround it in quotes, and it's a string. Put it in brackets, and it's a mutable list. Put it in parentheses with commas, and it's an immutable list. Put it in braces, and it's a dict. And so forth. Conversions are not automatic, and the programmer has to explicitly ask for them. ====== set operands {"2" 2} tcl::mathop::+ {*}$operands ;# 4 join $operands {} ;# 22 ====== ======none operands = ("2", 2) reduce(lambda x, y: x + y, operands) # cannot concatenate 'str' and 'int' objects reduce(lambda x, y: int(x) + int(y), operands) # 4 reduce(lambda x, y: str(x) + str(y), operands) # 22 ====== <> Internet