View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] info subclass

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Sun, 25 Apr 2010 10:15:50 +0200

Dear Kristorffer
Am 24.04.10 17:42, schrieb Kristoffer Lawson:
> In my 1.2 version of XOTcl (OSX) [info subclass] works in the
> following way:
>
> Class Foo
>
> Class Bar -superclass Foo
>
> Foo info class Bar
> => 1
>
[Foo info class] returns "::xotcl::Class", your probably meant "... info
subclass ...."
> However the current documentation says the parameter given is a
> pattern and the fully qualified name is returned, or empty if no match
> was found. Has this changed at some point? This would be quite an
> incompatible change.
>
This was changed more than 2 years ago (see changelog). The main reason is
consistency (with Tcl and other XOTcl info commands).

XOTcl has many introspection commands returning potentially a set,
similar to e.g. "info vars" in tcl:

     cls|Object info SUBCMD ?options? ?pattern? => answer-set

If the answer-set is non-empty, "pattern" (a glob style pattern) can
be used to restrict the answer-set, e.g. [info vars *o*]

For the definitions

    Class Foo
    Class Bar -superclass Foo
    Class Baz -superclass Foo

the command [Foo info subclass] returns "::Baz ::Bar", therefore
the pattern acts here as well as for other Tcl commands and for
the other 20 info options of XOTcl which accept the optional
pattern argument, such as

    children classchildren commands forward heritage
    instances instcommands instforward instmixin
    instmixinof instparametercmd instprocs mixin
    mixinof parametercmd procs precedence
    subclass superclass vars

The change was made in connection with the transitive
option "-closure", such one can use as well e.g.

    Object info subclass -closure

to obtain subclasses and their subclasses. The change
is documented in the Changelog.
> I actually prefer how it works on my installation. I want to
> explicitly check if one class is a subclass of another, as objects,
> not as patterns (patterns can be risky). And it's not actually clear
> what is meant by 'pattern'.
It is not "risky" as long "pattern" does not contain glob characters
(same as in Tcl).
> Foo is a class, Bar is a class, but Foo's
> actual fully qualified name is ::Foo, so if I wanted an exact search
> it should be against ::Foo, but will it also match 'Foo' (as desired)?
>
>
yes. both commands

      Foo info subclass Bar
      Foo info subclass ::Bar

return "::Bar"

Best regards

-gustaf neumann