Hunt for Tcl Extensional Equivalents

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: Given

set abc 123

The following command are equivalent

set xyz $abc
set xyz [set abc]

script ~~ eval {script}

See Many ways to eval

lindex "string" ~~ subst {string}


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 ...


set colors {taupe puce heliotrope}
set countries {Djibouti Brazil Azerbaijan}

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 ...


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

global varname ~~ ::varname

upvar #0 varname varname ~~ ::varname


set abc $::env(HOME)


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