Subroutine and Method Introspection

8 views
Skip to first unread message

Chromatic

unread,
Jul 21, 2005, 12:04:30 AM7/21/05
to perl6-l...@perl.org
A12 and S12 describe introspection on objects and classes. The
metaclass instance has the method getmethods() which returns "method
descriptors". The design specifies several traits queryable through
these descriptors.

Methods (and subroutines) can take other traits, such as "is lvalue" or
even user-defined traits. I can imagine that a Perl 6 port of
Test::Class would suggest using trats of "is startup" and "is
tests( 4 )" to replace the use of attributes in the Perl 5 version.

Currently, there's no way to query these traits through introspection,
nor is there a description of the descriptors beyond indicating that
they're some sort of object.

I have no strong feeling as to what type of object they should be, but
they ought to support some sort of traits() method to return a list of
names of all available traits on the method. Passing the name of a
trait to the method ought to return the value of the trait, if it is a
parametrized trait. Otherwise, it could return boolean.

Perhaps there's a more general mechanims that works better in specific
cases. Ruby's Class#method? syntax is nice, but being able to hardcode
a method name and pass a string parameter makes introspection a little
more automable.

Having the class for these descriptors be available and extensible also
makes it possible to write a method that returns only the *interesting*
traits, which might be convenient.

Thoughts?

-- c

Sam Vilain

unread,
Jul 24, 2005, 3:45:48 AM7/24/05
to chromatic, perl6-l...@perl.org
chromatic wrote:
> A12 and S12 describe introspection on objects and classes. The
> metaclass instance has the method getmethods() which returns "method
> descriptors". The design specifies several traits queryable through
> these descriptors.
[...]

> Currently, there's no way to query these traits through introspection,
> nor is there a description of the descriptors beyond indicating that
> they're some sort of object.
> I have no strong feeling as to what type of object they should be, but
> they ought to support some sort of traits() method to return a list of
[...]

Well, arguably Stevan's perl5/Perl6-MetaModel is the best place to
prototype such interfaces.

Getting traits requires deeper introspection. You need to ask the
Meta-Objects themselves what properties they support. In other words,
by looking at .meta.meta you should be able to see this. Even though
we're aiming to avoid the Smalltalk '72 problem[1] of
meta-meta-meta-meta-model madness. There is some early rantings of it
in modules/Perl-MetaModel/docs/perl6_meta_model.pod

Quite how far the "turtles all the way down" principle works will be an
interesting test of the design, I think. I wouldn't expect making
changes to .meta objects 3-4 levels deep to work, and that they should
be like a "reciprocal" (or a metaclass that can be its own metaclass).

Sam.

1. Piers Cawley drew the prior art connection here. I forget the exact
years, but there were two Smalltalk language versions, the first where
each meta-model layer was independant, and the second where they had
figured out how to make the system close back on itself simpler. Maybe
someone can give a better description than this.

Reply all
Reply to author
Forward
0 new messages