osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A question on modification of a list via a function invocation


Rustom Mody wrote:
> 2. is ? machine representation, too fine to be useful

No, it's *not* machine representation. As I pointed out before,
it's part of the abstract semantics of Python.

And it's not "too fine to be useful". On the contrary, being
aware of which objects are the same and which aren't is vital
to writing Python programs that behave in the intended way.

> 3. graph (or topological) equality

> 3 captures pythonistas intuition of same better than 1 or 2

I don't think so, see below.

>>>>a = [1,2]
>>>>b = [a,a]
>>>>c = [[1,2],[1,2]]

>>>>p = [1,2]
>>>>q = [p,p]
>>>>r = [[1,2],[1,2]]

> Now the pythonista understands that b and c may be math-= but have different structure
> Whereas b is graph-equal to q
> And c is graph-equal to r
> 
> However there is no available operation to show/see that distinction

Because usually it's not particularly important to know
whether two separate structures have the same topology.

On the other hand, it *is* important to know things
such as 'b[0] is b[1]' but 'c[0] is not c[1]', because
it makes a difference to what happens if you mutate
any of those.

> The trouble is that graph-isomorphism is NP-complete so the crucial operation
> cannot be reasonably implemented

We're fortunate that it's not actually a crucial
operation, then. :-)

-- 
Greg