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
Comments
From @cspencerThe following patch adds a Perl 6 version of rand and cis to Any.pm in the |
From @cspencer0001-Added-Perl-6-versions-of-rand-and-cis-to-the-setting.patchFrom 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
|
From @moritzHi, Cory Spencer (via RT) wrote:
Thanks for the patch. [...]
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 Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
From @pmichaudPatch applied in 3bbb1c4, thanks! Based on moritz's suggestion I switched the call to unpolar to be a I also eliminated the extra calls to 'return', and added the 0-argument Thanks, Pm |
1 similar comment
From @pmichaudPatch applied in 3bbb1c4, thanks! Based on moritz's suggestion I switched the call to unpolar to be a I also eliminated the extra calls to 'return', and added the 0-argument Thanks, Pm |
@pmichaud - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#64108 (status was 'resolved')
Searchable as RT64108$
The text was updated successfully, but these errors were encountered: