Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Best Solution: Expansion Substitution</h2> <p>The right approach is to ensure that the outer procedure (in stack terms) calls the inner one correctly; if multiple arguments are expected, that's what should be supplied. With the advent of Tcl 8.5, that's trivially done with a little language syntax called an <strong><em>expansion substitution</em></strong>:</p> <pre><code>proc abc1 {args} { puts "$args" array set arg $args set l2 [array get arg] abc {*}$l2 # Or combine the two lines above into: abc {*}[array get arg] } </code></pre> <p>All the <a href="http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M9" rel="noreferrer"><code>{*}</code></a> does is say that the rest of the word should be broken up (using list syntax rules) and used as multiple arguments instead of Tcl's default “one visual word forms a single word” rules. It's <em>ideal</em> for this.</p> <h2>Old Solution: Eval Command</h2> <p>If you're still using old versions of Tcl for some reason (i.e., Tcl 8.4 or before) then you use the <code>eval</code> command instead of the above syntax:</p> <pre><code>eval abc $l2 </code></pre> <p>There are some somewhat-more-efficient approaches to the above <code>eval</code>, which you might see in older code; for example:</p> <pre><code>eval [linsert $l2 0 abc] eval [list abc] [lrange $l2 0 end] # ... etc ... </code></pre> <p>But really they're all rendered obsolete by <code>abc {*}$l2</code> which is shorter, simpler to write, and faster. (It's just not available in 8.4 or before, and too many deployments have yet to upgrade.) <em>Use the expansion syntax if you can.</em> Indeed, idiomatic Tcl code for 8.5 and later hardly ever needs <code>eval</code>; the extent to which this has proved true has even been rather surprising to the language's maintainers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload