Skip to content
Permalink
Browse files

Abstract "keyof" parameterization into R:I:PARAMETERIZE-KEYOF

- DRY
- unfortunately, the ^parameterize method must exist in every class
  as it mangles its metaclass, and that would not do the right thing
  if it were in a role
- can also be used for future parameterization of other QuantHashes
  • Loading branch information...
lizmat committed Jan 13, 2019
1 parent 4bb5c33 commit e87b7afb0d23b50bc5c2cf14572a3aee511b40fd
Showing with 14 additions and 12 deletions.
  1. +10 −4 src/core/Rakudo/Internals.pm6
  2. +1 −3 src/core/Set.pm6
  3. +3 −5 src/core/SetHash.pm6
@@ -457,10 +457,6 @@ my class Rakudo::Internals {
)
}

our role Constraint[::CONSTRAINT] {
method keyof() { CONSTRAINT }
}

our role ImplementationDetail {
method new(|) { die self.gist }
method gist(--> Str:D) {
@@ -1658,6 +1654,16 @@ implementation detail and has no serviceable parts inside"
}
$CORE_METAOP_ASSIGN
}

# handle parameterization by just adding a "keyof" method
my role KeyOf[::CONSTRAINT] {
method keyof() { CONSTRAINT }
}
method PARAMETERIZE-KEYOF(Mu \base, Mu \type) {
my \what := base.^mixin(KeyOf[type]);
what.^set_name(base.^name ~ '[' ~ type.^name ~ ']');
what
}
}

# expose the number of bits a native int has
@@ -2,9 +2,7 @@ my class Set does Setty {
has ValueObjAt $!WHICH;

method ^parameterize(Mu \base, Mu \type) {
my \what := base.^mixin(Rakudo::Internals::Constraint[type]);
what.^set_name(base.^name ~ '[' ~ type.^name ~ ']');
what
Rakudo::Internals.PARAMETERIZE-KEYOF(base,type)
}

multi method WHICH (Set:D: --> ValueObjAt:D) {
@@ -1,10 +1,8 @@
my class SetHash does Setty {

method ^parameterize(Mu \base, Mu \type) {
my \what := base.^mixin(Rakudo::Internals::Constraint[type]);
what.^set_name(base.^name ~ '[' ~ type.^name ~ ']');
what
}
method ^parameterize(Mu \base, Mu \type) {
Rakudo::Internals.PARAMETERIZE-KEYOF(base,type)
}

#--- selector methods

0 comments on commit e87b7af

Please sign in to comment.
You can’t perform that action at this time.