Version 10 of Hunt for Tcl Extensional Equivalents

Updated 2011-08-08 02:59:58 by jbr

CMcC 8/7/7 Tcl contains some semantic equivalences. ~~ can be read as approximates. Add more if you find them. The hunt is on.


  • $varname ~~ [set varname]

Example:

        set abc "123"
        set xyz $abc

or

        set xyz [set abc]

  • [script] ~~ [eval {script}]

Example:

[replace with example]


  • "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]

  • "a b c ..." ~~ [list a b c ...]
  • {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)

escargo 7/7/7 - Are you looking for examples how these are not equivalent? CMcC I changed it to 'approximates.'

For example, I seem to recall that [eval] does a round of substitution before evaluating its input. (Logically, it would seem to be necessary for [] !~ [eval], otherwise eval is just taking up space.)

And subst takes arguments that allow limitations on the substitutions.

LV I think what is being sought are cases where there is more than one way to do it, as the Perl community says. This could be cases of Tcl syntactical sugar (notational shortcut approximates).