Skip to content

Instantly share code, notes, and snippets.

@prakashk
Created May 20, 2010 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prakashk/408099 to your computer and use it in GitHub Desktop.
Save prakashk/408099 to your computer and use it in GitHub Desktop.
### the patch passes the following tests :)
#?rakudo todo 'unicode'
{ # distribution for unary prefix
my @r;
@r = -« ([1, 2], [3, [4, 5]]);
my @e = ([-1, -2], [-3, [-4, -5]]);
is(~@r, ~@e, "distribution for unary prefix");
@r = -<< ([1, 2], [3, [4, 5]]);
@e = ([-1, -2], [-3, [-4, -5]]);
is(~@r, ~@e, "distribution for unary prefix, ASCII");
};
#?DOES 3
#?rakudo todo 'non-unicode hypers'
{ # distribution for binary infix - ASCII
my @r;
@r = (1, 2, [3, 4]) >>+<< (4, 5, [6, 7]);
my @e = (5, 7, [9, 11]);
is(~@r, ~@e, "distribution for binary infix, same shape, ASCII");
@r = (1, 2, [3, 4]) >>+>> (5, 6, 7);
@e = (6, 8, [10, 11]);
is(~@r, ~@e, "distribution for binary infix, dimension upgrade, ASCII");
@r = ([1, 2], 3) <<+>> (4, [5, 6]);
@e = ([5, 6], [8, 9]);
is(~@r, ~@e, "distribution for binary infix, S03 cross-upgrade, ASCII");
};
#?DOES 3
#?rakudo todo 'unicode hypers'
{ # distribution for binary infix - unicode
my @r;
@r = (1, 2, [3, 4]) »+« (4, 5, [6, 7]);
my @e = (5, 7, [9, 11]);
is(~@r, ~@e, "distribution for binary infix, same shape");
@r = (1, 2, [3, 4]) »+» (5, 6, 7);
@e = (6, 8, [10, 11]);
is(~@r, ~@e, "distribution for binary infix, dimension upgrade");
@r = ([1, 2], 3) «+» (4, [5, 6]);
@e = ([5, 6], [8, 9]);
is(~@r, ~@e, "distribution for binary infix, S03 cross-upgrade");
};
### but, breaks the following tests :(
{ # unary postfix
my @r = (1, 2, 3);
try { @r»++ };
my @e = (2, 3, 4);
#?pugs todo
is(~@r, ~@e, "hyper auto increment an array");
@r = (1, 2, 3);
try { @r>>++ };
@e = (2, 3, 4);
#?pugs todo
is(~@r, ~@e, "hyper auto increment an array ASCII notation");
};
not ok 15 - hyper auto increment an array
# got: "1 2 3"
# expected: "2 3 4"
not ok 16 - hyper auto increment an array ASCII notation
# got: "1 2 3"
# expected: "2 3 4"
#?rakudo todo 'unicode'
{ # distribution for unary postfix autoincrement
my @r;
@r = ([1, 2], [3, [4, 5]]);
try { @r»++ };
my @e = ([2, 3], [4, [5, 6]]);
#?pugs todo
is(~@r, ~@e, "distribution for unary postfix autoincr");
@r = ([1, 2], [3, [4, 5]]);
try { @r>>++ };
@e = ([2, 3], [4, [5, 6]]);
#?pugs todo
is(~@r, ~@e, "distribution for unary postfix autoincr, ASCII");
};
not ok 46 - distribution for unary postfix autoincr# TODO unicode
# got: "1 2 3 4 5"
# expected: "2 3 4 5 6"
not ok 47 - distribution for unary postfix autoincr, ASCII# TODO unicode
# got: "1 2 3 4 5"
# expected: "2 3 4 5 6"
Index: t/spec/S03-metaops/hyper.t
===================================================================
--- t/spec/S03-metaops/hyper.t (revision 30688)
+++ t/spec/S03-metaops/hyper.t (working copy)
@@ -223,7 +223,7 @@
is(~@r, ~@e, "hyper-method-call on list of user-defined objects");
};
-#?rakudo skip 'unicode'
+#?rakudo todo 'unicode'
{ # distribution for unary prefix
my @r;
@r = -« ([1, 2], [3, [4, 5]]);
@@ -235,7 +235,7 @@
is(~@r, ~@e, "distribution for unary prefix, ASCII");
};
-#?rakudo skip 'unicode'
+#?rakudo todo 'unicode'
{ # distribution for unary postfix autoincrement
my @r;
@r = ([1, 2], [3, [4, 5]]);
@@ -252,7 +252,7 @@
};
#?DOES 3
-#?rakudo skip 'non-unicode hypers'
+#?rakudo todo 'non-unicode hypers'
{ # distribution for binary infix - ASCII
my @r;
@r = (1, 2, [3, 4]) >>+<< (4, 5, [6, 7]);
@@ -269,18 +269,18 @@
};
#?DOES 3
-#?rakudo skip 'unicode hypers'
+#?rakudo todo 'unicode hypers'
{ # distribution for binary infix - unicode
my @r;
@r = (1, 2, [3, 4]) »+« (4, 5, [6, 7]);
my @e = (5, 7, [9, 11]);
is(~@r, ~@e, "distribution for binary infix, same shape");
- @r = (1, 2, [3, 4]) »+« (5, 6, 7);
+ @r = (1, 2, [3, 4]) »+» (5, 6, 7);
@e = (6, 8, [10, 11]);
is(~@r, ~@e, "distribution for binary infix, dimension upgrade");
- @r = ([1, 2], 3) »+« (4, [5, 6]);
+ @r = ([1, 2], 3) «+» (4, [5, 6]);
@e = ([5, 6], [8, 9]);
is(~@r, ~@e, "distribution for binary infix, S03 cross-upgrade");
};
@@ -338,7 +338,7 @@
ok ?(@a »|« @b), '»|« hyperjunction evals';
ok ?(@a >>|<< @b), '>>|<< hyperjunction evals, ASCII';
ok ?(@a »&« @b), '»&« hyperjunction evals';
- ok ?(@a >>&<< @b), '»&« hyperjunction evals, ASCII';
+ ok ?(@a >>&<< @b), '>>&<< hyperjunction evals, ASCII';
}
# test hypers on hashes
--- a/src/core/metaops.pm
+++ b/src/core/metaops.pm
@@ -88,7 +88,11 @@ our multi sub hyper(&op, Iterable $lhs-iterable, Iterable $rhs-iterable, :$dwim-
my @result;
for @lhs Z @rhs -> $l, $r {
- @result.push(op($l, $r));
+ if $l ~~ Iterable || $r ~~ Iterable {
+ @result.push(hyper(&op, $l.list, $r.list, :$dwim-left, :$dwim-right).list);
+ } else {
+ @result.push(op($l, $r));
+ }
}
@result
}
@@ -100,7 +104,11 @@ our multi sub hyper(&op, $lhs, $rhs, :$dwim-left, :$dwim-right) {
our multi sub hyper(&op, @arg) {
my @result;
for @arg {
- @result.push(op($_));
+ if $_ ~~ Iterable {
+ @result.push(hyper(&op, $_).list);
+ } else {
+ @result.push(op($_));
+ }
}
@result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment