Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you get the "proc name" inside a proc?

Tags:

tcl

Within a proc can you get the proc name (without hardcoding it)? e.g.

proc my_proc { some_arg } {
    puts "entering proc [some way of getting proc name]"
}
like image 909
Scooter Avatar asked Dec 21 '22 13:12

Scooter


1 Answers

Of course you can!

Use info level command:

proc my_proc { some_arg } {
    puts "entering proc [lindex [info level 0] 0]"
}

and you get exactly what you want

entering proc my_proc

Another way is to use info frame, which gives a dictionary with some other info, and read the proc key:

proc my_proc { some_arg } {
    puts "entering proc [dict get [info frame 0] proc]"
}

this time, you'll get the fully qualified proc name:

entering proc ::my_proc
like image 92
Marco Pallante Avatar answered Feb 05 '23 12:02

Marco Pallante