What does {*} do in TCL?

前端 未结 3 1608
梦如初夏
梦如初夏 2020-12-06 12:24

I have used some TCL, but this construction stumps me.

When $res = \"Table does not exist\", what will the following return?

[list [list {*}$res]]
         


        
3条回答
  •  不知归路
    2020-12-06 12:39

    Yeah I always find that construction troublesome too. It used be called expand and then they cleverly renamed it to {*} (very memorable!). Anyway I've seen it used to expand a list to make the list contents available.

    See this example for an idea of how it works:

    % set c [list a b]
    a b
    % set d [list e f]
    e f
    % set x [list $c {*}$d]
    {a b} e f
    % set y [lindex $x 2]
    f
    % set y [lindex $x 1]
    e
    % set y [lindex $x 0]
    a b
    

提交回复
热议问题