Re: Semantics of ==
Erik Max Francis <max@alcyone.co m>[color=blue]
> Axel Boldt wrote:
>[color=green]
> > I couldn't find that algorithm in the language reference, only in 5.9:
> > "Tuples and lists are compared lexicographical ly using comparison of
> > corresponding elements. This means that to compare equal, each element
> > must compare equal and the two sequences must be of the same type and
> > have the same length."
> >
> > That definition doesn't seem to fully specify equality of list values:
> > ...[/color]
>
> Sure it does; the rule can be used recursively.[/color]
....and then it can run into an infinite loop. I explained that for the
example s==w in the part you deleted. The recursion does not always
have a base case; the rule does not always give a definite truth
value.
[color=blue][color=green]
> > I hope that the
> > actual result received, i.e. s==w, is not implementation dependent?[/color]
>
> They're also equal in Jython. It wouldn't surprise me if you could find
> an implementation where they might not compare equal, because this is
> such a pathological case.[/color]
.... i.e. such a fun case. If there really is an implementation
dependency hidden in something as fundamental as == for lists, that'd
better be mentioned in the language reference.
[color=blue][color=green]
> > Is there a string
> > function analogous to pickle.dumps or repr which only takes values
> > into account, not internal structure?[/color]
>
> How can you define the value of an arbitrary object without reference to
> its internal structure?[/color]
Well, you claim that s and w have the same value yet different
internal structure, so you must work with some definition of "value"
that's different from internal structure. I don't know what it is, and
the language reference doesn't fully specify it.
I.e., I'm interesting in a function val : lists -> strings with the
property val(l1) == val(l2) iff l1 == l2. That would also considerably
clarify the semantics of == for lists, which I still don't understand.
Axel
Erik Max Francis <max@alcyone.co m>[color=blue]
> Axel Boldt wrote:
>[color=green]
> > I couldn't find that algorithm in the language reference, only in 5.9:
> > "Tuples and lists are compared lexicographical ly using comparison of
> > corresponding elements. This means that to compare equal, each element
> > must compare equal and the two sequences must be of the same type and
> > have the same length."
> >
> > That definition doesn't seem to fully specify equality of list values:
> > ...[/color]
>
> Sure it does; the rule can be used recursively.[/color]
....and then it can run into an infinite loop. I explained that for the
example s==w in the part you deleted. The recursion does not always
have a base case; the rule does not always give a definite truth
value.
[color=blue][color=green]
> > I hope that the
> > actual result received, i.e. s==w, is not implementation dependent?[/color]
>
> They're also equal in Jython. It wouldn't surprise me if you could find
> an implementation where they might not compare equal, because this is
> such a pathological case.[/color]
.... i.e. such a fun case. If there really is an implementation
dependency hidden in something as fundamental as == for lists, that'd
better be mentioned in the language reference.
[color=blue][color=green]
> > Is there a string
> > function analogous to pickle.dumps or repr which only takes values
> > into account, not internal structure?[/color]
>
> How can you define the value of an arbitrary object without reference to
> its internal structure?[/color]
Well, you claim that s and w have the same value yet different
internal structure, so you must work with some definition of "value"
that's different from internal structure. I don't know what it is, and
the language reference doesn't fully specify it.
I.e., I'm interesting in a function val : lists -> strings with the
property val(l1) == val(l2) iff l1 == l2. That would also considerably
clarify the semantics of == for lists, which I still don't understand.
Axel
Comment