3

This works:

my &Moves::shuffle = -> *@deck {
    @deck.pick: *;
}


say Moves::shuffle( "As de bastos", "3 de oros", "Sota de espadas" );

This does not:

sub Moves::shuffle( *@deck ) {
    return @deck.pick: *;
}


say Moves::shuffle( "As de bastos", "3 de oros", "Sota de espadas" );

And it fails with: Could not find symbol '&shuffle'

Any idea why?

jjmerelo
  • 19,108
  • 5
  • 33
  • 72
  • 3
    This also works: `package Moves { our sub shuffle( *@deck ) { @deck.pick: * } }` – Håkon Hægland May 01 '19 at 08:57
  • 4
    See also [Perl6: load functions into other namespace](https://stackoverflow.com/q/45770133/2173773) – Håkon Hægland May 01 '19 at 09:05
  • 1
    I could swear I read a comment by jnthn discussing thorny aspects constraining what can reasonably be done related to whether non-leaf package names (i.e. all but last in something like `non-leaf::non-leaf::leaf`) result in creating the non-leaf package hierarchy if it doesn't already exist. But my search of the issue queues of rakudo/rakudo, perl6/doc, and perl6/nqp repo drew a blank. One [comment that looked like it might possibly be relevant](https://github.com/rakudo/rakudo/issues/2126#issuecomment-412838181) closed with "the current mechanism has come to resemble a house of cards". – raiph May 11 '19 at 14:35

0 Answers0