Tutorial by Examples

proc myproc {} { puts "hi" } myproc # => hi An empty argument list (the second argument after the procedure name, "myproc") means that the procedure will not accept arguments.
proc myproc {alpha beta} { ... set foo $alpha set beta $bar ;# note: possibly useless invocation } myproc 12 34 ;# alpha will be 12, beta will be 34 If the argument list consists of words, those will be the names of local variables in the procedure, and their initi...
### Definition proc myproc {alpha {beta {}} {gamma green}} { puts [list $alpha $beta $gamma] } ### Use myproc A # => A {} green myproc A B # => A B green myproc A B C # => A B C This procedure accepts one, two, or three arguments: those parameters whose names are the fi...
proc myproc args { ... } proc myproc {args} { ... } ;# equivalent If the special parameter name args is the last item in the argument list, it receives a list of all arguments at that point in the command line. If there are none, the list is empty. There can be arguments, including optional one...
proc myproc {varName alpha beta} { upvar 1 $varName var set var [expr {$var * $alpha + $beta}] } set foo 1 myproc foo 10 5 puts $foo # => 15 In this particular case, the procedure is given the name of a variable in the current scope. Inside a Tcl procedure, such variables aren't...
Sometimes what you have is a list, but the command you want to pass the items in the list to demands to get each item as a separate argument. For instance: the winfo children command returns a list of windows, but the destroy command will only take a sequence of window name arguments. set alpha [wi...

Page 1 of 1