How to use a variable as the default value of a TCL argument

advertisements

I've got a variable that I would like to use as default value for an argument:

proc log {message {output $::output}} {
   ....
}

Is there a way to do this or need I to evaluate the variable inside my proc?


Yes, but you cannot use curly braces ({}) for your argument list. You declare the procedure e.g. this way:

proc log [list message [list output $::output]] {
   ....
}

But be aware:
The variable is evaluated at the time when the procedure is declared, not when it is executed!