0
votes

I wrote the following code in itcl

if {[info exists ::xtg::triggers::match$arg]} {
    eval delete object ::xtg::triggers::match$arg 
}

this code should check if there exists an object of name ::xtg::triggers::match$arg and delete it if it exists. The problem is that I get the following error in my shell : " command "match0" already exists in namespace "::xtg::Triggers" " and not 1 or 0 as written in the manual of info exists command.

How can I fix this problem?

1

1 Answers

1
votes

info exists checks for existing variables, not commands (incl. object commands).

Try:

if {[info commands ::xtg::triggers::match$arg] ne ""} {
     # ...
}

You might also want to consider Itcl's info objects:

if {::xtg::triggers::match$arg in [info objects]} {
     # ...
}

or

if {[info objects ::xtg::triggers::match$arg] ne ""} {
     # ...
}

(assuming that you call [info objects] for the correct namespace scope)