Given a simple tcl proc like
proc foo {a b} {puts "$a $b"}
What tcl command can I use to print out the procedure foo
... that is I want the text of the proc back ...
For instance:
% proc foo {a b} {puts "$a $b"}
% foo a b
a b
% puts $foo
can't read "foo": no such variable
how do I get foo {a b} {puts "$a $b"}
back?
% proc foo {a b} {puts "$a $b"} % info body foo puts "$a $b" % info args foo a b
For more goodies, reread info(n).
@Henry, it's a bit more complicated than that if any arguments have default values:
proc foo {a {b bar}} {
puts "$a $b"
}
proc info:wholeproc procname {
set result [list proc $procname]
set args {}
foreach arg [info args $procname] {
if {[info default $procname $arg value]} {
lappend args [list $arg $value]
} else {
lappend args $arg
}
}
lappend result [list $args]
lappend result [list [info body $procname]]
return [join $result]
}
info:wholeproc foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With