Skip to content

Commit

Permalink
More meta( |-) eliminated refs #3024
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Sep 15, 2019
1 parent 9407baa commit e7942a0
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions doc/Language/objects.pod6
Expand Up @@ -552,7 +552,7 @@ provide that method, the method of that name in one of the parent classes is
invoked instead, if it exists. The order in which parent classes are
consulted is called the I<method resolution order> (MRO). Perl 6 uses the
L<C3 method resolution order|https://en.wikipedia.org/wiki/C3_linearization>.
You can ask a type for its MRO through a call to its meta class:
You can ask a type for its MRO through a call to its metaclass:
=for code
say List.^mro; # ((List) (Cool) (Any) (Mu))
Expand Down Expand Up @@ -933,7 +933,7 @@ then C<X::Ouch> will inherit directly from Exception, as we can see above
by listing its parents.
As they do not use what can properly be called inheritance, roles are not part
of the class hierarchy. Roles are listed with the C<.^roles> meta-method
of the class hierarchy. Roles are listed with the C<.^roles> metamethod
instead, which uses C<transitive> as flag for including all levels or just the
first one. Despite this, a class or instance may still be tested with
smartmatches or type constraints to see if it does a role.
Expand Down Expand Up @@ -1003,7 +1003,7 @@ say Point.dimensions; # OUTPUT «2␤»
We call this automatic creation of classes I<punning>, and the generated class
a I<pun>.
Punning is not caused by most L<meta-programming|/language/mop> constructs,
Punning is not caused by most L<metaprogramming|/language/mop> constructs,
however, as those are sometimes used to work directly with roles.
X<|Parameterized Roles>
Expand Down Expand Up @@ -1137,35 +1137,33 @@ say %seen<not-there>.defined; # OUTPUT: «True␤» (0 may be False but is well
say Int.new(%seen<not-there>); # OUTPUT: «0␤»
=end code
=head1 Meta-object programming and introspection
=head1 Metaobject programming and introspection
Perl 6 has a meta object system, which means that the behavior of objects,
Perl 6 has a metaobject system, which means that the behavior of objects,
classes, roles, grammars, enums, etc. are themselves controlled by other
objects; those objects are called I<meta objects>. Meta objects are, like
ordinary objects, instances of classes, in this case we call them I<meta
classes>.
objects; those objects are called I<metaobjects>. Metaobjects are, like
ordinary objects, instances of classes, in this case we call them I<metaclasses>.
For each object or class you can get the meta object by calling C<.HOW> on it.
For each object or class you can get the metaobject by calling C<.HOW> on it.
Note that although this looks like a method call, it works more like a macro.
So, what can you do with the meta object? For one you can check if two
objects have the same meta class by comparing them for equality:
So, what can you do with the metaobject? For one you can check if two
objects have the same metaclass by comparing them for equality:
=begin code
say 1.HOW === 2.HOW; # OUTPUT: «True␤»
say 1.HOW === Int.HOW; # OUTPUT: «True␤»
say 1.HOW === Num.HOW; # OUTPUT: «False␤»
=end code
Perl 6 uses the word I<HOW> (Higher Order Workings) to refer to the meta
object system. Thus it should be no surprise that in Rakudo, the class name
of the meta class that controls class behavior is called
C<Perl6::Metamodel::ClassHOW>. For each class there is one instance of
C<Perl6::Metamodel::ClassHOW>.
Perl 6 uses the word I<HOW> (Higher Order Workings) to refer to the metaobject
system. Thus it should be no surprise that in Rakudo, the class name of the
metaclass that controls class behavior is called C<Perl6::Metamodel::ClassHOW>.
For each class there is one instance of C<Perl6::Metamodel::ClassHOW>.
But of course the meta model does much more for you. For example, it allows
But of course the metamodel does much more for you. For example, it allows
you to introspect objects and classes. The calling convention for methods on
meta objects is to call the method on the meta object and pass in the object
metaobjects is to call the method on the metaobject and pass in the object
of interest as first argument to the object. So to get the name of the class
of an object, you could write:
Expand All @@ -1179,7 +1177,7 @@ say 1.HOW.name(1); # OUTPUT: «Int␤»
=end code
(The motivation is that Perl 6 also wants to allow a more prototype-based
object system, where it's not necessary to create a new meta object for
object system, where it's not necessary to create a new metaobject for
every type).
There's a shortcut to keep from using the same object twice:
Expand All @@ -1190,9 +1188,9 @@ say 1.^name; # OUTPUT: «Int␤»
say 1.HOW.name(1); # OUTPUT: «Int␤»
=end code
See L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW> for documentation on
the meta class of C<class> and also the L<general documentation on the meta
object protocol|/language/mop>.
See L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW> for documentation on the
metaclass of C<class> and also the L<general documentation on the metaobject
protocol|/language/mop>.
=end pod

Expand Down

0 comments on commit e7942a0

Please sign in to comment.