Tcl question: expansion of variable names

Gustaf Neumann neumann at wu.ac.at
Tue Sep 4 19:45:50 UTC 2018


On 04.09.18 15:53, Ryan Schmidt wrote:
> I've never been quite clear on the benefits of using [list] vs just making a string, since a string is a list, and I seem to use them interchangeably.

in case the interpolated variables have values that have no Tcl meaning, 
one can use

    set a 10
    set b 20
    set l1 "$a $b"
    set l2 [list $a $b]

and get the same result from double quotes and [list], when e.g. using 
list operations like

    puts [lindex $l1 1]
    puts [lindex $l2 1]

however, when e.g. variable "a" has a value like "1 2" the output will 
differ,
since l1 consists now of three blank separates values,
where l2 keeps the the value a regardless of its contents a properly braced
as first element of the list. Same happens, when "a" is e.g. empty, etc.




More information about the macports-dev mailing list