9

Consider

.say for (1,2,2).rotor(2=>-1).map( -> ($a, $b) { $a - $b })

which works as expected. However,

.say for (1,2,2).pairs.rotor(2=>-1).map( -> ($a, $b) { $a.value - $b.value })

throws

Too few positionals passed to '<anon>'; expected 2 arguments but got 0 in sub-signature

Is this a bug or am I missing something?

This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d.

Holli
  • 5,072
  • 10
  • 27

2 Answers2

8

It is taking the Pair as a Capture, thus turning the Pair into a named argument:

$ raku -e '(a => 42, b => 666).map: -> |c { dd c }'
\(:a(42))
\(:b(666))

In your example, it then doesn't pass any positional arguments, thus causing the observed execution error.

jnthn++ for pointing this out.

Elizabeth Mattijsen
  • 25,654
  • 3
  • 75
  • 105
0

btw - I was wondering why |c and not \c ... from the doc...

Inside a Signature, a Capture may be created by prefixing a sigilless parameter with a vertical bar |. This packs the remainder of the argument list into that parameter.

librasteve
  • 6,832
  • 8
  • 30