Skip Menu |
Report information
Id: 128330
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: lloyd.fourn [at]

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)

Date: Mon, 06 Jun 2016 16:07:51 +0000
From: Lloyd Fournier <lloyd.fourn [...]>
Subject: [FEATURE] delegate Array/Hash methods in a consistent way
To: "rakudobug [...]" <rakudobug [...]>
Download (untitled) / with headers
text/plain 1.3k
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 = => [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).

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at