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
Multiple bug fixes (list branch) #1841
Comments
From justin.sahs@gmail.comApply to branch list, commit ddb39d064c6e334f4d08 core/operators.pm: builtins/control.pir Results of make spectest: t/spec/S02-builtin_data_types/array_exten 21 1 19 |
From justin.sahs@gmail.comMight help if i actually attached a patch :-| |
From justin.sahs@gmail.comfixes.patchdiff --git a/src/builtins/control.pir b/src/builtins/control.pir
index 30ba345..4a17f9c 100644
--- a/src/builtins/control.pir
+++ b/src/builtins/control.pir
@@ -224,16 +224,23 @@ src/builtins/control.pir - control flow related functions
ex['type'] = .CONTROL_TAKE
ex['severity'] = .EXCEPT_NORMAL
ex['message'] = 'take without gather'
-
$I0 = elements values
if $I0 == 0 goto nil
if $I0 > 1 goto many
- values = values[0]
+ $P0 = values[0]
+ values = clone $P0
goto done
nil:
values = '&Nil'()
goto done
many:
+ $I1 = 0
+ many_loop:
+ $P0 = values[$I1]
+ $P1 = clone $P0
+ values[$I1] = $P1
+ $I1 = $I1 + 1
+ if $I1 < $I0 goto many_loop
values = '&infix:<,>'(values :flat)
done:
setattribute ex, 'payload', values
diff --git a/src/core/operators.pm b/src/core/operators.pm
index 7e02233..960227f 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -306,14 +306,24 @@ our multi sub item($item) {
class Whatever { ... }
-# the magic one that handles stuff like
-# 'a' ... 'z' and 'z' ... 'a'
-our multi sub infix:<...>($lhs, $rhs) {
+our multi sub infix:<scmp>($lhs, $rhs) {
+ $lhs cmp $rhs;
+}
+
+our multi sub infix:<scmp>(Str $lhs, Str $rhs) {
+ $lhs.chars <=> $rhs.chars || $lhs cmp $rhs;
+}
+
+our multi sub infix:<scmp>($lhs, @rhs) {
+ $lhs scmp @rhs[0];
+}
+
+our multi sub infix:<...>($lhs is copy, $rhs) {
if $rhs ~~ Whatever {
my $i = $lhs;
return gather {
loop {
- my $j = $i++;
+ my $j = $i.succ;
take $j;
}
}
@@ -321,35 +331,28 @@ our multi sub infix:<...>($lhs, $rhs) {
gather {
take $lhs;
- if ($lhs cmp $rhs) == 1 {
- my $x = $lhs;
- # since my $a = 'a'; $a-- gives
- # "Decrement out of range" we can't easily
- # decrement over our target, which is why the
- # case of going backwards is slighly more complicated
- # than going forward
- while (--$x cmp $rhs) == 1 {
- # need to make a fresh copy here because of RT #62178
- my $y = $x;
- take $y;
- }
- take $x if ($x cmp $rhs) == 0;
- } elsif ($lhs cmp $rhs) == -1 {
- my $x = $lhs;
- while (++$x cmp $rhs) <= 0 {
- my $y = $x;
- take $y;
- }
+
+ if $lhs scmp $rhs == 1 {
+ # here, we use '== 1' instead of '>= 0'
+ # because my $a = 'a'; $a-- gives
+ # "Decrement out of range"
+ take $lhs while --$lhs scmp $rhs == 1;
+ take $lhs if $lhs scmp $rhs == 0;
+ }
+ elsif $lhs scmp $rhs == -1 {
+ take $lhs while ++$lhs scmp $rhs <= 0;
}
if $rhs ~~ Iterable {
- for @($rhs) {
- take $_;
- }
- }
+ # the first element has already been taken
+ # should be:
+ # take $_ for $rhs[1..*]; but this doesn't work yet
+ take $_ for $rhs[{1..$_-1}];
+ }
}
}
+
# our multi sub infix:<...>($lhs, Code $rhs) {
# if $rhs.count != 1 {
# die "Series operator currently cannot handle blocks with count != 1";
@@ -368,24 +371,6 @@ our multi sub infix:<...>($lhs, $rhs) {
# }
# }
# }
-#
-# our multi sub infix:<...>(@lhs, Whatever) {
-# given @lhs.elems {
-# when 2 {
-# @lhs[0] ... { $_ + (@lhs[1] - @lhs[0]) };
-# }
-# when 3 {
-# if @lhs[1] - @lhs[0] == @lhs[2] - @lhs[1] {
-# @lhs[0] ... { $_ + (@lhs[1] - @lhs[0]) };
-# } elsif @lhs[1] / @lhs[0] == @lhs[2] / @lhs[1] {
-# @lhs[0] ... { $_ * (@lhs[1] / @lhs[0]) };
-# } else {
-# fail "Unable to figure out pattern of series";
-# }
-# }
-# default { fail "Unable to figure out pattern of series"; }
-# }
-# }
our multi sub infix:<...>(Code $lhs, $rhs) {
my $limit;
@@ -407,17 +392,17 @@ our multi sub infix:<...>(Code $lhs, $rhs) {
our multi sub infix:<...>(@lhs is copy, $rhs) {
my sub succ-or-pred($lhs, $rhs) {
if $rhs ~~ Whatever || $lhs cmp $rhs != 1 {
- -> $x { $x.succ };
+ *.succ;
} else {
- -> $x { $x.pred };
+ *.pred;
}
}
my sub succ-or-pred2($lhs0, $lhs1, $rhs) {
if $lhs1 cmp $lhs0 == 0 {
- $next = { $_ };
+ { $_ };
} else {
- $next = succ-or-pred($lhs1, $rhs);
+ succ-or-pred($lhs1, $rhs);
}
}
@@ -487,6 +472,13 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
}
}
}
+
+ if $rhs ~~ Iterable {
+ # the first element has already been taken
+ # should be:
+ # take $_ for $rhs[1..*]; but this doesn't work yet
+ take $_ for $rhs[{1..$_-1}];
+ }
}
}
|
justin.sahs@gmail.com - Status changed from 'new' to 'open' |
From @cokeOn Wed Jun 16 09:05:34 2010, ciphertext wrote:
Sorry, this branch has been deleted. If these fixes are still relevant, we'd love a patch against the latest (nom) branch. Thanks, sorry -- |
@coke - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#75810 (status was 'rejected')
Searchable as RT75810$
The text was updated successfully, but these errors were encountered: