Maybe first explain why the error:
When you specify a Pair as such as an argument, it is interpreted as a *named*
argument.
$ raku -e 'sub a(|c) { dd c }; a b => 42'
\(:b(42))
So thus you can see why the error is thrown: you passed 0 positional arguments
to the subroutine, and it never gets to report the fact that you passed one
unexpected named argument.
There's several ways to fix the problem:
xxx Pair.new("key","value"); # be explicit about sending a Pair
xxx (key => "value"); # add parentheses to break the syntactic
sugar for named arguments
The latter option also shows that whitespace *can* be significant in Raku:
xxx(key => "value"); # same error
In Raku, an identifier directly followed by a parens open, means calling that
object of that identifier, with the arguments specified. And then you know
that "xxx foo" is really syntactic sugar for "xxx(foo)".
Again, it is all about *reading* the error message. Is there room for
improvement? There always is!
> On 2 Jan 2022, at 08:34, Marc Chantreux <[email protected]> wrote:
>
> hello rakoons,
>
> I got this error message
>
> Too few positionals passed; expected 1 argument but got 0
> in sub xxx at - line 1
> in block <unit> at - line 2
>
> Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.09.
> Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.
> Built on MoarVM version 2021.09.
>
> by running this:
>
> <<\-. raku; raku -v
> sub xxx ( Pair $test ) { $test.raku.say }
> xxx key => 'value';
>
> and i think it's worth a bug: i don't know if
>
> xxx key => 'value'
>
> should parse but at least it deserve a less
> confusing message, don't you think ?
>
> regards
> marc