probably worth a bug report ?
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 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
Re: probably worth a bug report ?
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 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 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
Re: probably worth a bug report ?
Le Sun, Jan 02, 2022 at 12:32:46PM +0100, Elizabeth Mattijsen a รฉcrit : > Maybe first explain why the error thanks for the explaination. especially > $ raku -e 'sub a(|c) { dd c }; a b => 42' > \(:b(42)) now my sub works the way I wanted: sub got (|c) { for c.hash.kv -> $rule ,$input { ok (my $r = Pugish.subparse: $input , :$rule ) , "match a $rule in: $input"; $r and return $r; } } got pair => 'obey the law'; > Again, it is all about *reading* the error message. > Is there room for improvement? There always is! I wrote this message mostly because the error message didn't help at all here but now i discovered and inspected the Capture, i realize the message was true but just left me clueless. Capture is a good way to understand what happened. > > Too few positionals passed; expected 1 argument but got 0 because c.list got is all ... many thanks for helping. marc
Re: probably worth a bug report ?
cf https://www.nntp.perl.org/group/perl.perl6.users/2021/04/msg9883.html -- love, raiph On Sun, Jan 2, 2022 at 7:35 AM Marc Chantreux 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 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