PDD 03 Issue: keyword arguments
Python provides the ability for any function to be called with either positional or keyword [1] arguments. Here is a particularly brutal example: args={'a':1,'b':2,'c':3} def f(a,b,c): return (a,b,c) def g(b,c,a): return (a,b,c) for j in [f,g]: print j(1,2,3) for j in [f,g]: print j(a=1,b=2,c=3) for j in [f,g]: print j(*args.values()) for j in [f,g]: print j(**args) I see nothing in pdd 03 that provides any guidance as to how to handle this. What makes this issue so critical is that any solution will potentially affect *every* function. - Sam Ruby P.S. Jython handles the above test correctly. Iron-Python handles all but the **args properly. [1] http://docs.python.org/ref/calls.html
Keyword arguments
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?
Re: Keyword arguments
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 --- Piers Cawley [EMAIL PROTECTED] wrote: 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? __ Do you Yahoo!? HotJobs - Search new jobs daily now http://hotjobs.yahoo.com/
Re: Keyword arguments
Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm From: Piers Cawley [EMAIL PROTECTED] Date: Wed, 06 Nov 2002 12:44:39 + 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
Re: Keyword arguments
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 - [EMAIL PROTECTED] http://www.pjcj.net
Re: Keyword arguments
Paul Johnson [EMAIL PROTECTED] 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. -- 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?