Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mark some numeric operators as pure
  • Loading branch information
moritz committed Jan 27, 2013
1 parent 9c9d790 commit a1bcaa6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/core/Numeric.pm
Expand Up @@ -175,75 +175,75 @@ multi sub round($a) { $a.Numeric.round }
multi sub round(Numeric $a) { $a.round }
multi sub round(Numeric $a, $scale) { $a.round($scale) }

proto infix:<+>($a?, $b?) { * }
proto infix:<+>($a?, $b?) is pure { * }
multi infix:<+>($x = 0) { $x.Numeric }
multi infix:<+>(\a, \b) { a.Numeric + b.Numeric }

proto infix:<->($a?, $b?) { * }
proto infix:<->($a?, $b?) is pure { * }
multi infix:<->($x = 0) { $x.Numeric }
multi infix:<->(\a, \b) { a.Numeric - b.Numeric }

proto infix:<*>($a?, $b?) { * }
proto infix:<*>($a?, $b?) is pure { * }
multi infix:<*>($x = 1) { $x.Numeric }
multi infix:<*>(\a, \b) { a.Numeric * b.Numeric }

proto infix:</>($a?, $b?) { * }
proto infix:</>($a?, $b?) is pure { * }
multi infix:</>() { fail "No zero-arg meaning for infix:</>" }
multi infix:</>($x) { $x.Numeric }
multi infix:</>(\a, \b) { a.Numeric / b.Numeric }

proto infix:<div>($a?, $b?) { * }
proto infix:<div>($a?, $b?)is pure { * }
# rest of infix:<div> is in Int.pm

proto infix:<%>($a?, $b?) { * }
proto infix:<%>($a?, $b?) is pure { * }
multi infix:<%>() { fail "No zero-arg meaning for infix:<%>" }
multi infix:<%>($x) { $x }
multi infix:<%>(\a, \b) { a.Real % b.Real }

proto infix:<%%>($a?, $b?) { * }
proto infix:<%%>($a?, $b?) is pure { * }
multi infix:<%%>() { fail "No zero-arg meaning for infix:<%%>" }
multi infix:<%%>($x) { Bool::True }
multi infix:<%%>(\a, \b) { a.Real % b.Real == 0 }

proto infix:<lcm>($a?, $b?) { * }
proto infix:<lcm>($a?, $b?) is pure { * }
multi infix:<lcm>(Int $x = 1) { $x }
multi infix:<lcm>(\a, \b) { a.Int lcm b.Int }

proto infix:<gcd>($a?, $b?) { * }
proto infix:<gcd>($a?, $b?) is pure { * }
multi infix:<gcd>() { fail 'No zero-arg meaning for infix:<gcd>' }
multi infix:<gcd>(Int $x) { $x }
multi infix:<gcd>(\a, \b) { a.Int gcd b.Int }

proto infix:<**>($a?, $b?) { * }
proto infix:<**>($a?, $b?) is pure { * }
multi infix:<**>($x = 1) { $x.Numeric }
multi infix:<**>(\a, \b) { a.Numeric ** b.Numeric }

## relational operators

proto infix:«<=>»($, $?) { * }
proto infix:«<=>»($, $?) is pure { * }
multi infix:«<=>»(\a, \b) { a.Real <=> b.Real }

proto infix:<==>($a?, $b?) { * }
proto infix:<==>($a?, $b?) is pure { * }
multi infix:<==>($x?) { Bool::True }
multi infix:<==>(\a, \b) { a.Numeric == b.Numeric }

proto infix:<!=>(Mu $a?, Mu $b?) { * }
proto infix:<!=>(Mu $a?, Mu $b?) is pure { * }
multi infix:<!=>($x?) { Bool::True }
multi infix:<!=>(Mu \a, Mu \b) { not a == b }

proto infix:«<»($a?, $b?) { * }
proto infix:«<»($a?, $b?) is pure { * }
multi infix<»($x?) { Bool::True }
multi infix<»(\a, \b) { a.Real < b.Real }

proto infix:«<=»($a?, $b?) { * }
proto infix:«<=»($a?, $b?) is pure { * }
multi infix<=»($x?) { Bool::True }
multi infix<=»(\a, \b) { a.Real <= b.Real }

proto infix:«>»($a?, $b?) { * }
proto infix:«>»($a?, $b?) is pure { * }
multi infix>»($x?) { Bool::True }
multi infix>»(\a, \b) { a.Real > b.Real }

proto infix:«>=»($a?, $b?) { * }
proto infix:«>=»($a?, $b?) is pure { * }
multi infix>=»($x?) { Bool::True }
multi infix>=»(\a, \b) { a.Real >= b.Real }

Expand Down
5 changes: 5 additions & 0 deletions src/core/traits.pm
Expand Up @@ -246,6 +246,11 @@ multi trait_mod:<is>(Routine:D $r, :$hidden_from_backtrace!) {
});
}

multi trait_mod:<is>(Routine:D $r, :$pure!) {
$r.HOW.mixin($r, role {
method IS_PURE { True }
});
}

proto trait_mod:<returns>(|) { * }
multi trait_mod:<returns>(Routine:D $target, Mu:U $type) {
Expand Down

0 comments on commit a1bcaa6

Please sign in to comment.