On Fri, Nov 15, 2019, at 10:48, Richard Damon wrote: > On 11/15/19 6:56 AM, R.Wieser wrote: > > There are quite a number of languages where /every/ type of argument > > (including values) can be transfered "by reference". Though some default > > to > > "by value", where others default to "by reference". > > It seems you are stuck in a programming model different than what Python > provides, In a very real sense, the terms call "By Reference" and "By > Value" don't apply to Python. Those concepts presume that a variable > name represents a bucket of bytes that holds some value, and call by > value copies those bytes into a new variable for the subroutine, and > call by Reference creates a pointer value back to original value, and > all uses of that parameter work indirect that pointer. > > That is NOT how Python works. In Python, in effect, every name in your > code is just a reference which points to some object (This is called > binding). Multiple names can point to the same object (or no names, at > which point the object is subject to being garbage collected). Names > themselves aren't objects, so you can't really make one name refer to > another, only to the same object that the other one does. (In actuality, > these collections of names are implemented basically in a Dictionary, so > using this sort of implementation details you can sort of get that > result, but I don't think that is defined to work in the language).
Being abstractly typed objects rather than a bucket of bytes, and having the values themselves be a kind of reference or pointer (though to immutable data in some important cases), does not in fact change the meaning of the "call by reference" concept or its applicability. It would be entirely reasonable, I think, in the python model, to provide a way for making a variable a cell variable, passing the cell object around explicitly, and having the called function automatically set/get the value when the argument is accessed. I don't think it would solve the OP's problem, since his talk about automatically "inheriting" the caller's variable of the same name sounds a lot more like dynamic scope than call by reference. -- https://mail.python.org/mailman/listinfo/python-list