My solution was to create a Type() method that generates the class' name followed by the names of the superclasses. FFI, please see
http://eudyptula.freezope.org/uunit/uunit.icn.html
from which this snippet is snipped:

method Type(
# Produces the name of the class and its superclasses
)
# Since there is little (if any) reason not to subclass TestCase, # generate its name after generating name of subclass.
every suspend ( type(self) ? tab(upto('_')\1) ) | "TestCase" | "Test"
end



Steve Wampler wrote:

Is there a way in Unicon to determine the inheritance chain of a
class instance at runtime. For example, suppose I have something
like:

class A ()
method callback()
...
end

class B : A ()
end

procedure main()
a := B()
f(a)
end


# Is there someway to write something like:

procedure f(a)
if instanceof(B, a) then a.callback()
end

Actually, it might be nice if there were some 'default' methods
declared on classes - with instanceof() being one of them,
so that the above procedure f() could be written as:

procedure f(a)
B.instanceof(a).callback()
end

B.instanceof(a) would just fail if B isn't in the inheritance chain for
the class instance in a, and [because it seems useful] produce that
class instance from a otherwise.

Note that in this case, instanceof() is a method defined on the
class instead of the class instance - I don't know of any methods
defined this way currently in Icon, and so it might be, uh,
"interesting" to implement...

[I'm *not* interested in digging through the record implementation of
a class to figure the inheritance chain - I'd like to see this a
something provided by Unicon without requiring the user to understand
how classes are implemented!]




-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to