Ulysses
Ulysses

Reputation: 6025

What is the significance of {*} when used with args like {*}args in tcl

What is the significance of {*} when used with args like {*}args? For instance: how is using the following in a class method

next a {*}$args b 

different from using

next a $args b

Upvotes: 1

Views: 1574

Answers (3)

Peter Lewerin
Peter Lewerin

Reputation: 13282

You can see the difference for yourself in the interactive shell by putting the command list in front of the invocation:

list next a {*}$args b 
list next a $args b

Set args to some value (preferably some list value), run the above, and you'll see what the invocation actually looks like.

Upvotes: 1

bipll
bipll

Reputation: 11940

{*} splices the element of a list as individual arguments, not the whole list as a single argument.

Upvotes: 0

slebetman
slebetman

Reputation: 114014

It's the argument/list expansion operator. It converts a list into many single words.

It's documented as part of the tcl syntax rules: http://www.tcl.tk/man/tcl/TclCmd/Tcl.htm. It is rule number 5.

For example, say you have a list:

set foo {a b c d}

and you call the command:

bar $foo

The command will be interpreted as:

bar "a b c d"

But if instead you do:

bar {*}$foo

Then the command will be interpreted as:

bar a b c d

Upvotes: 4

Related Questions