Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Perl 6 version of rand and cis to Any.pm in the setting #827

Closed
p6rt opened this issue Mar 22, 2009 · 7 comments
Closed

Added a Perl 6 version of rand and cis to Any.pm in the setting #827

p6rt opened this issue Mar 22, 2009 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 22, 2009

Migrated from rt.perl.org#64108 (status was 'resolved')

Searchable as RT64108$

@p6rt
Copy link
Author

p6rt commented Mar 22, 2009

From @cspencer

The following patch adds a Perl 6 version of rand and cis to Any.pm in the
setting.

@p6rt
Copy link
Author

p6rt commented Mar 22, 2009

From @cspencer

0001-Added-Perl-6-versions-of-rand-and-cis-to-the-setting.patch
From fa585efe343dd1f58433812525d55904a813ccfe Mon Sep 17 00:00:00 2001
From: git <cspencer@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 <cspencer@sprocket.org>
Date:   Sun Mar 22 12:23:06 2009 -0700

    Moved cis method to Any.pm setting

commit b96748a4ea055d3c4c9d4a7386bc4e3aec734351
Author: git <cspencer@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

@p6rt
Copy link
Author

p6rt commented Mar 23, 2009

From @moritz

Hi,

Cory Spencer (via RT) wrote​:

The following patch adds a Perl 6 version of rand and cis to Any.pm in the
setting.

Thanks for the patch.
Unfortunately, it doesn't apply cleanly here (at rakudo
748771092a53e8910df4c633567c9a57b090a12e), does it depend on a previous
patch you send?

[...]

- our Int multi method floor (Num $x​:) is export {
+ our Complex multi method cis is export {
+ unpolar(1.0, self)
+ }
+

is there any good reason to use the sub form over the method form?

I somehow would prefer the latter, because I think it'll DWIM better
with respect to user defined numeric types and polymorphism, but I'm not
sure if that's really the case.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Mar 23, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 26, 2009

From @pmichaud

Patch applied in 3bbb1c4, thanks!

Based on moritz's suggestion I switched the call to unpolar to be a
method call instead of a subroutine call (we can always switch it back).

I also eliminated the extra calls to 'return', and added the 0-argument
parens to the method definitions (which we likely need to add to many of
the methods in settings, as well as the specifications in S32).

Thanks,

Pm

1 similar comment
@p6rt
Copy link
Author

p6rt commented Mar 26, 2009

From @pmichaud

Patch applied in 3bbb1c4, thanks!

Based on moritz's suggestion I switched the call to unpolar to be a
method call instead of a subroutine call (we can always switch it back).

I also eliminated the extra calls to 'return', and added the 0-argument
parens to the method definitions (which we likely need to add to many of
the methods in settings, as well as the specifications in S32).

Thanks,

Pm

@p6rt
Copy link
Author

p6rt commented Mar 26, 2009

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 26, 2009
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant