Using the following code:
use v6d;
# sub circumfix:<α ω>( @a ) {
# @a[0] >= @a[1] & @a[0] <= @a[2];
# };
sub circumfix:<α ω>( $a, $b, $c ) {
$a >= $b & $a <= $c;
};
if (α <5 0 10> ω) {
say 'Truthy';
}
else {
say 'Falsey';
}
Results in:
(base) hsmyers@BigIron:~/board$ perl6 ./op.p6
Too few positionals passed; expected 3 arguments but got 1
in sub circumfix:<α ω> at ./op.p6 line 7
in block <unit> at ./op.p6 line 11
Whereas switching the commented block for the other definition results in:
(base) hsmyers@BigIron:~/board$ perl6 ./op.p6
Truthy
The broken version (with three parameters) is the one I want, could someone explain why it is broken?
<5 0 10>
literally constructs a List
, a single List
.
An analogy would be a list of things to do, a todo list. How many things is a todo list? It's 1 -- one todo list.
Thus you get the error message:
expected 3 arguments but got 1
What you want is to specify that you want one value that is itself made up of several values. Here's one way to do that:
sub circumfix:<α ω>( ( $a, $b, $c ) ) ...
The additional surrounding (
and )
cause destructuring.
D:\>6e "say <5 0 10>"
(5 0 10)
These aren't three arguments. It's a list of three values (of type IntStr
) and therefore a single argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With