Can a simple a==b 'hang' in and endless loop?
Claudio Grondi
claudio.grondi at freenet.de
Thu Jan 19 10:58:41 EST 2006
Fuzzyman wrote:
> (If I understand correctly...)
>
> The reason he is looking for it, is in order to assert that Python
> 'comparison' is broken.
a bit this way, but why formulate it with such a negative touch?
Lets understand it more as looking for a way to get a deep understanding
of the concept behind the Python '==' operator (and many other things
related to it) and a way to explain it to a C programmer (because it
differs from the concept he knows from C). If it should turn out, that
there is some inconsistency in the Python concept it will become
apparent why and then it can be discussed further or even lead to a PEP
and everyone here will profit from this. If it turns out that there is
no inconsistency, one more Python user (i.e. me :-) ) will get deep
understanding of this Python concept and maybe can help others seeking
same enlightenment.
>
> Part of this is because of his assertation that the term 'value' has no
> meaning in Python.
This seems to me still to be true, but lets postpone the discussion of
it (which should first give a definition what 'value' means in Python)
and about if it makes sense to use this term to describe something which
is far away from the common understanding of it to another thread and a
later time when I get even more clear picture about it as it is the case
now.
>
> He bases this on the fact that Java and C define 'value' to mean the
> pointer when the object is mutable.
I base it on the fact, that a value is what is actually stored in memory
in a data structure which can be reached used a name (i.e. an
identifier). This way of understanding what value means allows to
distinguish between memory content (the value) and memory address
(represented by the name of the variable). The concept of the pointer in
C does not change the meaning of the term value, because there is a
value a pointer has (i.e. there is data in memory addressed by the
variable name which is the pointer) and that this value means here an
address is another beer (leading to much confusion when learning to work
with pointers in C).
By the way: please don't mix Javascript and Java - these are two totally
different things. Java is a programming language you can compile for a
Java VM, Javascript is the interpreted scripting language used for
scripting of HTML where its Windows version JScript is a full featured
scripting engine like Python is. I haven't mentioned Java as I know only
very little about it, I have mentioned Javascript (JScript) I am much
more experienced with.
>
> In fact Python defines value much more clearly. Value is *obviously*
> type dependent. (This is why in Python you can implement your own
> comparison methods).
>
> For integers and floats, Python defines the value to be the numerical
> value.
>
> For strings it defines it to be the contents of the string.
>
> For mutable objects it defines it to be the contents of the object, if
> the object types are the same. i.e. [1] == [1], [1] != (1,)
>
> For user defined classes, you are able to build your own definition of
> value into the object - this doesn't prevent stupidity.
>
> Python doesn't have a comparison operator analagous to his reference
> languages - but IMHO Python is better here. He can achieve what he
> wants by subclassing the built in datatypes and overriding the
> comparison methods to behave as he desires.
You seem here to try to give a definition of the term 'value' for
Python. If I understand it right, the definition of the term can't be
generally given for many reasons. It depends at least on type and in
advanced usage it can be arbitrary defined or changed.
That is why I mean, that it makes no sense to talk in Python about
value. I see not much sense in taking existing term in order to redefine
it for a new context - the result is always increase of confusion. Let
give it another name in order to know, that it must be defined for the
context it is used before it becomes meaningful.
Any suggestions?
Claudio
More information about the Python-list
mailing list