Rules / Types, classes & roles / uncategorised

Metamodel::TypePretense Reference

Metarole for type pretenses

What it is #

Position in the hierarchy #

Routines #

Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.

method pretend_to_be #

method pretend_to_be(@types)

Makes all types for a type of HOW pretend to be any of the type objects in @types.

method pretending_to_be #

method pretending_to_be()

Returns the type objects this type of HOW is pretending to be.

method type_check #

method type_check($obj, $checkee)

If $checkee is the same object as $obj or is of any of the types $obj is pretending to be, returns 1, otherwise returns 0.

Examples, run three ways #

Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.

1 all-differ · 1 no-output · 1 rakupp-differs

role Metamodel::TypePretense { }

Not executed: the documentation states no expected output for this example.

class Class { }
role  Role  { }

say Role ~~ Mu;   # OUTPUT: «True␤»
say Role ~~ Any;  # OUTPUT: «True␤»
say Role ~~ Cool; # OUTPUT: «True␤»

say Class.^parents(:all).map(*.^name);     # OUTPUT: «(Any Mu)␤»
say Role.^pun.^parents(:all).map(*.^name); # OUTPUT: «()␤»
Documentation
True
True
True
(Any Mu)
()
Rakudo
True
True
True
(Any Mu)
(Any Mu)
Raku++
True
True
True
(Any)

All three differ. Needs a human.

Not yet examined. Which of these is correct has not been established — do not treat either engine as settled here.

say Role.HOW.pretending_to_be.map(*.^name); # OUTPUT: «(Cool Any Mu)»
Documentation
(Cool Any Mu)
Rakudo
(Cool Any Mu)
Raku++

Raku++ disagrees with both the documentation and Rakudo — a defect.