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 edit
Example: Given
set abc 123
The following command are equivalent
set xyz $abc
set xyz [set abc]
script ~~ eval {script} edit
See
Many ways to eval lindex "string" ~~ subst {string} edit
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 ... edit
Example:
#given
set colors {taupe puce heliotrope}
set countries {Djibouti Brazil Azerbaijan}
#equivalents
set var "$colors $countries"
set var [concat $colors $countries]
set var [list {*}$colors {*}$countries]
set var [string cat $colors { } $countries]
lindex {a b c ...} ~~ list a b c ... edit
Example:
set var "1 2 3"
set var {1 2 3}
set var 1\ 2\ 3
set var [list 1 2 3]
global varname ~~ ::varname edit
upvar #0 varname varname ~~ ::varnameExample:
set abc $::env(HOME)
or
global env
upvar #0 env env2
set abc $env(HOME)
set abc2 $env2(HOME)