TCL obtain the proc name in which I am

The correct idiomatic way to achieve what's implied in your question is to use return -code error $message like this:

proc nameOfTheProc {} {
    #a lot of code here
    return -code error "Wrong sequence of blorbs passed"
}

This way your procedure will behave exactly in a way stock Tcl commands do when they're not satisfied with what they've been called with: it would cause an error at the call site.


You can use the info level command for your issue:

proc nameOfTheProc {} {

    #a lot of code here
    puts "ERROR: You are using '[lindex [info level 0] 0]' proc wrongly"
    puts "INFO:  You specified the arguments: '[lrange [info level [info level]] 1 end]'"
}

With the inner info level you will get the level of the procedure call depth you are currently in. The outer one will return the name of the procedure itself.

Tags:

Proc

Tcl