tuple.index()

J. Clifford Dyer webmaster at cacradicalgrace.org
Tue Dec 19 14:41:45 EST 2006


Nick Maclaren wrote:
> In article <em9aq9$2tn$1 at aioe.org>,
> "J. Clifford Dyer" <webmaster at cacradicalgrace.org> writes:
> |> 
> |> On the contrary, I think that example fits perfectly with my definition
> |> of homogenous.  If there is no constraint on position, then what is the
> |> position determinative of?  Order in the queue.  Nothing more.  By my
> |> definition, homogeneous.  QED.
> |> 
> |> I'll grant, it's not exactly the most intuitive definition of
> |> homogenous, but I think it is the most accurate for this situation.
> |> Perhaps homogenous and heterogenous aren't the best possible words here,
> |> but I think they work.
> 
> Grrk.  I see what you mean.  The homogeneity is referring to the order
> and not to the types :-)

Thank you.  The more I tried to explain it, the more I was losing the
sense of the actual words "homogeneous" and "heterogenous" in this
context, but that helps me recapture it.  It made so much sense until I
tried to articulate it...

> 
> |> By my definition, how can it be mutable AND heterogenous?  If the first
> |> element is a name, the second element is a phone number, and the third
> |> element is an email address, and you insert an element in between the
> |> first two elements, do you mean to tell me that the phone number, which
> |> has moved to the third slot, is now an email address?  It doesn't make
> |> sense.
> 
> Well, I could provide an example, but they are a bit weird.  More
> seriously, consider changing a structure consisting of a name and
> telephone number, and then changing the value of the latter (not
> exactly an unreasonable requirement!)  With tuples that can't be done,
> but it makes perfect sense, and it is a mutable heterogeneous sequence
> with your definition.
>

Good example.  Of course, an immutable sequence can be made up of
mutable elements, but a string (which you'd probably use for a telephone
number or an email address) isn't one of those types.

> |> Maybe the words are wrong.  I'm not sure.  But I think the distinction
> |> is valid.  Furthermore, I think we "lists are intended to be homogenous"
> |> people would say that you are perfectly welcome to use lists for other
> |> purposes, if it suits you.  Just as you can use a string as a list.  We
> |> don't have to be rigid to appreciate the difference.  :)
> 
> Nope.  That is DEFINITELY wrong.  If you write code that abuses a
> language construct in a way that is discouraged but just happens to
> work, a couple of decades down the line it will stop working, because
> someone will change the feature.  Been there - been caught by that :-(
> 

Yeah, that could suck.  Personally, I can't picture such a basic
construct as a list or a tuple ever being given such a restrictive
meaning.  If you ask me what a list is (in python), I would never say "a
list is a homogeneous sequence."  I would say "a list is a mutable
sequence," as I believe the language reference defines it.  (No
citation).  If you then asked me why we have separate mutable and
immutable sequences, THAT's when I'd bring up homogeneity and
heterogeneity.  So I wouldn't say you were misusing the structure for
making a homogeneous tuple, as long as you didn't try to mutate it.  Or
that you were misusing a list if you really needed a mutable
heterogeneous sequence (like for changing phone numbers).  The mapping
from heterogeneous to immutable is helpful, but not perfect, nor
normative.  However, if more powerful minds disagree with me, that's
when you'd get in trouble.

Cheers,
Cliff

> 
> Regards,
> Nick Maclaren.



More information about the Python-list mailing list