Skip to content

Commit

Permalink
Make the .ord method a proper multi
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Mar 31, 2021
1 parent 8fc4cb5 commit 2a972b2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core.c/unicodey.pm6
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
augment class Cool {
method ord(--> Int:D) {
self.Str.ord
}
proto method ord(*%) {*}
multi method ord(Cool:D: --> Int:D) { self.Str.ord }

method chr() {
self.Int.chr;
}
Expand Down Expand Up @@ -52,7 +52,6 @@ augment class Int {
}

augment class Str {
proto method ord(|) {*}
multi method ord(Str:D: --> Int:D) {
nqp::chars($!value)
?? nqp::p6box_i(nqp::ord($!value))
Expand Down Expand Up @@ -127,7 +126,6 @@ augment class Str {
nqp::join("",$parts)
}
}
BEGIN .^compose for IntStr, NumStr, RatStr, ComplexStr;

augment class List {
multi method chrs(List:D: --> Str:D) {
Expand Down Expand Up @@ -163,14 +161,17 @@ augment class List {
)
}
}
BEGIN .^compose for Array, Match, Range, Seq;

augment class Nil {
# These suggest using Nil.new if they fall through, which is LTA
method ords() { self.Str.ords }
method chrs() { self.Int.chrs }
}

# Make sure all affected subclasses are aware of additions to their parents
BEGIN .^compose for
Array, Match, Range, Seq, IntStr, NumStr, RatStr, ComplexStr;

# all proto's in one place so they're available on all (conditional) backends
#-------------------------------------------------------------------------------
proto sub chr($, *%) is pure {*}
Expand Down Expand Up @@ -201,7 +202,7 @@ multi sub chr(int $x --> str) { nqp::chr($x) }

multi sub chrs(*@c --> Str:D) { @c.chrs }

multi sub ord($s) { $s.ord }
multi sub ord(\what) { what.ord }
multi sub ords($s) { $s.ords }

multi sub uniname(Str:D $str) { $str ?? uniname($str.ord) !! Nil }
Expand Down

0 comments on commit 2a972b2

Please sign in to comment.