Re: Tuples vs Lists: Semantic difference (was: Extract String From Enclosing Tuple)

2007-03-01 Thread MonkeeSage
On Mar 1, 5:02 am, [EMAIL PROTECTED] wrote:
> I don't know Ruby, but I think it allows such purposes with a freezing
> function.

In ruby all objects can be frozen (freeze is a method on Object, from
which all other objects derive), not just Arrays (Arrays == lists in
python; ruby has no built-in container equiv. to tuple). But that's
more of an implementation detail rather than anthing to do with the
structure/semantics of a certain type of object (e.g., a String can be
frozen, a Hash can be frozen, &c).

Regards,
Jordan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuples vs Lists: Semantic difference (was: Extract String From Enclosing Tuple)

2007-03-01 Thread bearophileHUGS
George Sakkis, I agree with the things you say.
Sometimes you may have a sequence of uniform data with unknown len (so
its index doesn't have semantic meaning). You may want to use it as
dict key, so you probably use a tuple meant as just an immutable list.
I don't know Ruby, but I think it allows such purposes with a freezing
function.

Bye,
bearophile

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuples vs Lists: Semantic difference (was: Extract String From Enclosing Tuple)

2007-02-28 Thread George Sakkis
On Feb 28, 10:45 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:

> Bjoern Schliessmann <[EMAIL PROTECTED]> writes:

> > I know tuples as immutable lists ...
>
> That's a common misconception.

And this catch phrase, "that's a common misconception", is a common
aping of the BDFL's take on this. As several long threads have shown,
it is a highly controversial topic and claiming that one side has
misconceived it doesn't make it more true than a Catholic claiming
that Protestants are misconceived about the True Christianity or vice
versa.

> Tuples are intended for use as heterogeneous data structures: every
> index in the sequence *means* something, a semantic meaning applied to
> the item at that index. It's for this reason that a tuple is
> immutable: removing items, inserting them in the middle, etc. would
> imply that the index doesn't have semantic meaning for the structure,
> which is not true.
>
> Lists are intended for use as homogeneous sequences: not that every
> value is of the same type, but that a particular index in the sequence
> doesn't *mean* anything about the semantic interpretation of the item
> at that position. It's for this reason that a list is mutable: since
> the index of an item has no semantic meaning, inserting new items or
> removing them from anywhere in the sequence doesn't alter the meaning
> of the structure.
>
> James Tauber explains further:
>
> 
> http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constan...>

Nice, that's a good summary of the straw man arguments about the
"true" distinction between tuples and lists. Now can you please
explain why an "heterogeneous data structure":
1) does not support __setitem__, changing the value of an existing
item from 3 to 4,
2) supports iteration over its ("heterogeneneous") elements, but not
an index() method, and
3) why using indices rather than names for implied semantics is a good
idea anyway.

As for addition/removal/insertion of elements not making sense for a
heterogeneous data structure, have you heard of database schema
change ?

Heterogeneous data structures are well known for several decades now;
they are commonly spelled "records" though, not tuples, and have a
more reasonable API to support their semantics.

George

-- 
http://mail.python.org/mailman/listinfo/python-list