# New Ticket Created by  Cory Spencer 
# Please include the string:  [perl #64108]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=64108 >



The following patch adds a Perl 6 version of rand and cis to Any.pm in the 
setting.
>From fa585efe343dd1f58433812525d55904a813ccfe Mon Sep 17 00:00:00 2001
From: git <cspen...@sprocket.org>
Date: Sun, 22 Mar 2009 12:24:35 -0700
Subject: [PATCH] Added Perl 6 versions of rand and cis to the setting.
 Squashed commit of the following:

commit 52d52445b21f0aeda14145357b26acfaef307381
Author: git <cspen...@sprocket.org>
Date:   Sun Mar 22 12:23:06 2009 -0700

    Moved cis method to Any.pm setting

commit b96748a4ea055d3c4c9d4a7386bc4e3aec734351
Author: git <cspen...@sprocket.org>
Date:   Sun Mar 22 12:15:04 2009 -0700

    Added a Perl 6 version of rand to the setting.
---
 src/builtins/any-num.pir |   37 +------------------------------------
 src/setting/Any-num.pm   |   34 +++++++++++++++++++++++++---------
 2 files changed, 26 insertions(+), 45 deletions(-)

diff --git a/src/builtins/any-num.pir b/src/builtins/any-num.pir
index 6dfcee6..b2971a9 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,cis,int,log,chr,polar,sqrt,truncate,unpolar', 'from'=>$P0)
+    '!EXPORT'('abs,int,log,chr,polar,sqrt,truncate,unpolar', 'from'=>$P0)
 
     ##  pre-seed a random number generator
     $P0 = new 'Random'
@@ -52,15 +52,6 @@ the size of that file down and to emphasize their generic,
     .return ($S0)
 .end
 
-=item cis($angle)
-
-=cut
-
-.namespace ['Any']
-.sub 'cis' :method :multi(_)
-    .tailcall 'unpolar'(1.0, self)
-.end
-
 
 .sub 'int' :method :multi(_)
     .tailcall self.'truncate'()
@@ -94,32 +85,6 @@ error.
 .end
 
 
-=item rand()
-
-=cut
-
-.namespace []
-.sub 'rand'
-    .param pmc x               :slurpy
-    ## 0-argument test, RT#56366
-    unless x goto no_args
-    die "too many arguments passed - 0 params expected"
-  no_args:
-    $P0 = get_hll_global ['Any'], '$!random'
-    $N0 = $P0
-    .return ($N0)
-.end
-
-.namespace ['Any']
-.sub 'rand' :method
-    $N0 = self
-    $P0 = get_hll_global ['Any'], '$!random'
-    $N1 = $P0
-    $N0 *= $N1
-    .return ($N0)
-.end
-
-
 =item sqrt()
 
 =cut
diff --git a/src/setting/Any-num.pm b/src/setting/Any-num.pm
index f84a18c..5ed9b5e 100644
--- a/src/setting/Any-num.pm
+++ b/src/setting/Any-num.pm
@@ -1,29 +1,45 @@
 class Any is also {
-    our Int multi method ceiling (Num $x:) is export {
+    our Int multi method ceiling is export {
         return Q:PIR {
-            $P0 = find_lex "$x"
-            $N0 = $P0
+            $N0 = self
             $I0 = ceil $N0
             %r = box $I0
         }
     }
 
-    our Int multi method floor (Num $x:) is export {
+    our Complex multi method cis is export {
+        unpolar(1.0, self)
+    }
+
+    our Int multi method floor is export {
         return Q:PIR {
-            $P0 = find_lex "$x"
-            $N0 = $P0
+            $N0 = self
             $I0 = floor $N0
             %r = box $I0
         }
     }
 
-    our Int multi method round (Num $x:) is export {
+    our Num method rand {
+        return Q:PIR {
+            $N0 = self
+            $P0 = get_hll_global ['Any'], '$!random'
+            $N1 = $P0
+            $N0 *= $N1
+            %r = box $N0
+        }
+    }
+
+    our Int multi method round is export {
         return Q:PIR {
-            $P0 = find_lex "$x"
-            $N0 = $P0
+            $N0 = self
             $N0 = $N0 + 0.5
             $I0 = floor $N0
             %r = box $I0
         }
     }
 }
+
+our Int sub rand (*...@args) {
+    die "too many arguments passed - 0 params expected" if @args;
+    1.rand
+}
-- 
1.6.0.6

Reply via email to