Passing list to Tcl procedure

前端 未结 3 785
日久生厌
日久生厌 2021-02-13 02:56

What is the canonical way to pass a list to a Tcl procedure?

I\'d really like it if I could get it so that a list is automatically expanded into a variable number of arg

3条回答
  •  暖寄归人
    2021-02-13 02:58

    It depends on the version of Tcl you're using, but: For 8.5:

    set mylist {a b c}
    myprocedure option1 option2 {*}$mylist
    

    For 8.4 and below:

    set mylist {a b c}
    eval myprocedure option1 option2 $mylist
    # or, if option1 and 2 are variables
    eval myprocedure [list $option1] [list $option2] $mylist
    # or, as Bryan prefers
    eval myprocedure \$option1 \$option2 $mylist
    

提交回复
热议问题