Joe Strout wrote: > ru...@yahoo.com wrote: > >> "the same as anyone else's" only if [Python's] "idea >> of assignment" does not include producing the same >> results. >> >> a = array (1,2,3) >> b = a >> a[1] = 4 >> print b >> >> C, C++, VBA, Fortran, Perl: 1, 2, 3 >> Python: 1, 4, 3 > > You are mistaken
I don't think so. See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 The code I quoted there was tested. In the C/C++ case, array-to-pointer coercion confuses the issue so I embedded the array in a struct which is more like an "object". The assignment semantics are copy-like producing the results I quoted. (Keep in mind my point was not to show the behavior of arrays, but to show that several common languages *do not* use Python's "*all* names are references" model -- though of course this does not preclude their having some Python-like assignments since they all have some way of doing references.) It seems plausible to me that experience with copy-like assignments semantics in other languages accounts for the frequent misunderstanding of Python assignments that is seen on this list. > (except perhaps in the Fortran case, which is an > oddball by modern standards, and I don't know Perl well enough to judge). Whether or not Perl is oddball or modern is irrelevant; it is still widely used and it is reasonable to assume that there are a significant number of people coming to Python with a lot of previous experience with Perl. Even Fortran is still used in scientific computing circles (or so I'm told) although I can't say I have seen any c.l.p. postings from people claiming Python doesn't work like fortran. :-) > C/C++ code: > > int* a = malloc(3); > a[0] = 1; > a[1] = 2; > a[2] = 3; > int* b = a; > a[1] = 4; > print_array(b) > ---> Result: 1, 4, 3 > > REALbasic code: > > Dim a() As Integer = Array(1,2,3) > Dim b() As Integer = a > a(1) = 4 > PrintArray b > --> Result: 1, 4, 3 > > VB.NET code would be very similar in syntax, and identical in behavior, > to the REALbasic code. Don't know about RealBasic or VB.Net, my experience and quoted results were from MS Visual Basic for Apps which is (I think) based on VB6. -- http://mail.python.org/mailman/listinfo/python-list