Can you get the name "proc" inside proc?

Inside proc, can you get the name proc (without hard coding)? eg.

proc my_proc { some_arg } { puts "entering proc [some way of getting proc name]" } 
+4
source share
1 answer

Of course you can!

Use the 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 the info frame , which gives a dictionary with some other information and reads the proc key:

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

this time you get the full name of proc:

 entering proc ::my_proc 
+10
source

Source: https://habr.com/ru/post/1444797/


All Articles