Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

named arguments: What's the signature?

6 views
Skip to first unread message

Mark Stosberg

unread,
Aug 29, 2006, 9:28:13 PM8/29/06
to perl6-l...@perl.org

Regarding The S06 description of named arguments:
http://feather.perl6.nl/syn/S06.html#Named_arguments

What I find missing here is documentation of the signature to use
if you want to declare "I accept an arbitrary number of named
arguments". (Like the param() methods common in Perl5 do).

Maybe it's the slurpy hash?

sub foo (*%h) {...} ?

The spec could use some clarification on this point.

Mark

Trey Harris

unread,
Aug 29, 2006, 8:37:31 PM8/29/06
to Mark Stosberg, perl6-l...@perl.org

I think it's already there:

Slurpy parameters follow any required or optional parameters. They are
marked by a C<*> before the parameter:

sub duplicate($n, *%flag, *@data) {...}

Named arguments are bound to the slurpy hash (C<*%flag>
in the above example). Such arguments are evaluated in scalar context.
Any remaining variadic arguments at the end of the argument list
are bound to the slurpy array (C<*@data> above) and are evaluated
in list context.

Trey

Stuart Cook

unread,
Aug 29, 2006, 8:43:59 PM8/29/06
to Mark Stosberg, perl6-l...@perl.org
On 8/30/06, Mark Stosberg <ma...@summersault.com> wrote:
> Regarding The S06 description of named arguments:
> http://feather.perl6.nl/syn/S06.html#Named_arguments
>
> What I find missing here is documentation of the signature to use
> if you want to declare "I accept an arbitrary number of named
> arguments". (Like the param() methods common in Perl5 do).

Go down one section and read "List parameters". (I agree that it's not
particularly explicit, and there probably should be a mention of it
under "Named parameters".)

A06 also says:

"A hash declaration like *%named indicates that the %named hash should
slurp up all the remaining named arguments (that is, those that aren't
bound explicitly to a specific formal parameter)."

This description should probably be copied to the Synopsis.

> Maybe it's the slurpy hash?
>
> sub foo (*%h) {...} ?

Correct.


Stuart

Mark Stosberg

unread,
Aug 29, 2006, 10:25:14 PM8/29/06
to perl6-l...@perl.org
Trey Harris wrote:
>
>
> Slurpy parameters follow any required or optional parameters. They are
> marked by a C<*> before the parameter:
>
> sub duplicate($n, *%flag, *@data) {...}
>
> Named arguments are bound to the slurpy hash (C<*%flag>
> in the above example). Such arguments are evaluated in scalar context.
> Any remaining variadic arguments at the end of the argument list
> are bound to the slurpy array (C<*@data> above) and are evaluated
> in list context.

So would this mean zero or more" pairs of named arguments, or one or more:

sub foo (*%h)

I expected this:

sub foo (*%h) # one more pairs
sub foo (*%h?) # zero or more pairs

The answer with pugs now is different:

sub foo (*%h) # zero or more pairs
sub foo (%h, *%h), # one or more pairs

If pugs behavior is intended, I think it should be documented in the
spec, as I found unintuitive.

Mark

0 new messages