A question on modification of a list via a function invocation

Rustom Mody rustompmody at gmail.com
Tue Sep 5 10:08:56 EDT 2017


On Tuesday, September 5, 2017 at 7:12:48 PM UTC+5:30, Rustom Mody wrote:
> On Tuesday, September 5, 2017 at 6:42:07 PM UTC+5:30, Gregory Ewing wrote:
> > Steve D'Aprano wrote:
> > > The third entity is the reference linking the name to the object (the arrow).
> > > This isn't a runtime value in Python, nor is it a compile time entity that
> > > exists in source code. It is pure implementation, and as such, exists outside
> > > of the Python domain.
> > 
> > The fact that there is a connection between the name and the
> > object is very much part of Python's abstract semantics.
> > 
> > There are different ways to implement that connection, but
> > *any* implementation of Python has to include *some*
> > representation of it.
> > 
> > There are also different words that can be used to describe
> > it. You can say that names are bound to objects, or that
> > names refer to objects, or that names hold references to
> > objects. These are all equally good ways of talking about
> > the exact same abstract concept.
> > 
> > To me this argument about whether Python has references
> > or not is like an American person saying that cars have
> > hoods, and a British person saying he's wrong, hoods
> > are an implementation detail and cars actually have
> > bonnets instead.
> 
> Also called playing humpty-dumpty
> 
> I believe there is a germ of value behind all this empty polemics 
> There are 3 equivalence relations:
> 1. == — mathematical, too coarse to understand nuances of python semantics
> 2. is — machine representation, too fine to be useful
> 3. graph (or topological) equality which experienced pythonistas have internalized 
> in understanding when two data structures are same or different
> [Roughly Anton's diagrams that are beyond my drawing capability!]
> 
> 
> And yet pythonistas need that to understand python data structures
> 
> >>> a = [1,2]
> >>> b = [a,a]
> >>> c = [[1,2],[1,2]]
> >>> b == c
> True
> >>> b is c
> False
> >>> p = [1,2]
> >>> q = [p,p]
> >>> r = [[1,2],[1,2]]
> >>> q == r
> True
> >>> q is r
> False
> >>> b == q
> True
> >>> b == r
> True
> >>> b is q
> False
> >>> b is r
> False

To make it more clear
Suppose ≡ is graph-equal. The pythonista understands that
b ≢ c ## ≡ is finer than ==
Whereas
b ≡ r
ie ≡ is coarser than is

Its another matter that the name 'is' makes these discussions much harder in python
than in equivalent languages like java, lisp, javascript etc
by making the mostly unnecessary and irrelevant 
"is machine-rep same" sound the same(!) as "is conceptually same"



More information about the Python-list mailing list