Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mark more subs and ops as pure
  • Loading branch information
moritz committed Feb 1, 2013
1 parent 8f39611 commit 6d5dc67
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 68 deletions.
14 changes: 7 additions & 7 deletions src/core/Any.pm
Expand Up @@ -409,17 +409,17 @@ my class Any {
}
Metamodel::ClassHOW.exclude_parent(Any);

proto infix:<===>($?, $?) { * }
proto infix:<===>($?, $?) is pure { * }
multi infix:<===>($a?) { Bool::True }
multi infix:<===>($a, $b) {
nqp::p6bool(nqp::iseq_s(nqp::unbox_s($a.WHICH), nqp::unbox_s($b.WHICH)))
}

proto infix:<before>($, $?) { * }
proto infix:<before>($, $?) is pure { * }
multi infix:<before>($x?) { Bool::True }
multi infix:<before>(\a, \b) { (a cmp b) < 0 }

proto infix:<after>($, $?) { * }
proto infix:<after>($, $?) is pure { * }
multi infix:<after>($x?) { Bool::True }
multi infix:<after>(\a, \b) { (a cmp b) > 0 }

Expand All @@ -438,7 +438,7 @@ proto postfix:<-->(|) { * }
multi postfix:<-->(Mu:D \a is rw) { my $b = a; a = a.pred; $b }
multi postfix:<-->(Mu:U \a is rw) { a = -1; 0 }

proto infix:<min>(|) { * }
proto infix:<min>(|) is pure { * }
multi infix:<min>(*@args) { @args.min }
# XXX the multi version suffers from a multi dispatch bug
# where the mandatory named is ignored in the presence of a slurpy
Expand All @@ -448,14 +448,14 @@ multi infix:<min>(*@args) { @args.min }
sub min(*@args, :&by = &infix:<cmp>) { @args.min(&by) }


proto infix:<max>(|) { * }
proto infix:<max>(|) is pure { * }
multi infix:<max>(*@args) { @args.max }
#proto sub max(|) { * }
#multi sub max(*@args) { @args.max() }
#multi sub max(*@args, :&by!) { @args.max(&by) }
sub max(*@args, :&by = &infix:<cmp>) { @args.max(&by) }

proto infix:<minmax>(|) { * }
proto infix:<minmax>(|) is pure { * }
multi infix:<minmax>(*@args) { @args.minmax }
#proto sub minmax(|) { * }
#multi sub minmax(*@args) { @args.minmax() }
Expand Down Expand Up @@ -511,5 +511,5 @@ multi sub sort(*@values) {
!! @values.sort;
}

multi sub item(*@a) { my $ = @a }
multi sub item(*@a) is pure { my $ = @a }
multi sub item(Mu $a) { $a }
16 changes: 8 additions & 8 deletions src/core/Bool.pm
Expand Up @@ -29,34 +29,34 @@ multi prefix:<-->(Bool:U \a is rw) { a = False; }
multi postfix:<++>(Bool:U \a is rw) { a = True; False; }
multi postfix:<-->(Bool:U \a is rw) { a = False; }

proto prefix:<?>(Mu $) { * }
proto prefix:<?>(Mu $) is pure { * }
multi prefix:<?>(Bool:D \a) { a }
multi prefix:<?>(Mu \a) { a.Bool }

proto prefix:<so>(Mu $) { * }
proto prefix:<so>(Mu $) is pure { * }
multi prefix:<so>(Bool:D \a) { a }
multi prefix:<so>(Mu \a) { a.Bool }

proto prefix:<!>(Mu $) { * }
proto prefix:<!>(Mu $) is pure { * }
multi prefix:<!>(Bool \a) { nqp::p6bool(a ?? 0 !! 1) }
multi prefix:<!>(Mu \a) { nqp::p6bool(a.Bool ?? 0 !! 1) }

proto prefix:<not>(Mu $) { * }
proto prefix:<not>(Mu $) is pure { * }
multi prefix:<not>(Bool \a) { nqp::p6bool(a ?? 0 !! 1) }
multi prefix:<not>(Mu \a) { nqp::p6bool(a.Bool ?? 0 !! 1) }

proto prefix:<?^>(Mu $) { * }
proto prefix:<?^>(Mu $) is pure { * }
multi prefix:<?^>(Mu \a) { not a }

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

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

proto infix:<?^>(|) { * }
proto infix:<?^>(|) is pure { * }
multi infix:<?^>(Mu $x = Bool::False) { $x.Bool }
multi infix:<?^>(Mu \a, Mu \b) { a.Bool ^^ b.Bool }

