sub foo (+$a, *%overflow) {
say "%overflow{}";
}
foo(:a(1), :b(2)); # b 2
foo(:a(1), :overflow{ b => 2 }); # b 2
foo(:a(1), :overflow{ b => 2 }, :c(3)); # ???
Luke
Luke Palmer wrote:
> sub foo (+$a, *%overflow) {
> say "%overflow{}";
> }
>
> foo(:a(1), :b(2)); # b 2
> foo(:a(1), :overflow{ b => 2 }); # b 2
I'd think so, too.
> foo(:a(1), :overflow{ b => 2 }, :c(3)); # ???
Error: Too many arguments passed to &foo?
Presuming that multiple *%slurpy_hashes are allowed, I'd say that...
sub bar (+$a, *%overflow, *%real_overflow) {
say "[%overflow{}] [%real_overflow{}]";
}
bar(:a(1), :overflow{ b => 2 }); # [b 2] []
bar(:a(1), :overflow{ b => 2 }, :c(3)); # [b 2] [c 3]
But it seems to be cleaner to disallow multiply *%slurpies and just go
with the error.
--Ingo
--
Linux, the choice of a GNU | "The future is here. It's just not widely
generation on a dual AMD | distributed yet." -- William Gibson
Athlon! |
I would have thought:
overflow b 2
i.e. %overflow<overflow> = (b => 2)
Because :overflow() is an unrecognised named argument, so it goes in the slurpy
hash. The fact that the hash has the same name as the argument is a
coincidence--does it make sense to explicitly name a slurpy when you can just
splat *{ b => 2 } in directly?
> foo(:a(1), :overflow{ b => 2 }, :c(3)); # ???
overflow b 2
c 3
Of course, that's just my way of thinking.
(Also, last I heard you /could/ have multiple slurpy hashes, but any after the
first would always be empty.)
Stuart