Fw: Python sequences by reference - how to make
I vowed not to make a mission of my copy import issue. And in my mind am living with it. But I do think it is an intersting point to discuss. Happens the the Quote of the Week from this weeks Dr Dobbs weekly Python URL http://www.ddj.com/topics/pythonurl/ is a Martelli quote that is from his response to the same post from Michal to python-list that instigating the discussion here. QOTW: "When something "is *EVERYWHERE*", how can it be "clearly VISIBLE" at the same time?" - Alex Martelli http://mail.python.org/pipermail/python-list/2002-September/123526.html A slightly fuller excerpt: """ *EVERY* assignment in Python uses reference semantics. Every occurrence of an assignment, therefore, makes reference behavior "clearly VISIBLE". Presumably fish don't find water "clearly VISIBLE", being used to that, much as it is for us and air. When something "is *EVERYWHERE*", how can it be "clearly VISIBLE" at the same time?-) """ Is it possible that "copy" clearly in the game as a built_in makes us slightly more amphibious? Hate to think that Martelli's suggestion that math types might need to stick with languages that implement a more uniformly functional model, is the only answer to this issue. Art
At 08:57 AM 9/25/2002 -0400, Arthur wrote:
Hate to think that Martelli's suggestion that math types might need to stick with languages that implement a more uniformly functional model, is the only answer to this issue.
Art
re: http://mail.python.org/pipermail/python-list/2002-September/123526.html Martelli's answer was quite interesting, as it mixes in a lot of history about computer languages. His main point is that assignment by reference, vs. assignment by copy, is the trend in modern languages, and being stuck on a copy-based semantics is not intrinsically a "math thing" -- it's just a habit of thought. This quote seems to argue against your suggestion: "You're in water. Water is *everywhere*. When you think there is nothing there, there's water. Just get used to it. Trying to muddy up the water in an attempt to make it more visible would be counter-productive." [fixed a typo] I think when we teach Python, the assignment-by-reference idea has to be made very clear:
a = [1, 2, 3] thelist = [a,a,a] # same as [a]*3 a[0]=42 thelist # there's only one list in this picture [[42, 2, 3], [42, 2, 3], [42, 2, 3]] b = a # b also points to a's list
id(a) # id() could be used when showing the identity 11095040
id(b) 11095040
a[0] = 92 thelist = [a,b,a] # still only one list here [[92, 2, 3], [92, 2, 3], [92, 2, 3]]
So how do we get another copy of a to play with?
from copy import copy b = copy(a) # now b points to its own list a[1] = 17 a [92, 17, 3] b # b is unchanged [92, 2, 3]
So back to our original example (with copy still available):
a = [1,2,3] thelist = [a,copy(a),copy(a)] a[0] = 42 thelist [[42, 2, 3], [1, 2, 3], [1, 2, 3]]
Stuff like that. I think one could argue that "teaching by changing the list of built-ins" is too subtle to really make newbies notice. Beginners don't necessarily know how to get a list of what's built in. How would they know 'copy' is even present? They rely on a book to tell them, which book then goes through each feature. But if you're relying on a book or tutorial, then the same source might as well give examples of what's *not* a built in, e.g. copy. I'd think the math people would be especially easy to educate: just as you must import sin, cos, log, so must you import copy, i.e. lots of functionality is in the libraries (same with C, same with Java, same all modularized languages). Kirby
Is it possible that "copy" clearly in the game as a built_in makes us slightly more amphibious?
The only example that came up here so far was the issue of initializing a multi-dimensional array properly, which cannot be solved with copying alone. Copying issues generally crop up with lists. Copying a list is done with [:]. You can't get much more built-in than that. --Guido van Rossum (home page: http://www.python.org/~guido/)
Guido writes -
Copying issues generally crop up with lists. Copying a list is done with [:]. You can't get much more built-in than that.
It seems clear you object to an approach to discssing this kind of thing that is highly rhetorical. And as I said before, I acknowledge that *I* am the one out of water. But maybe that's the point a little. Using Alex's anology I would argue that [:], from the perspective of a fish, does represent somethingof an underwater rock formation. A fish does know that everything is not water. But [:] still gives us no sight of land. Art
Interesting quotes.. thanks. http://mail.python.org/pipermail/python-list/2002-September/123526.html "Python uses reference semantics. When you want a copy, you ask for a copy -- it's as simple as this. If you don't ask for a copy, you don't get a copy... you get a reference to the original. There is no complication: it's _always_ this way. " - Alex Martelli That's a really helpful explanation. He writes so well :-)
Presumably fish don't find water "clearly VISIBLE", being used to that, much as it is for us and air. When something "is *EVERYWHERE*", how can it be "clearly VISIBLE" at the same time?-)
[OT] I am not questioning the Python copy() suggestions, but regarding fish in water, and people in air, don't you think it is also always and everywhere a matter of context and degree? It's fun to extend the analogy to how are are with this programming stuff.. Water is not just water, as Air is not just air. Very deep sea fish effectively live without sunlight, though often with other photo/electro-phoresence of other species. [cf. 'lantern fish']. They develop some very strange physical forms to adapt. sound, smell, taste, current temperature. http://people.whitman.edu/~yancey/deepsea.html Mid-depth fish must be more aware of light. But yes still spend 100% of their lives in water. Surface fish many of them know well here the edges are. water vs. surface + air People despite spending their lives in air, are likewise conscious to a greater or lesser degree, thanks to our senses. Clean air, fresh air, hayfevers, humidity, old icy air, hot dust, sea breezes, city air mountain air, [stinky new york august air], etc.. As kids we are fascinated with holding our breath, putting our heads in plastic bags, going in closets etc. Firemen, smokers and sick or dying people have another more serious sensibility. Athletes, swimmers and lovers celebrate consciousness of existence and air. Meditation practices focus on the essence and meaning of breath - in/out, who we are, and how time, mind and body are affected. regards ./Jason
participants (4)
-
Arthur -
Guido van Rossum -
Jason Cunliffe -
Kirby Urner