On Wed, 14 Dec 2005, Steven D'Aprano wrote: > On Tue, 13 Dec 2005 15:28:32 +0000, Tom Anderson wrote: > >> On Tue, 13 Dec 2005, Steven D'Aprano wrote: >> >>> On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote: >>> >>> [snippidy-doo-dah] >>> >>>> I had the same thought, but reread the post. He asks "if a given >>>> variable is a character or a number". I figured that even if he is >>>> coming from another language he knows the difference between "a given >>>> variable" and the "contents of a give variable". I guess we will >>>> see.... ;-). This list is so good, he gets BOTH questions answered. >>> >>> The problem is, Python doesn't have variables (although it is >>> oh-so-tempting to use the word, I sometimes do myself). It has names in >>> namespaces, and objects. >> >> In what sense are the names-bound-to-references-to-objects not variables? > > Because saying "Python has variables" leads to nonsense like the following: > > [snip] >>> That's why, for instance, Python is neither call by reference nor call >>> by value, it is call by object. >> >> No, python is call by value, and it happens that all values are >> pointers. > > All values in Python are pointers???
Right. > So when I write: > > name = "spam spam spam spam" > > the value of the variable "name" is a pointer, and not a string. Riiight. Right. > Call by value and call by reference have established meanings in > computer science, Right. > and Python doesn't behave the same as either of them. Wrong. Python behaves exactly like call by value, just like Smalltalk, Objective C, LISP, Java, and even C. > Consider the following function: > > def modify(L): > "Modify a list and return it." > L.append(None); return L > > If I call that function: > > mylist = range(10**10) # it is a BIG list > anotherlist = modify(mylist) > > if the language is call by value, mylist is DUPLICATED before being > passed to the function. Wrong. The value of mylist is a pointer to a list, and that's what's passed to the function. The same analysis applies to the rest of your example. > The conceptual problem you are having is that you are conflating the > object model of Python the language with the mechanism of the underlying > C implementation, which does simply pass pointers around. No, i'm not, i'm really not. Thinking in terms of variables, pointers and objects is a simple, consistent and useful abstract model of computation in python. If you like, we can use the word 'reference' instead of 'pointer' - i guess a lot of people who came from C (which i didn't) are hung up on the idea that a pointer is a memory address, rather than just a conceptual thing which goes from a variable to an object; the trouble is that then we remind people of 'call by reference', and it all goes to pot. I think the background thing is the kicker here. I'm guessing you come from C, where pointers are physical and explicit, you can have a variable which really does contain an object, etc, and so for you, applying those terms to python is awkward. I come from java, where all pointers are abstract (in the sense of being opaque) and implicit, and variables only ever contain pointers (unless they're primitive - but that's an implementation detail), so the terminology carries over to python quite naturally. >> I'm sure this has been argued over many times here, and we still all >> have our different ideas, so please just ignore this post! > > I'd love to, but unfortunately I've already hit send on my reply. Fair enough. Sorry about all this. In future, i'm going to send posts which i *know* will generate heat but no light straight to /dev/null ... tom -- The literature, especially in recent years, has come to resemble `The Blob', growing and consuming everything in its path, and Steve McQueen isn't going to come to our rescue. -- The Mole -- http://mail.python.org/mailman/listinfo/python-list