Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Add &prefix:<|> to flatten arrays into positional arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Nov 12, 2009
1 parent 5ea3604 commit 8c211fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -494,6 +494,15 @@ method arglist($/) {
}
else { $past.push($expr); }
}
my $i := 0;
my $n := +$past.list;
while $i < $n {
if $past[$i].name eq '&prefix:<|>' {
$past[$i] := $past[$i][0];
$past[$i].flat(1);
}
$i++;
}
make $past;
}

Expand Down
1 change: 1 addition & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -417,6 +417,7 @@ token prefix:sym<~> { <sym> <O('%symbolic_unary, :pirop<set S*>')> }
token prefix:sym<-> { <sym> <![>]> <O('%symbolic_unary, :pirop<neg>')> }
token prefix:sym<?> { <sym> <O('%symbolic_unary, :pirop<istrue>')> }
token prefix:sym<!> { <sym> <O('%symbolic_unary, :pirop<isfalse>')> }
token prefix:sym<|> { <sym> <O('%symbolic_unary')> }

token infix:sym<*> { <sym> <O('%multiplicative, :pirop<mul>')> }
token infix:sym</> { <sym> <O('%multiplicative, :pirop<div>')> }
Expand Down
15 changes: 15 additions & 0 deletions t/nqp/41-flat.t
@@ -0,0 +1,15 @@
#!./parrot nqp.pbc

# flattened arguments

plan(3);

sub xyz($x, $y, $z) {
ok( $x == 7, 'first argument');
ok( $y == 8, 'second argument');
ok( $z == 9, 'third argument');
}

my @a := [7,8,9];
xyz(|@a);

0 comments on commit 8c211fe

Please sign in to comment.