*%overflow

0 views
Skip to first unread message

Luke Palmer

unread,
Aug 21, 2005, 5:39:20 PM8/21/05
to Perl6 Language List
Output?

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

Ingo Blechschmidt

unread,
Aug 21, 2005, 5:52:09 PM8/21/05
to perl6-l...@perl.org
Hi,

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! |

Stuart Cook

unread,
Aug 21, 2005, 8:55:18 PM8/21/05
to Perl6 Language List
On 22/08/05, Luke Palmer <lrpa...@gmail.com> wrote:
> Output?
>
> sub foo (+$a, *%overflow) {
> say "%overflow{}";
> }
>
> foo(:a(1), :b(2)); # b 2
> foo(:a(1), :overflow{ b => 2 }); # b 2

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

Reply all
Reply to author
Forward
0 new messages