I have used some TCL, but this construction stumps me.
When $res = “Table does not exist”, what will the following return?
[list [list {*}$res]]
I know what [list [list $res]] would do, but the extra {*} just baffles me.
Thanks for helping.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, first know that
[list {*}…]is a construct that returns a list of the words in the ellipsis (the contents of theresvariable in your case). It happens that in your case, the net effect is nothing as the input string is actually also a well-formed list. That then becomes a single argument to the outerlistand so we get a single-element list as result, whose element contains a list of the wordsTable,does,notandexistin that order, i.e.,{Table does not exist}.Notes on expansion
The list of expanded word form is useful for doing concatenation of lists; the
concatcommand does something similar (but not identical; there are some historical weirdnesses involved in theconcatcommand). Thus, you’d concatenate two lists like this:Also note that expansion (introduced in Tcl 8.5) is true syntax, which is a very unusual thing in Tcl. The
{*}changes the nature of the following substitution so that it yields multiple words instead of just one. While it is possible to do without it, it’s actually remarkably difficult to get right. For example, without it the above would be:The introduction of expansion has greatly reduced the number of calls to
evalrequired in most Tcl code (a benefit since it was hard to write properly; a lot of programmers were caught out by the difficulty). This has proved particularly beneficial in practice with theexeccommand; it makes working withglobandauto_execokmuch easier:Ugh. That last one was a bit brain-bending to write out in non-expansion form even though I know what I’m doing. (The wrong version is wrong because it falls apart if
$arg1contains Tcl meta-characters…)