terminological obscurity

Donn Cave donn at u.washington.edu
Fri May 21 20:19:26 EDT 2004


In article <slrncastid.5mc.grante at grante.rivatek.com>,
 Grant Edwards <grante at visi.com> wrote:

> On 2004-05-21, Donn Cave <donn at u.washington.edu> wrote:
> 
> >> For example, why shouldn't index() find an object in a
> >> non-homogeneous sequence? Either the object is in the sequence or
> >> it's not. If it is, there is an index that corresponds to it.
> >
> > For example,
> >   tm = time.localtime(time.time())
> >   i = tm.index(5)
> >
> > What would that mean?
> >
> > It's absurd to search for the location of a value in a tuple,
> > because the values don't have any meaning independent of their
> > location.
> 
> OK, I see what you mean.  That brings up the question of why
> use integer indexes to access members of of a group of objects
> when the order of the objects is meaningless?

I would somewhat strictly speaking say, sure, order is
not ordinarily applicable to tuples, but only in the sense
that it describes a _relative_ position, as in "after" or
"before".  That's the way lists work, not tuples.

But of course absolute position is vitally important in a
tuple, as actually implemented in Python.  I am guessing
that your question is basically, why use a sequence at
all, and not a collection of attributes & values like a
dict or class.

If course that's done - we can and do sometimes use a
dict or class instead.  But then you don't get unpacking,
like for k, v in dict.items() ...   And this same pattern
occurs on other languages, notably Haskell which has all
three types - a (head:tail) list, a tuple (rarely more than
two or three long), and a struct.  The tuple is usually
evaluated in a pattern match analogous to unpacking.

I think positional structure can be pretty useful, not
necessarily inferior to attributes & values in every case.
I understand that crows can count to three - if they're
watching people enter and leave from a shed, they can keep
track as long as there aren't more than three at a time.
Maybe our cognitive abilities with tuples isn't much greater,
but within those limits they work well.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list