/
positional.t
41 lines (32 loc) 路 999 Bytes
/
positional.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use v6;
use Test;
plan 7;
sub my_first ($x, $, $ ) { $x };
sub my_second ($, $x, $ ) { $x };
sub my_third ($, $, $x) { $x };
is my_first( 4, 5, 6), 4, '($x, $, $) works as a signature';
is my_second(4, 5, 6), 5, '($, $x, $) works as a signature';
is my_third( 4, 5, 6), 6, '($, $, $x) works as a signature';
# RT #60408
{
sub rt60408 {
return { @_.join };
}
is rt60408().(1, 2, 3), '123', '@_ belongs to the inner-most block';
}
{
sub f(@a, $i) {
$i ~ "[{map { f($_, $i + 1) }, @a}]"
};
is f([[], [[]], []], 0), "0[1[] 1[2[]] 1[]]",
'recusion and parameter binding work out fine';
}
# using "special" variables as positional parameters
{
# RT #77054
sub dollar-underscore($x, $y, $_, $z) { "$x $y $_ $z"; }
is dollar-underscore(1,2,3,4), '1 2 3 4', '$_ works as parameter name';
sub dollar-slash($x, $/, $y) { "$x $<b> $y" }
is dollar-slash(1, { b => 2 }, 3), '1 2 3', '$/ works as parameter name';
}
# vim: ft=perl6