At 10:29 PM -0500 11/30/04, Sam Ruby wrote:
Python provides the ability for any function to be called with either positional or keyword [1] arguments. Here is a particularly brutal example:

Oh, it's even more brutal than that. Perl 6 goes one step further, such that you can't tell whether a name/value pair is a keyword or positional parameter at the time you make the call, and can potentially be either with MMD. (There's a reason I've been hiding from this one) Each potential keyword parameter is a name/value pair (of type Pair), but whether it's to be taken as a keyword fillin or a positional parameter depends on the called sub. For example:


   foo(b => 1, a=> 2)

is a keyword call if foo's prototype is:

   sub foo($a, $b)

or

   sub foo(Integer $a, Integer $b)

but is a positional call if the prototype is:

   sub foo(Pair $a, Pair $b)

and if the prototype is

   sub foo(Pair $a, Integer $b)

I think I get to smack someone with a stick.

Anyway, this is... complex, or at least hurts my brain, but it's time to deal with it.

My first thought is this scheme:

All potential keyword parameters (that is, name/value pairs) are passed in as PMCs of type Pair. (Pairs will need to have some sort of funky vtable to allow them to act mostly like their value, I think, to make this work right) The called sub, if it cares to do named arg parsing, will then go process the passed in parameters and Do The Right Thing with them, presumably stuffing values into the right spots and yelling if things aren't right.

It feels like something of a cheat, but I'm OK with cheating with this if we set up the right protocol and provide support for it. (Like some sort of library routine or opcode to handle shuffling the keyword parameters into the right spots, and we probably ought to have it provide optional typechecking while we're at it)
--
Dan


--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to