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

Keyword arguments

1 view
Skip to first unread message

Piers Cawley

unread,
Nov 6, 2002, 7:44:39 AM11/6/02
to perl6-l...@perl.org
So, I was, thinking about the way Common Lisp handles keyword
arguments. It's possible to declare a Lisp function as follows:

(defun make-para ( content &key alignment font size color ) ...)

The point here is that the first argument is dealt with positionally,
and subsequent, optional args are dealth with as keyword arguments. It
seems to me that similar functionality might sit well with Perl 6, but
I'm not sure I can think of a good declaration syntax. Calling syntax
is easy:

make_para $text, font => 'Helvetica,Arial,Whatever';

Any thoughts?

--
Piers

"It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite."
-- Jane Austen?

Austin Hastings

unread,
Nov 6, 2002, 10:36:55 AM11/6/02
to Piers Cawley, perl6-l...@perl.org
I think Damian already covered this: it's the semicolon.

sub mysub(String $content; int $key, int $align)
{
...
}

sub callmysub
{
mysub("Testing .. 1, 2, 3!"; key => 1024, align => Module::RIGHT);
}

Which, upon reflection, apparently introduces an "implicit hashparsing"
context for autoquoting hashkeys.

=Austin


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/

Luke Palmer

unread,
Nov 6, 2002, 10:56:21 AM11/6/02
to pdca...@bofh.org.uk, perl6-l...@perl.org
> Mailing-List: contact perl6-lan...@perl.org; run by ezmlm
> From: Piers Cawley <pdca...@bofh.org.uk>
> Date: Wed, 06 Nov 2002 12:44:39 +0000
> X-SMTPD: qpsmtpd/0.12, http://develooper.com/code/qpsmtpd/

>
> So, I was, thinking about the way Common Lisp handles keyword
> arguments. It's possible to declare a Lisp function as follows:
>
> (defun make-para ( content &key alignment font size color ) ...)
>
> The point here is that the first argument is dealt with positionally,
> and subsequent, optional args are dealth with as keyword arguments. It
> seems to me that similar functionality might sit well with Perl 6, but
> I'm not sure I can think of a good declaration syntax. Calling syntax
> is easy:
>
> make_para $text, font => 'Helvetica,Arial,Whatever';
>
> Any thoughts?

Sure. It already does that. But only if the caller feels like it.
If you can remember the order of all those arguments, great, but if
you can't, you can use keywords.

sub make_para($text; $alignment, $font, $size, $color) {...}

Can be called in a lot of ways, one of which you wrote above.

I sure hope it doesn't complain that you didn't specify alignment. I
guess that's what exists() is for.

Luke

Paul Johnson

unread,
Nov 6, 2002, 12:06:39 PM11/6/02
to Austin_...@yahoo.com, austin_...@yahoo.com, pdca...@bofh.org.uk, perl6-l...@perl.org

Austin Hastings said:

> sub callmysub
> {
> mysub("Testing .. 1, 2, 3!"; key => 1024, align => Module::RIGHT);
> }
>
> Which, upon reflection, apparently introduces an "implicit hashparsing"
> context for autoquoting hashkeys.

Those are pairs, aren't they?

--
Paul Johnson - pa...@pjcj.net
http://www.pjcj.net

Piers Cawley

unread,
Nov 6, 2002, 12:55:44 PM11/6/02
to Paul Johnson, Austin_...@yahoo.com, perl6-l...@perl.org
"Paul Johnson" <pa...@pjcj.net> writes:

> Austin Hastings said:
>
>> sub callmysub
>> {
>> mysub("Testing .. 1, 2, 3!"; key => 1024, align => Module::RIGHT);
>> }
>>
>> Which, upon reflection, apparently introduces an "implicit hashparsing"
>> context for autoquoting hashkeys.
>
> Those are pairs, aren't they?

Yup.

0 new messages