is(n)

πŸ¦‹ NAME πŸ¦‹

itcl::is β€” bestie, this is the lil test that checks whether an argument is a class or an object. That's it, that's the whole job, and it does it flawlessly πŸ’…

(it lives in the [incr Tcl] manual, under the name is(n) β€” yes the section letter is part of the name, we don't make the rules πŸŽ€)


✨ SYNOPSIS ✨

itcl::is option ?arg arg ...?

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea πŸ“ β€” the is command checks whether the argument you hand it is a class or an object, and which one it checks for depends on the option you gave. If the argument is a class or an object, you get 1 back. If it's not, you get 0. No drama, no error, just a clean little boolean.

and ngl there's a bonus: the is command also recognizes the commands wrapped in the itcl code command 🧚 so those wrapped-up command names still get vibe-checked properly.

The option argument is what decides which action the command actually carries out. The legal options β€” and yes, they may be abbreviated, so you don't have to type the whole thing, queen πŸ‘‘ β€” are:

  • is class command β€” returns 1 if command is a class, and returns 0 otherwise. πŸŽ€
⚠️ heads up: you have to give the fully qualified name of the class as the command argument. So if a class lives in a namespace, the namespace has to be spelled out too. So if a class C resides in a namespace N, you call it like this:
is N::C
    or
is ::N::C
  • is object ?-class className? command β€” returns 1 if command is an object, and returns 0 otherwise. πŸ¦‹

If you pass the optional -class parameter, then command gets checked within the context of the class you named. But bestie, listen: className has to exist. If it doesn't, you get an error, periodt. So if you're not 100% sure className is actually a class, you gotta check its existence beforehand yourself, or wrap the whole thing in a catch statement. no cap 😭

So if c is an object in the class C, in namespace N, then these are the possibilities (and all of them return 1):

set obj [N::C c]
itcl::is object N::c
itcl::is object c
itcl::is object $obj
itcl::is object [itcl::code c]

🌈 KEYWORDS 🌈

  • class
  • object

and that's the whole page, bestie!! 🫢 this one came from itcl, version 3.3, and it's the is(n) page β€” go forth and vibe check your classes and objects responsibly πŸ’œβœ¨