From 032aadad66d59cd1227ec299ac924001fc6b4f7b Mon Sep 17 00:00:00 2001
From: Cory Spencer <cspencer@sprocket.org>
Date: Fri, 27 Mar 2009 20:17:29 -0700
Subject: [PATCH] Added Perl 6 versions of chr, ord and chars to Any.pm in the setting.
 Squashed commit of the following:

commit ece903768c7cbdb1c06439a94d30f93debfe1a58
Author: Cory Spencer <cspencer@sprocket.org>
Date:   Fri Mar 27 19:49:21 2009 -0700

    Added a Perl 6 version of chars to Any.pm in the setting.

commit 5e9aa208bad387466446477a1d48919bdf07602d
Author: Cory Spencer <cspencer@sprocket.org>
Date:   Fri Mar 27 18:06:52 2009 -0700

    Add Perl 6 version of ord/chr to Any.pm in the setting.
---
 src/builtins/any-num.pir |   12 +-----------
 src/builtins/any-str.pir |   25 +------------------------
 src/setting/Any-num.pm   |    9 +++++++++
 src/setting/Any-str.pm   |   16 ++++++++++++++++
 4 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/src/builtins/any-num.pir b/src/builtins/any-num.pir
index 7ee280c..fb42e84 100644
--- a/src/builtins/any-num.pir
+++ b/src/builtins/any-num.pir
@@ -21,7 +21,7 @@ the size of that file down and to emphasize their generic,
 .namespace []
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('abs,int,log,chr,polar,sqrt,truncate,unpolar', 'from'=>$P0)
+    '!EXPORT'('abs,int,log,polar,sqrt,truncate,unpolar', 'from'=>$P0)
 
     ##  pre-seed a random number generator
     $P0 = new 'Random'
@@ -41,17 +41,7 @@ the size of that file down and to emphasize their generic,
     .return ($N1)
 .end
 
-=item chr()
-
-=cut
-
 .namespace ['Any']
-.sub 'chr' :method :multi(_)
-    $I0 = self
-    $S0 = chr $I0
-    .return ($S0)
-.end
-
 
 .sub 'int' :method :multi(_)
     .tailcall self.'truncate'()
diff --git a/src/builtins/any-str.pir b/src/builtins/any-str.pir
index 22be0aa..456accc 100644
--- a/src/builtins/any-str.pir
+++ b/src/builtins/any-str.pir
@@ -23,22 +23,11 @@ the size of that file down and to emphasize their generic,
 .namespace []
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('chomp,chars,:d,:e,:f,index,rindex,ord,substr', 'from'=>$P0)
+    '!EXPORT'('chomp,:d,:e,:f,index,rindex,substr', 'from'=>$P0)
 .end
 
-
-=item chars()
-
-=cut
-
 .namespace ['Any']
 
-.sub 'chars' :method :multi(_)
-    $S0 = self
-    $I0 = length $S0
-    .return ($I0)
-.end
-
 =item chomp
 
  our Str method Str::chomp ( Str $string: )
@@ -871,18 +860,6 @@ Partial implementation. The :g modifier on regexps doesn't work, for example.
     die "Must pass a non-negative integer to :x()"
 .end
 
-
-=item ord()
-
-=cut
-
-.namespace ['Any']
-.sub 'ord' :method :multi(_)
-    $S0 = self
-    $I0 = ord $S0
-    .return ($I0)
-.end
-
 # Local Variables:
 #   mode: pir
 #   fill-column: 100
diff --git a/src/setting/Any-num.pm b/src/setting/Any-num.pm
index d2fda3e..09622ae 100644
--- a/src/setting/Any-num.pm
+++ b/src/setting/Any-num.pm
@@ -7,6 +7,15 @@ class Any is also {
         }
     }
 
+    # TODO: Return type should be a Char once that is supported.
+    our Str multi method chr is export {
+        Q:PIR {
+            $I0 = self
+            $S0 = chr $I0
+            %r = box $S0
+        }
+    }
+
     our Complex multi method cis() is export {
         (1.0).unpolar(self)
     }
diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm
index 27c2080..77cf4c3 100644
--- a/src/setting/Any-str.pm
+++ b/src/setting/Any-str.pm
@@ -1,4 +1,12 @@
 class Any is also {
+    our Int multi method chars is export {
+        Q:PIR {
+            $S0 = self
+            $I0 = length $S0
+            %r = box $I0
+        }
+    }
+
     our Str multi method capitalize() is export {
         self.lc.subst(/\w+/, { .ucfirst }, :global)
     }
@@ -23,6 +31,14 @@ class Any is also {
         self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! ""
     }
 
+    our Int multi method ord is export {
+        Q:PIR {
+            $S0 = self
+            $I0 = ord $S0
+            %r = box $I0
+        }
+    }
+
     our Int multi method p5chomp is export(:P5) {
         my $num = 0;
 
-- 
1.6.1.3