Expand Down
2 changes: 1 addition & 1 deletion src/core/Complex.pm
Expand Up @@ -396,7 +396,7 @@ multi sub infix:<==>(Complex:D \a, Complex:D \b) returns Bool:D { a.re == b.re &
multi sub infix:<==>(Complex:D \a, Real \b) returns Bool:D { a.re == b && a.im == 0e0 }
multi sub infix:<==>(Real \a, Complex:D \b) returns Bool:D { a == b.re && 0e0 == b.im }

proto postfix:<i>(|) returns Complex:D { * }
proto postfix:<i>(|) returns Complex:D is pure { * }
multi postfix:<i>(Real \a) returns Complex:D { Complex.new(0e0, a); }
multi postfix:<i>(Complex:D \a) returns Complex:D { Complex.new(-a.im, a.re) }
multi postfix:<i>(Numeric \a) returns Complex:D { a * Complex.new(0e0, 1e0) }
Expand Down
10 changes: 5 additions & 5 deletions src/core/Cool.pm
Expand Up @@ -204,11 +204,11 @@ sub uc(Cool $s) { $s.uc }

sub ucfirst(Cool $s) is DEPRECATED { $s.ucfirst }

proto sub rindex($, $, $?) { * };
proto sub rindex($, $, $?) is pure { * };
multi sub rindex(Cool $s, Cool $needle, Cool $pos) { $s.rindex($needle, $pos) };
multi sub rindex(Cool $s, Cool $needle) { $s.rindex($needle) };

proto sub ords($) { * }
proto sub ords($) is pure { * }
multi sub ords(Cool $s) { ords($s.Stringy) }

proto sub comb($, $, $?) { * }
Expand All @@ -218,11 +218,11 @@ proto sub capitalize($) is DEPRECATED { * }
multi sub capitalize(Str:D $x) {$x.capitalize }
multi sub capitalize(Cool $x) {$x.Stringy.capitalize }

proto sub wordcase($) { * }
proto sub wordcase($) is pure { * }
multi sub wordcase(Str:D $x) {$x.wordcase }
multi sub wordcase(Cool $x) {$x.Str.wordcase }

proto sub tclc($) { * }
proto sub tclc($) is pure { * }
multi sub tclc(Cool $x) { tclc $x.Str }

sub sprintf(Cool $format, *@args) {
Expand All @@ -240,7 +240,7 @@ sub split($pat, Cool $target, $limit = $Inf, :$all) {
$target.split($pat, $limit, :$all);
}

proto sub chars($) {*}
proto sub chars($) is pure {*}
multi sub chars(Cool $x) { $x.Str.chars }
multi sub chars(Str:D $x) { nqp::p6box_i(nqp::chars($x)) }
multi sub chars(str $x) returns int { nqp::chars($x) }
6 changes: 3 additions & 3 deletions src/core/Int.pm
Expand Up @@ -239,21 +239,21 @@ multi prefix:<+^>(int $a) {
nqp::bitneg_i($a);
}

proto sub chr($) {*}
proto sub chr($) is pure {*}
multi sub chr(Int:D \x) returns Str:D { x.chr }
multi sub chr(Cool \x) returns Str:D { x.Int.chr }
multi sub chr(int $x) returns str {
nqp::chr($x);
}

proto sub is-prime($, $?) {*}
proto sub is-prime($, $?) is pure {*}
multi sub is-prime(Int:D \i, Int:D $tries = 100) {
nqp::p6bool(nqp::isprime_I(nqp::p6decont(i), nqp::unbox_i($tries)));
}
multi sub is-prime(\i, $tries = 100) {
nqp::p6bool(nqp::isprime_I(nqp::p6decont(i.Int), nqp::unbox_i($tries.Int)));
}
proto sub expmod($, $, $) {*}
proto sub expmod($, $, $) is pure {*}
multi sub expmod(Int:D \base, Int:D \exp, Int:D \mod) {
nqp::expmod_I(nqp::p6decont(base), nqp::p6decont(exp), nqp::p6decont(mod), Int);
}
Expand Down
86 changes: 43 additions & 43 deletions src/core/Numeric.pm
Expand Up @@ -31,146 +31,146 @@ multi sub infix:<eqv>(Numeric:D $a, Numeric:D $b) {

## arithmetic operators

proto prefix:<+>($?) { * }
proto prefix:<+>($?) is pure { * }
multi prefix:<+>(\a) { a.Numeric }

proto prefix:<->($?) { * }
proto prefix:<->($?) is pure { * }
multi prefix:<->(\a) { -a.Numeric }

proto sub abs($) { * }
proto sub abs($) is pure { * }
multi sub abs(\a) { abs a.Numeric }

proto sub sign($) {*}
proto sub sign($) is pure {*}
multi sub sign(Numeric \x) { x.sign }
multi sub sign(Cool \x) { x.Numeric.sign }

proto sub log($, $?) {*}
proto sub log($, $?) is pure {*}
multi sub log(Numeric $x) { $x.log }
multi sub log(Numeric $x, Numeric $base) { $x.log($base) }
multi sub log(Cool $x) { $x.Numeric.log }
multi sub log(Cool $x, Cool $base) { $x.Numeric.log($base.Numeric) }

proto sub log10($, $?) {*}
proto sub log10($, $?) is pure {*}
multi sub log10(Numeric $x) { $x.log(10e0) }
multi sub log10(Cool $x) { $x.Numeric.log(10e0) }

proto sub exp($, $?) {*}
proto sub exp($, $?) is pure {*}
multi sub exp(Numeric $x) { $x.exp }
multi sub exp(Numeric $x, Numeric $base) { $x.exp($base) }

proto sub sin($) {*}
proto sub sin($) is pure {*}
multi sub sin(Numeric \x) { x.sin }
multi sub sin(Cool \x) { x.Numeric.sin }

proto sub asin($) {*}
proto sub asin($) is pure {*}
multi sub asin(Numeric \x) { x.asin }
multi sub asin(Cool \x) { x.Numeric.asin }

proto sub cos($) {*}
proto sub cos($) is pure {*}
multi sub cos(Numeric \x) { x.cos }
multi sub cos(Cool \x) { x.Numeric.cos }

proto sub acos($) {*}
proto sub acos($) is pure {*}
multi sub acos(Numeric \x) { x.acos }
multi sub acos(Cool \x) { x.Numeric.acos }

proto sub tan($) {*}
proto sub tan($) is pure {*}
multi sub tan(Numeric \x) { x.tan }
multi sub tan(Cool \x) { x.Numeric.tan }

proto sub atan($) {*}
proto sub atan($) is pure {*}
multi sub atan(Numeric \x) { x.atan }
multi sub atan(Cool \x) { x.Numeric.atan }

proto sub sec($) {*}
proto sub sec($) is pure {*}
multi sub sec(Numeric \x) { x.sec }
multi sub sec(Cool \x) { x.Numeric.sec }

proto sub asec($) {*}
proto sub asec($) is pure {*}
multi sub asec(Numeric \x) { x.asec }
multi sub asec(Cool \x) { x.Numeric.asec }

proto sub cosec($) {*}
proto sub cosec($) is pure {*}
multi sub cosec(Numeric \x) { x.cosec }
multi sub cosec(Cool \x) { x.Numeric.cosec }

proto sub acosec(|) {*}
proto sub acosec(|) is pure {*}
multi sub acosec(Numeric \x) { x.acosec }
multi sub acosec(Cool \x) { x.Numeric.acosec }

proto sub cotan($) {*}
proto sub cotan($) is pure {*}
multi sub cotan(Numeric \x) { x.cotan }
multi sub cotan(Cool \x) { x.Numeric.cotan }

proto sub acotan($) {*}
proto sub acotan($) is pure {*}
multi sub acotan(Numeric \x) { x.acotan }
multi sub acotan(Cool \x) { x.Numeric.acotan }

proto sub sinh($) {*}
proto sub sinh($) is pure {*}
multi sub sinh(Numeric \x) { x.sinh }
multi sub sinh(Cool \x) { x.Numeric.sinh }

proto sub asinh($) {*}
proto sub asinh($) is pure {*}
multi sub asinh(Numeric \x) { x.asinh }
multi sub asinh(Cool \x) { x.Numeric.asinh }

proto sub cosh($) {*}
proto sub cosh($) is pure {*}
multi sub cosh(Numeric \x) { x.cosh }
multi sub cosh(Cool \x) { x.Numeric.cosh }

proto sub acosh($) {*}
proto sub acosh($) is pure {*}
multi sub acosh(Numeric \x) { x.acosh }
multi sub acosh(Cool \x) { x.Numeric.acosh }

proto sub tanh($) {*}
proto sub tanh($) is pure {*}
multi sub tanh(Numeric \x) { x.tanh }
multi sub tanh(Cool \x) { x.Numeric.tanh }

proto sub atanh($) {*}
proto sub atanh($) is pure {*}
multi sub atanh(Numeric \x) { x.atanh }
multi sub atanh(Cool \x) { x.Numeric.atanh }

proto sub sech($) {*}
proto sub sech($) is pure {*}
multi sub sech(Numeric \x) { x.sech }
multi sub sech(Cool \x) { x.Numeric.sech }

proto sub asech($) {*}
proto sub asech($) is pure {*}
multi sub asech(Numeric \x) { x.asech }
multi sub asech(Cool \x) { x.Numeric.asech }

proto sub cosech($) {*}
proto sub cosech($) is pure {*}
multi sub cosech(Numeric \x) { x.cosech }
multi sub cosech(Cool \x) { x.Numeric.cosech }

proto sub acosech($) {*}
proto sub acosech($) is pure {*}
multi sub acosech(Numeric \x) { x.acosech }
multi sub acosech(Cool \x) { x.Numeric.acosech }

proto sub cotanh($) {*}
proto sub cotanh($) is pure {*}
multi sub cotanh(Numeric \x) { x.cotanh }
multi sub cotanh(Cool \x) { x.Numeric.cotanh }

proto sub acotanh($) {*}
proto sub acotanh($) is pure {*}
multi sub acotanh(Numeric \x) { x.acotanh }
multi sub acotanh(Cool \x) { x.Numeric.acotanh }

proto sub sqrt($) {*}
proto sub sqrt($) is pure {*}
multi sub sqrt(Numeric \x) { x.sqrt }
multi sub sqrt(Cool \x) { x.Numeric.sqrt }

proto sub roots($, $) { * }
proto sub roots($, $) is pure { * }
multi sub roots($x, Cool $n) { $x.Numeric.Complex.roots($n.Int) }
multi sub roots($x, Numeric $n) { $x.Numeric.Complex.roots($n.Int) }

proto sub floor($) { * }
proto sub floor($) is pure { * }
multi sub floor($a) { $a.Numeric.floor }
multi sub floor(Numeric $a) { $a.floor }

proto sub ceiling($) { * }
proto sub ceiling($) is pure { * }
multi sub ceiling($a) { $a.Numeric.ceiling }
multi sub ceiling(Numeric $a) { $a.ceiling }

proto sub round($) { * }
proto sub round($) is pure { * }
multi sub round($a) { $a.Numeric.round }
multi sub round(Numeric $a) { $a.round }
multi sub round(Numeric $a, $scale) { $a.round($scale) }
Expand All @@ -192,7 +192,7 @@ 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?)is pure { * }
proto infix:<div>($a?, $b?) is pure { * }
# rest of infix:<div> is in Int.pm

proto infix:<%>($a?, $b?) is pure { * }
Expand Down Expand Up @@ -249,31 +249,31 @@ multi infix:«>=»(\a, \b) { a.Real >= b.Real }

## bitwise operators

proto infix:<+&>($?, $?) { * }
proto infix:<+&>($?, $?) is pure { * }
multi infix:<+&>() { +^0 }
multi infix:<+&>($x) { $x }
multi infix:<+&>($x, $y) { $x.Numeric.Int +& $y.Numeric.Int }

proto infix:<+|>($?, $?) { * }
proto infix:<+|>($?, $?) is pure { * }
multi infix:<+|>() { 0 }
multi infix:<+|>($x) { $x }
multi infix:<+|>($x, $y) { $x.Numeric.Int +| $y.Numeric.Int }

proto infix:<+^>($?, $?) { * }
proto infix:<+^>($?, $?) is pure { * }
multi infix:<+^>() { 0 }
multi infix:<+^>($x) { $x }
multi infix:<+^>($x, $y) { $x.Numeric.Int +^ $y.Numeric.Int }

proto infix:«+<»($?, $?) { * }
proto infix:«+<»($?, $?) is pure { * }
multi infix+<»() { fail "No zero-arg meaning for infix:«+<»"; }
multi infix+<»($x) { $x }
multi infix+<»($x,$y) { $x.Numeric.Int +< $y.Numeric.Int }

proto infix:«+>»($?, $?) { * }
proto infix:«+>»($?, $?) is pure { * }
multi infix+>»() { fail "No zero-arg meaning for infix:«+>»"; }
multi infix+>»($x) { $x }
multi infix+>»($x,$y) { $x.Numeric.Int +> $y.Numeric.Int }

proto prefix:<+^>($?, $?) { * }
proto prefix:<+^>($?, $?) is pure { * }
multi prefix:<+^>($x) { +^ $x.Numeric.Int }

0 comments on commit 6d5dc67

Please sign in to comment.