Version 14 of Hunt for Tcl Extensional Equivalents

Updated 2014-05-28 15:15:13 by pooryorick

CMcC {et al} 2008-07-08:

Tcl contains some semantic equivalences. ~~ can be read as approximates. Add more if you find them. The idea is to find cases where there is more than one way to do it. The hunt is on.

In the following examples, lindex is used as the identity command, i.e., a command that returns its argument, verbatim.

$varname ~~ set varname

Example:

set abc "123"
set xyz $abc

or

set xyz [set abc]

script ~~ eval {script}

Example:

[replace with example]

lindex "string" ~~ subst {string}

Example:

Using string can result in quoting hell for some strings while using subst is more verbose but "cleaner".

[replace with example]

"$list1 $list2 ... ~~ concat $list1 $list2 ...

Example:

set colors {taupe puce heliotrope}
set countries {Djibouti Brazil Azerbaijan}
set var "$colors $countries"
set var [concat $colors $countries]

lindex {a b c ...} ~~ list a b c ...

Example:

set var "1 2 3"
set var {1 2 3}
set var [list 1 2 3]

global varname ~~ ::varname

upvar #0 varname varname ~~ ::varname

Example:

set abc $::env(HOME)

or

global env
upvar #0 env env2
set abc $env(HOME)
set abc2 $env2(HOME)