New Python User Question about Python.

Grant Griffin not.this at seebelow.org
Mon Aug 27 17:51:41 EDT 2001


In article <3B8A930D.BC2B4C92 at home.net>, Chris says...
>
...
>Better yet: I'd love to see Python add homogenous sequences as a
>concept. First the concept, which could be used by extension modules to
>make type checking a whole lot easier, and perhaps ultimately in the
>interpreter to make list comprehensions and the like much faster. First
>the infrastructure, then, hopefully, the actual optimisations.
>
>There may be major flaws with my homogenous sequence idea, but I have
>been unable to coax thoughtful analysis out of any of the truly
>knowledgeable folks in this group so far. Maybe it's such a stupid idea
>that no one bothers...

Naw, it's not a stupid idea.  Python already supports that for various numeric
types in a way that's somewhat, though not completely general, via NumPy and the
"array" module.  The problem is, I'm not sure how you make it _completely_
general by providing something like NumPy's "universal functions" which operate
on the sequence as a whole (and whose speed is drawn from the assumption of
homogeny.)

In a sense, Python's list and tuple types already are homegenous, because they
hold only one type: PyObject.  Of course, a PyObject can seem like many
different objects, but it's still a PyObject.  So if you're suggesting, for
example, a list that could only hold strings, I'm not sure there would be much
benefit as long as the string is still a PyObject: then, we still have a list of
PyObjects.  However, if that list held some _different_ kind of string, for
example, C-style strings (which aren't PyObjects), it might be useful--but only
if it comes with useful operations that you can do to the whole list, e.g.
strip, uncapitalize, etc.

Problem is, that adds two new data types: C-strings and C-string-lists.  But one
important design feature of Python is its very small set of basic types.  Like
its other minimization of features, this makes it easier to learn and use, and
more portable.  (In contrast, C/C++ provides a zillion combinations.)

Also, given its small set of types, Python can cheat by providing a syntax to
implicitly declare the types of variables:

   x = 1
   x = 1.0
   x = 1.0+1.0j
   x = {}
   x = []

but this becomes awkward to extend beyond its current few types.  So the only
thing to do would be to more formally declare the new types.

Anyway, I guess what I'm saying is that homogenous sequences aren't a bad idea,
they just don't fit into Python in a completely general way.  To me, it seems
like homogenous sequences of numeric and character types are about the only
things that fit, and that's already been done.

the-squareness-of-the-peg-and-the-roundness-of-the
  hole-does-not-reflect-badly-on-either-ly y'rs,

=g2

_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation            http://www.iowegian.com




More information about the Python-list mailing list