Op 04-09-17 om 17:43 schreef Steve D'Aprano: > On Tue, 5 Sep 2017 01:17 am, Rustom Mody wrote: > >> Anton gave a picture explaining why/how references are needed and to be >> understood > Antoon gave a picture demonstrating one model of Python's semantics. > > It's a nice model that has a lot going for it, in particular that it matches > the > most obvious implementation. But it doesn't describe *Python* semantics, it > describes an overlap between Python the language and the implementation of the > Python interpreter. > > In particular, consider the picture of a name binding to a value: > > > +-----+ > | | > | 5 | > | | > +-----+ > ^ > | > <x> > > > This picture has three entities, but only two of them exist in Python: > > - the object 5; > > - the name "x" (names are not values in Python at runtime, but they > are entities which exist in Python source code at compile time). > > 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. > > I'm not saying that we should never use this model. Its a good model. But we > should be clear that it is a model of the implementation, and it describes > entities which are not part of the Python language. We cannot do this: > > > +-----+ > | | > | 5 | > | | > +-----+ > ^ > | > <x> > ^ > | > <y> > > > or any of the other things we can do in a language with references-as-values, > like C or Pascal.
I don't agree that the above is an accurate picture of C or Pascal. It is more like the following: +-----+ +-----+ | | | | | 5 |<----+--* | | | | | +-----+ +-----+ ^ ^ | | <x> <y> And in case of a VAR parameter in Pascal like procedure f(VAR x); f(y) one could use the following, which is the same as after an assignment in python. +-----+ | | | 7 | ---> | | / +-----+ / / ^ / | <x> <y> -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list