Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #555 from cognominal/nom
equiv/tighter/looser traits with is equiv<+> syntax
  • Loading branch information
moritz committed Oct 17, 2015
2 parents 1b4715f + b670517 commit ebe21c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/core/operators.pm
Expand Up @@ -631,6 +631,35 @@ sub infix:<orelse>(**@a) {
$current;
}

# next three sub would belong to traits.pm if PseudoStash were available
# so early in the setting compunit
multi sub trait_mod:<is>(Routine $r, Str :$equiv!) {
if (my $i = nqp::index($r.name, ':')) > 0 {
my \nm ='&' ~ nqp::substr($r.name, 0, $i+1) ~ '<' ~ $equiv ~ '>';
trait_mod:<is>($r, equiv => ::(nm));
return;
}
die "Routine given to equiv does not appear to be an operator";;
}

multi sub trait_mod:<is>(Routine $r, Str :$tighter!) {
if (my $i = nqp::index($r.name, ':')) > 0 {
my \nm ='&' ~ nqp::substr($r.name, 0, $i+1) ~ '<' ~ $tighter ~ '>';
trait_mod:<is>($r, tighter => ::(nm));
return;
}
die "Routine given to tighter does not appear to be an operator";;
}

multi sub trait_mod:<is>(Routine $r, Str :$looser!) {
if (my $i = nqp::index($r.name, ':')) > 0 {
my \nm ='&' ~ nqp::substr($r.name, 0, $i+1) ~ '<' ~ $looser ~ '>';
trait_mod:<is>($r, looser => ::(nm));
return;
}
die "Routine given to looser does not appear to be an operator";;
}

proto sub infix:<> (&?, &?) {*}
multi sub infix:<> () { *.self }
multi sub infix:<> (&f) { &f }
Expand Down
1 change: 1 addition & 0 deletions src/core/traits.pm
Expand Up @@ -148,6 +148,7 @@ multi sub trait_mod:<is>(Routine:D $r, :prec(%spec)!) {
}
0;
}
# three other trait_mod sub for equiv/tighter/looser in operators.pm
multi sub trait_mod:<is>(Routine $r, :&equiv!) {
nqp::can(&equiv, 'prec')
?? trait_mod:<is>($r, :prec(&equiv.prec))
Expand Down

0 comments on commit ebe21c4

Please sign in to comment.