ArmanHunanyan
ArmanHunanyan

Reputation: 1015

Implementing wrapper functions in Tcl

I want to wrap tcl interp command and do special handling for some options

My code looks like

rename ::interp ::interp_old
proc interp { args } {
    # my code
    # call interp_old with args
}

My question is how to call interp_old with $args. I have tried eval [concat interp_old $args], but it is not working in some cases when arguments are nested lists.

Upvotes: 1

Views: 278

Answers (1)

slebetman
slebetman

Reputation: 113896

In current versions of tcl you should be able to use the {*} (splat) operator:

interp_old {*}$args

In older versions that don't have the splat operator you can eval it carefully:

eval [linsert $args 0 interp_old]

We use list operations (linsert) to properly handle whitespace in args.

Upvotes: 4

Related Questions