Search code examples
error-handlingsyntax-errorruntime-errortcl

Using Tcl info procs return value


given that not_there isn't a proc I would expect

[info procs not_there] eq ""

to return 0, but I'm seeing

empty command name ""

could someone explain my conceptual error?


Solution

  • This statement of yours:

    [info procs not_there] eq ""
    

    will first have info procs not_there evaluated by the Tcl interpreter. Next the interpreter will evaluate the equivalent of this statement:

    "" eq ""
    

    ...where the first word "" is not a valid command.

    In the Tcl statements, the first word must always be a command. command arg arg arg...

    What you're missing is using the expr command at the beginning

    expr {"" eq ""}                       --> 1
    expr {[info procs not_there] eq ""}   --> 1
    

    By the way, the expr is implied in the conditional argument of the if statement:

    if {[info procs not_there] eq ""} {
         puts "This is not a proc"
    }