You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Delegating array behaviour to an attribute is a common pattern.
class Foo {
has @!interal handles <AT-POS EXISTS-POS elems end iterator>
}
But the above is easy to get wrong. And is wrong. It doesn't work for [*-1]
like access because internally rakudo is using .cache.elems.
'class Foo does Positional { has $.val handles <AT-POS EXISTS-POS elems end
iterator>; }; my $f = Foo.new(val => [5,6]); say $f[1], $f[*-1]' # 5,6
(should be 6,6)
This RT is to suggest that there should be some way to say delegate "all
the things that would make &postcircumfix:sym<[ ]> work" (and likewise for
{ }) and perhaps other things. These "delegation groups" would be
implementation independent, ie different Perl 6 implementations could
choose to delegate different sets of methods to get [] to work properly.
Of course the right way to do this most of the time is to do class Foo is
Array { ... } which works fine. But sometimes has-a relationships are
preferable to is-a.
So the questions to be answered are:
1. is this a good idea?
2. how do we do this using the pre-existing "handles" trait syntax? (roles
with lists of methods maybe?)
3. how can we divide the groups of methods so you can opt-in only to
particular behaviour? ie you may want to delegate [] stuff like AT-POS but
not have <push pop shift unshift append prepend> (or vis versa or both).
Migrated from rt.perl.org#128330 (status was 'new')
Searchable as RT128330$
The text was updated successfully, but these errors were encountered: