Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Unreasonably painful to add a method to all *Array PMCs #454

japhb opened this Issue · 1 comment

2 participants


Adding a method that works for all *Array PMCs (in either PIR or NQP) should be really easy, but it isn't. If all *Array PMCs had a common ancestor (Array, say), you could do this:

module Array {
    method reverse () {
        my @reversed;
        for self { @reversed.unshift($_); }

Unfortunately, there is no such common ancestor. Likewise, they
share no common role, so that's not an in either.

One could copy and paste the above block for each *Array module, but that's just nuts. Talk about a DRY violation.

It's possible one might create one method code object, then iterate over all the known *Array types and use add_method to add that code to them as a method, but this will fail if the list of *Array types changes, which it reasonably might. Plus it's just ugly for what should be a simple task.



This is by no means the only problem we have with the various array types, as detailed in ArrayTasklist.

Unfortunately I don't think "one common ancestor" is the the best answer. The problem is that what we regard as "Array" is in fact a combination of several different features. IMHO what's needed isn't *one* root type, but a number of them:

  • Orderable (iterable, reversible)
  • Indexable read
  • Indexable write
  • Deque (push, pop, shift, unshift)
  • Tuple (fixed-sized, equivalent to a List)

However we could use this ticket as an opportunity to implement a more general refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.