HaloO,
John M. Dlugosz wrote:
OK, what is the proper use of ::?CLASS ? Say in a role you want to
take an argument of the same class as the final class, or explicitly
declare $self. S12 gives an example:
method doit (::?CLASS $self: $a, $b, $c) { ... }
but this CONTRADICTS the idea that using the :: sigil in a
declaration declares a generic type. And you can't spell ?CLASS
without the sigil because you never have a twigil without a sigil and
?CLASS is not a legal identifier.
Sorry, I see no contradiction. Method doit *is* a parametric type.
That is you need a type argument to make a code type. And then
you need args to make an invocation. Now the question is who provides
the type argument and when. An explicit instanciation would read
doit[Int] 3: 3,2,1;
but the compiler might also infer this. Note that this has the
surprising effect of inserting doit into the HOW of the runtime
invocant. Question is how long this persists and what errors can
occur when the attempt is made. This is what I call a free method
and the Perl 6 grammar might actually forbid method definitions
outside of class bodies.
The usual circumstance of instanciating doit is in class composition
role R
{
method doit (::?CLASS $self: $a, $b, $c) { ... }
}
class A does R
{
# this is generated by the compiler
method doit (A $self: $a, $b, $c) {...}
}
That is all methods in a role are parametric on ::?CLASS just
as all methods in a class are parametric on ::?SELF
class B is A;
instanciates a new type &doit:(B $self: $a, $b, $c). This nicely
avoids the problem of schizophrenic self reference. And of course
you need only one body for doit somewhere in R. But doit[int32] could
get a specialized body.
The meaning of $?CLASS is never explained. Just a cryptic line in
S02 "what class am I in (as variable)". Is the same Type object
accessible as the value of the item with the $ sigil? Why is this
necessary? I wonder if it has something to do with problems using
the :: sigil that I'm musing with.
Hmm, let's try that with a metaphor. ::?USA refers to the abstract
concept of the nation as a whole. $?USA refers to an individual
representing that nation. Currently this is Bush. So e.g. a treaty
between ::?USA and ::?GERMANY is negotiated by $?USA and $?GERMANY.
These are obviously individuals. If you had two delegations at work
these would be @?USA and @?GERMANY. I really love the linguistic power
of Perl 6 :)
Regards, TSa.
--
"The unavoidable price of reliability is simplicity"
-- C.A.R. Hoare