Dynamically though? The attraction of ECS is that your house can start and stop being a boat as needed.
https://metacpan.org/dist/Moose/source/lib/Moose/Meta/Role/A...
https://github.com/rakudo/rakudo/blob/master/src/Perl6/Metam...
Reading the source codes, I think this is due to no one yet having requested the ability to do so. To me it feels like implementing this is possible, but tedious.
The simple work-around for the problem would be to rebless the instance. Example:
class Structure {}
role Floatable {}
role Inhabitable {}
class Houseboat extends Structure with Floatable with Inhabitable {}
$hb = Houseboat new
$s = Structure new
$s apply Floatable, Inhabitable # houseboat at run-time
# stop swimming
### NYI
### $s unapply Floatable
# make a new house that cannot swim
$s1 = Structure new
$s1 apply Inhabitable
$s1 = $s rebless_into $s1In Raku speak:
my $house = House.new;
my $houseboat = $house but Boat;
See: https://docs.raku.org/routine/butThere would be no need to de-compose.
var id = ecs.createEntity() // returns an int
ecs.addComponent(id, 'house')
ecs.addComponent(id, 'boat')
So, very different from the class-based approach being floated a few comments ago. Does that answer your question?Instead one can use `does` to mix in to an existing entity:
role House {}
role Boat {}
my \id = 42;
id does House;
id does Boat;
say id ~~ House; # True
(What's missing is the ability to drop a mixin once it's been added via `does`.)