@@ -24,6 +24,22 @@ of just one method called C<why>:
24
24
CATCH { default { put .^name, ': ', .Str } };
25
25
# OUTPUT: «X::Method::NotFound: Method 'list' not found for invocant of class 'why oh why?'»
26
26
27
+ Every metaobject has the capacity to hold a parameterization cache. This is
28
+ distinct from the C < parameterize > metamethod backing parameterization syntax.
29
+ For example, a package can be parametric in this low-level sense:
30
+
31
+ package Cache {
32
+ our sub parameterize(+args) is raw {
33
+ Metamodel::Primitives.parameterize_type: $?PACKAGE, args
34
+ }
35
+
36
+ sub noop(Mu, Mu \args) is raw {
37
+ args
38
+ }
39
+
40
+ BEGIN Metamodel::Primitives.set_parameterizer: $?PACKAGE, &noop;
41
+ }
42
+
27
43
= head1 Methods
28
44
29
45
= head2 method create_type
@@ -93,4 +109,44 @@ L<special arrangements|https://github.com/rakudo/rakudo/issues/3414#issuecomment
93
109
94
110
Type-checks C < obj > against C < type >
95
111
112
+ = head2 method set_parameterizer
113
+
114
+ method set_parameterizer(Mu \obj, ¶meterizer --> Nil)
115
+
116
+ Initializes the parameterization cache for a metaobject. This incorporates the
117
+ C < ¶meterize > routine to produce parameterizations to be cached. This is
118
+ assumed to carry a signature compatible with C < :(Mu $root, List:D $args) > ,
119
+ C < $root > being the base metaobject for the parameterization, C < $args > being the
120
+ type arguments' object buffer.
121
+
122
+ = head2 method parameterize_type
123
+
124
+ method parameterize_type(Mu \obj, +parameters --> Mu)
125
+
126
+ Parameterizes a metaobject prepared by C < set_parameterizer > with C < parameters > .
127
+ The resulting metaobject is cached by literal object comparisons with C < =:= >
128
+ for each element of C < parameters > . I < Containers tend to invalidate any match > .
129
+
130
+ = head2 method type_parameterized
131
+
132
+ method type_parameterized(Mu \obj --> Mu)
133
+
134
+ Returns the base metaobject from a parameterization given its resulting C < obj > .
135
+ Returns C < Mu > if none was ever performed.
136
+
137
+ = head2 method type_parameters
138
+
139
+ method type_parameters(Mu \obj --> List:D)
140
+
141
+ Returns the type arguments' object buffer from a parameterization given its
142
+ resulting C < obj > . Dies if none was ever performed.
143
+
144
+ = head2 method type_parameter_at
145
+
146
+ method type_parameter_at(Mu \obj, Int:D \idx --> Mu) is raw
147
+
148
+ Returns a particular object from a parameterization given its resulting C < obj >
149
+ and an index, skipping the C < List > -building step of C < type_parameters > . Dies if
150
+ none was ever performed.
151
+
96
152
= end pod
0 commit comments