arnsholt / snake

Not Quite Python
9 stars 1 forks source link

Keyword arguments to calls #6

Open arnsholt opened 9 years ago

arnsholt commented 9 years ago

Python doesn't really have keyword arguments (except when it does), only positionals. Thus, a call like foo(a=1) actually passes the value of argument a in its positional slot. The only case where keyword args have an independent existence is when a function has a **excess parameter to contain names not already defined in the parameter list.

Thus, we need some kind of binder process, either converting nameds to positionals or positionals nameds. Of course, this has to interact properly with default values and the like.

arnsholt commented 9 years ago

The solution to this might be a custom HOW for function objects. The call handler can then stuff the right things into the right places, and the object can also carry around the default values to parameters.

arnsholt commented 9 years ago

One potential way to do this:

A function object is supposed to have a member defaults containing the default values. A call handler can then nqp::clone that to get the default values. Next, populate actually passed values into the call arguments (there's no standard member with a name -> position mapping, but the inspect standard module needs it anyways). Once everything is set up, nqp::call(_args, *_excess_kw) or something along those lines.

There are still some things (mostly related to the semi-predicate problem, I think) to get checking of calls exactly right, though. But this should get us some things.