Op 24-09-17 om 04:13 schreef Steve D'Aprano: >> and consider >> that something else has to happen as an alternative, and (2) understand >> that in Python, objects don't have names, they have references (which >> have names). The rest could be "implementation dependent" (no?) > No. > > There are many different alternatives for "something else", and while some of > them may be behave the same in some circumstances, they do not behave the same > in all circumstances. Any interpreter calling itself Python would be expected > to match the behaviour of the reference implementation, CPython. > > For example, if I made "Pass-By-Reference Python" where all argument passing > was > done by reference, my language would differ from real Python:
Can you explain, what you mean by "Pass-By-Reference" as far a I understand, pass by reference means that the parameter of the function becomes an alias of the argument, so that if the entity is mutated through one name that mutation is visible through the other name. > function(x, y) # allowed > function(namespace.x, module.y) # allowed > function(x + 1, 2) # FORBIDDEN: can't pass expressions or constants Pass by reference, doesn't imply the above is forbidden. A language can define, that the "x + 1" will produce an new entity and that a reference to that entity will be passed. > Obviously that's not Python! > > On the other hand, "Pass-By-Name Python" would allow passing expressions and > constants, but will differ in other ways. > > Assignment by reference would mean that name binding was an *alias* operation: It is. > module.y = 1 > x = module.y # x is an alias for the name "module.y" > x = 2 # binds 2 to module.y The comment in the above statement is wrong. You ignore the fact that the assignment is an alias operation and so that through the assignment x now becomes a new alias for the value 2. Your statement should be: x = 2 # x is now an alias for an object with value 2. Your comment would have been true, if that assignment would have been a copy-over assignment. This is a confusion I see you make regularly. When making statements about what effect reference parameters or an alias operation would have, you at some point depend on the assignment being a copy-over operation, as you did here. The fact that assignment is an *alias* opertation is illustrated by the fact that a mutation through one name, is visible through the other name. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list