Menu

#211 $object info self command

open
snit (13)
5
2005-09-07
2005-09-07
No

When an object inherits publically from another, it
would sometimes be useful to be able to determine the
object name from outside - this suggested instance
standard command would enable that, by returning (for
any object) its $self value.

I don't believe there's any other way to do this
introspectively.

Discussion

  • Will Duquette

    Will Duquette - 2005-09-08

    Logged In: YES
    user_id=372859

    Hmmm. I'm not sure what you mean by "an object inherits publically
    from another". Are you referring to the "component" statement's "-
    inherit" flag? Also, if I implemented an "info self" method, then if

    set a [$object info self]

    it should always be the case that "$a eq $object". Unless $object isn't
    fully qualified--but [namespace which] should help you there.

    There might, on the other hand, be some point to an "info selfns"
    method that returns the object's private namespace.

    If I'm missing the point entirely, please enlighten me!

     
  • Colin McCormack

    Colin McCormack - 2005-09-08

    Logged In: YES
    user_id=19214

    Consider:

    package require snit

    snit::type Y {
    }

    snit::type X {
    component Y -public y -inherit true

    constructor {
    install Y using Y %AUTO%
    }
    }

    X x;

    # I would like to know what object [x Y m] will be evaluated in.

    x Y ;# this could return the Y instance?
    x Y self ;# or this?
    x Y info self ;# or this?

    It came up when I wanted to return a handler object, and
    associate some information with the object, and then
    retrieve that information on handler completion by using
    [upvar self] as an implicit argument.

    I couldn't see a way to determine [x Y] easily. I've coded
    around it, so it's not a dire need, but it occurred to me as
    a possibly useful facility.

    Colin.

     
  • Will Duquette

    Will Duquette - 2005-09-09

    Logged In: YES
    user_id=372859

    OK, I see what you're after.

    In your example, "x y" can't return the Y object's name; I'm using
    [namespace ensemble] for the dispatch now, and [namespace ensemble]
    requires a subcommand.

    Yes, "info self" would give you what you want; and it would certainly
    be easy to do. I'll think about it.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.