Updated 2011-07-08 08:18:33 by dkf

AMG: This page is of historical interest only. The argument expansion syntax has been decided to be {*} immediately followed by the word to be expanded, with no intervening whitespace.


TIP #144 Argument Expansion Syntax [1] (and the earlier TIP #103 Argument Expansion Command [2]) proposes to add syntax to Tcl to perform argument expansion in a safe and efficient manner.

For example, instead of having to write:
 eval [linsert $args 0 exec $program]

The TIP would allow one to say:
 exec $program {}$args

where the leading {} indicates that the remainder of the word shall be parsed as a list (after applying the usual substitution rules), and each element of the list is passed as a separate argument to the command.

Naturally, there has been a great deal of discussion about what syntax should be used to indicate argument expansion. The two most popular options seem to be {} and ` (backquote).

The main advantage of the {} syntax is that it can be added to Tcl 8.5 without breaking backwards-compatibility, as such usage is currently a syntax error. Any other option would have to wait until Tcl 9.0.

A similar poll was conducted on the tcl-core mailing list. The result is on the Argument Expansion Poll Summary page.


The purpose of this poll is to get a feel for the Tcl community's preferences regarding the proposed syntaxes. The poll is in two parts: the first asks which syntax would be preferable if backwards compatibility were not an issue. The second asks if the backwards-compatible syntax would be acceptable if it meant the feature could be introduced earlier.

Please vote by signing your name or initials after the proposed option.

Discussion moved to DISCUSSION: Argument Expansion Syntax

Part 1: which syntax do you prefer?

Option 1: leading {}: Vince, RS, Roy Terry, Jeffrey Hobbs, EB, Andreas Leitgeb, JMN

Option 2: leading `: Joe English, ramsan, SO, US, MC, NEM, Heiner Marxen, FW, Philipp Roessler

Option 3: other (please specify):

  eval arg1 arg2 arg3 arg4 arg5    ; same as before - expands all args
  eval -only { arg4 }              ; expands arg 4
  eval -only { arg1 to arg3 }      ; expand arg 1 to arg3
  eval -- -only arg2               ; -- turns off switch processing, -only just another arg to expand

  • Just use a postfix * As in cmd $*var or [*cmd] , has small impact on backwards compatibility. This syntax places expansion back at the parser backend where it has already detected special chars of either $ or [. PWQ MSW (although I prefer ruby's *[cmd] or *$var) Brent Welch

Option 4: neither: marc, THIRION, lv (as long as it truly can be provided as a command) George Peter Staplin, Jacob Levy: (It has proven to be simple enough to implement expand in pure Tcl. Therefore I feel that neither is worthy of the trouble.), Bradipo

Option 5: anything, just give me the functionality: KPV, Andreas Leitgeb, schlenk

Option 5a: anything that gives the functionality but which isn't too ugly and which won't be too typo-inclined: DKF, rmax, ulis

Part 2: Is {} acceptable for Tcl 8.5?

Yes, {} is acceptable: DGP, Vince, Daniel Steffen, RS, KBK, Peter Spjuth, Roy Terry, EB, Andreas Leitgeb, DKF (if we must), NEM, Heiner Marxen, JMN, Lars H

Yes, ` is acceptable (never mind the slight chance of breakage): US, DKF (if we can stand that much subtle incompatability)

Yes, [expand] is acceptable, and it is also back-portable to older Tcl versions (noone yet came up with a convincing argument that required additional syntax and was not doable with a command): Jacob Levy, Steve Redler IV, TP, PT, Joe Mistachkin, JBR, TFW

Yes, -only is acceptable: Larry Smith

Yes, anything is acceptable: KPV, ulis MSW

No, wait until Tcl 9 to add the feature: Joe English, marc, THIRION, SO, Setok, schlenk, Scott Gargash, MC, rmax, davidw, Salvatore Sanfilippo, FW, Philipp Roessler

Not if this functionality can be achieved in some other manner: lv, Jacob Levy, Joe Mistachkin (seems it can be implemented as a command)

PWQ How?, how does a command echive this:

.widget configure [*array get myoptions]

If you oppose the new syntax, then propose that all commands that now take a list of args are changed to also take a arglist (like canvas coords can do).

No, we do not need this functionality: ---

Just skip Tcl version 8.5 and release v9 as next version: ramsan I'm cool w/this, too. Larry Smith Setok

Skipping Tcl 8.5 would be a horrible thing to do: Joe Mistachkin

If a new syntax rule is added in 8.5, it should be permanent. No new different rule for 9.0 Clif Flynt, FW, Philipp Roessler, US

FW adds: I prefer @ to ` or {} FW

DKF notes that @ cannot be used as it clashes badly with existing code (especially many things in Tk.)