-
-
Notifications
You must be signed in to change notification settings - Fork 373
/
Order.pm
37 lines (32 loc) · 984 Bytes
/
Order.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Order enumeration, for cmp and <=>
my enum Order (:Less(-1), :Same(0), :More(1));
only Increase () { DEPRECATED("Less", |<2013.11 2014.11>); Less }
only Decrease (){ DEPRECATED("More", |<2013.11 2014.11>); More }
sub ORDER(int $i) {
$i == 0 ?? Same !! $i < 0 ?? Less !! More
}
#?if parrot
proto infix:<cmp>($, $) { * }
#?endif
#?if !parrot
proto infix:<cmp>(Mu $, Mu $) { * }
#?endif
multi infix:<cmp>(\a, \b) {
return Order::Less if a === -Inf || b === Inf;
return Order::More if a === Inf || b === -Inf;
a.Stringy cmp b.Stringy
}
multi infix:<cmp>(Real \a, Real \b) { a.Bridge cmp b.Bridge }
multi infix:<cmp>(Int:D \a, Int:D \b) {
ORDER(nqp::cmp_I(nqp::decont(a), nqp::decont(b)))
}
multi infix:<cmp>(int $a, int $b) {
ORDER(nqp::cmp_i($a, $b))
}
multi infix:«<=>»(Int:D \a, Int:D \b) {
ORDER(nqp::cmp_I(nqp::decont(a), nqp::decont(b)))
}
multi infix:«<=>»(int $a, int $b) {
ORDER(nqp::cmp_i($a, $b))
}
# vim: ft=perl6 expandtab sw=4