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

E6 question

6 views
Skip to first unread message

Mark J. Reed

unread,
Aug 1, 2003, 11:44:55 AM8/1/03
to perl6-l...@perl.org
Is it possible with the new parameter declaration syntax to declare
a mandatory name-only parameter?

-Mark

Luke Palmer

unread,
Aug 1, 2003, 12:14:09 PM8/1/03
to mark...@turner.com, perl6-l...@perl.org
> Is it possible with the new parameter declaration syntax to declare
> a mandatory name-only parameter?

Not directly, no. However, some trickyness with macros would probably
let you do it. I don't yet understand macros well enough to show
you...

Luke

> Mark

Damian Conway

unread,
Aug 1, 2003, 5:52:59 PM8/1/03
to perl6-l...@perl.org
Mark J. Reed wrote:

> Is it possible with the new parameter declaration syntax to declare
> a mandatory name-only parameter?

Probably. I think that the '?', '*', and '+ prefixes are abbreviations for
traits (C<is optional>, C<is List>, C<is optional is named>). So a named,
mandatory parameter would be:

sub foo($bar is named) {...}

Alternatively, you could just specify a mandatory parameter that has to be a Pair:

sub foo(Pair $bar) {...}

(though then you'd have to use C<$bar.value> for the value).

Damian

John Siracusa

unread,
Aug 3, 2003, 6:01:03 PM8/3/03
to Perl 6 Language
On 8/1/03 11:44 AM, Mark J. Reed wrote:
> Is it possible with the new parameter declaration syntax to declare
> a mandatory name-only parameter?

My earlier plea for this feature begins here:

http://archive.develooper.com/perl6-l...@perl.org/msg14666.html

I didn't think I made much headway, but this...

On 8/1/03 5:52 PM, Damian Conway wrote:
> Probably.

...is encouraging :)

> I think that the '?', '*', and '+ prefixes are abbreviations for
> traits (C<is optional>, C<is List>, C<is optional is named>). So
> a named, mandatory parameter would be:
>
> sub foo($bar is named) {...}

Good, but a single-letter prefix would also be nice :)

> Alternatively, you could just specify a mandatory parameter that has to be a
> Pair:
>
> sub foo(Pair $bar) {...}
>
> (though then you'd have to use C<$bar.value> for the value).

Ick.

-John

0 new messages