Skip to content

Commit

Permalink
make ord() and chr() work with named args
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Dec 6, 2009
1 parent 63caed2 commit 7fc4854
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/core/Any-num.pm
Expand Up @@ -12,7 +12,7 @@ augment class Any {
pir::box__PN(pir::ceil__IN(self))
}

our Str multi method chr() is export {
our Str multi method chr() {
~(pir::chr__SI(self))
}

Expand Down Expand Up @@ -387,7 +387,7 @@ our multi sub sqrt(Any $x) {
}

our proto sign($x) {
defined($x) ?? $x.Num.sign !! undef;
defined($x) ?? $x.Num.sign !! Mu;
}

# This one doesn't seem to be needed with the above defined.
Expand All @@ -413,5 +413,8 @@ our multi sub infix:«<=>»($a, $b) {
+$a cmp +$b
}

our proto chr($graph) {
$graph.chr;
}

# vim: ft=perl6
10 changes: 9 additions & 1 deletion src/core/Any-str.pm
Expand Up @@ -133,7 +133,7 @@ augment class Any {
Regex::Cursor.parse(self, :rule($pat), :c($c));
}

our Int multi method ord() is export {
our Int multi method ord() {
fail('Can not take ord of empty string') if self.chars == 0;
pir::box__PI(pir::ord__IS(self))
}
Expand Down Expand Up @@ -179,6 +179,14 @@ augment class Any {
}
}

our multi sub ord($string) {
$string.ord;
}

our proto ord($string) {
$string.ord;
}

multi sub infix:<x>($str, $n) {
$n > 0 ?? ~(pir::repeat__SSI($str, $n)) !! ''
}
Expand Down

0 comments on commit 7fc4854

Please sign in to comment.