I know how this can be done in P5. Using the layout "Hash" things are easy. How can P6 deal with this, without allocating too much memory to things that'd never get used? The layout "P6Hash" could come to the rescue, but there is still the issue of syntax:
what exactly does C<has $.bisector1> do? IIRC, in the P6Opaque layout, every instance of the class would have space the size of a PMC allocated for it. This behavior is not needed for P6Hash, and it should just leave attributes alone until they are assigned to (where defaults are also "assigns").
In which case, maybe for that layout we can get away without declaring all attributes, perhaps? (Since the declaration does nothing except help the parser).
I was thinking whether we could do something like this:
class Triangle is layout<P6Hash> does autovivify{ method calculate_bisectors { $.bisector1 = ...; # $.bisector1 autovivifies } }
where it is an error without the autovivify, and only P6Hash supports autovivification.
--abhijit