5

There does not seem to be a way to use new_type in MetamodelConcreteRoleHOW, which as its name implies should be used to create new instances of a Role. The main problem is when you try to mix-in new roles, as implied by the signature ( method new_type(:@roles, :$name = '<anon>', :$ver, :$auth, :$repr, :$api)):

my $a = Metamodel::ConcreteRoleHOW.new_type(name => "Bar", roles => [Iterable]);
$a.^compose;
say $a.^roles;
# Error: «Cannot iterate object with P6opaque representation (Array)␤

Using another Positional, a list, yields a different error:

my $a = Metamodel::ConcreteRoleHOW.new_type(name => "Bar", roles => (Iterable));
$a.^compose;
say $a.^roles
# « Cannot iterate over a Iterable type object␤»

Beats me what kind of positional could I use there. To be sure, this is implemented in NQP, so maybe I should be defining an NQP array. But I really have no idea. Any help will be appreciated.

Edit. First, the error happens when you call compose. Second, you effectively have to use an NQP array as Raiph says

use nqp;
my $roles := nqp::list(Iterable);
my $a = Metamodel::ConcreteRoleHOW.new_type(name => "Bar", roles => $roles);
$a.^compose;
say $a.^is_composed();
say $a.^roles # OUTPUT: «1␤(Mu)␤»

compose works now, and it is actually composed, but the roles composed still show only the ur-role, Mu, not Iterable which is the one that should have been added to it. Any idea?

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • See also [How to add an attribute to an object using the meta-object protocol?](https://stackoverflow.com/q/51920051/2173773) – Håkon Hægland Apr 12 '19 at 20:16
  • 2
    "To be sure, this is implemented in NQP, so maybe I should be defining an NQP array." That's what I'd expect. I imagine you know this already (and may have written the following doc sentence) but it's also worth noting, for other readers, that the P6 doc says that `Metamodel::ConcreteRoleHOW` "is Rakudo specific, and ... Not really intended to be used by the final user." – raiph Apr 13 '19 at 01:11
  • @raiph indeed I did, but all that part is not documented, there's an issue that requests for it to be addressed, and it's simply coherent to add it together with the equivalent for classes. The problem also with Rakudo specific classes is that they are simply not documented, thus not available to the regular user. So they have to be documented somewhere... – jjmerelo Apr 13 '19 at 06:13

0 Answers0