[Zope-Perl] Python void context

Gisle Aas gisle@ActiveState.com
26 May 2000 17:46:10 +0200


Chris McDonough <chrism@digicool.com> writes:

> It occurs to me that you could define a context default keyword argument
> to the Perl function e.g.
> 
> obj.func(1,2,context="list")
> obj.func(1,2,context="scalar")
> obj.func(1,2,context="void")
> 
> Where func's signature defines context as a default:
> 
> func(self, arg1, arg2, context="list")
> 
> This seems to be the 'pythonic' way of dealing with such a thing.  I'm
> not sure how you're implementing a Perl function wrapper, so I'm not
> sure if this suits you.

Currently I just ignore keyword arguments so this is doable.  It might
be in conflict with other mappings of keyword arguments that we want
to do insted, but reserving some namesspace like __*, i.e. use
__context="list" etc. should be ok.

We might pass keyword arguments directly to perl as either a hash
reference or simply as key value pairs after the other arguments.
That means a function declared as:

   sub foo {
       my($a, $b, %args) = @_;
       ...
   }

could be called from python as

   foo(1, 2, foo=3, bar=4)

In this case the '=' will basically be treated like ",", but is kind
of ok since that is just what perl's '=>' actually is.  The bad thing
about this is that python programmers might expect

   foo(b = 3, foo = 3, a = 1, bar=4)

to actually work (pass the same arguments as above).

--Gisle