[Zope-Perl] Mixing perl arrays with python lists

Gisle Aas gisle@ActiveState.com
13 Jun 2000 12:04:55 +0200


I have a python extension type that wraps a perl array.  The extension
type make sure that such wrapped up perl arrays can be operated (from
python) the same way as python lists, i.e. allow item subscription,
taking slices, assigning to slices as well as implementing the list
methods (append, pop, index, reverse,...)

If python calls a perl function that returns an array reference, then
such a wrap up will be the result.  You might also get it by taking
explicit references to stuff inside the perl name space,
e.g. perl.get_ref("@INC").

The question is: Should perl arrays allow python lists (and tuples) to
be used as arguments to its functions or should we require the other
argument(s) to always be another perl array thingy.

   array = perl.get_ref("@")    # gives you a new empty array
   array[:] = [1,2,3];          # should this be allowed

The python way seems to be to never allow mixing types and to provide
the functions list() and tuple() to do explicit conversions where you
want them to be allowed.  I could do something similar and provide a
perl.array() that turns any sequence object into a new perl array.
That would make the example above:

   array[:] = perl.array([1,2,3])

The same thing also applies for the relationship between perl hashes
and python dicts.  Should hash.update({...}) be allowed?

As the perl person I am, I tend to want to allow any argument that
makes sense.  Is this the wrong thing to do?  After all, this is the
API that python programmers see, and they seem to want exceptions to
occur at every possible opportunity :-)

Regards,
Gisle