Issue500539
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2002-01-07 20:15 by arkoenig, last changed 2022-04-10 16:04 by admin. This issue is now closed.
Messages (7) | |||
---|---|---|---|
msg8632 - (view) | Author: Andrew Koenig (arkoenig) | Date: 2002-01-07 20:15 | |
Section 9.2 paragraph 3 defines a namespace as a mapping from names to objects. Perhaps I'm being picky here, but isn't a namespace a mapping from names to object references? For example, doesn't executing the expression "modname.the_answer = 42" as shown in paragraph 5 cause modname.the_answer to refer to a different object than the one to which it referred previously, rather than affecting the specific object to which modname.the_answer refers? |
|||
msg8633 - (view) | Author: Fred Drake (fdrake) | Date: 2002-01-08 15:20 | |
Logged In: YES user_id=3066 There is no difference between an object reference and an object in Python code, so the statement in the tutorial is correct. The behavior you are describing as "object" behavior seems to assume that there's some sort of assignment which mutates the object which is the current value of the assignment target, but there is no such operator. I can see where this might be confusing for programmers coming from C++, though. ;-) |
|||
msg8634 - (view) | Author: Andrew Koenig (arkoenig) | Date: 2002-01-08 16:22 | |
Logged In: YES user_id=418174 Actually, I was saying the opposite. Executing "x = 42" certainly does not mutate the object that was previously associated with x, but rather causes x to be associated with a new object, namely 42. To me that suggests that 42 is an object and x is something else, perhaps a way of accessing an object. You are right that this kind of confusion is common among people who write about C++, but you are not right that I used C++ as the basis for my original comment. I first became aware of the importance of distinguishing between objects and object references in Algol 68, many years before C++ ever existed, and there is a wonderful piece in Lewis Carroll's ``Through the Looking Glass'' about this very issue. More seriously, if there is no program I can ever write that is capable of distinguishing between an object and an object reference, then it doesn't matter. However, I think I can write such a program: a = [42]; b = [a, a] Now it doesn't make sense to say that b[0] and b[1] are the same object, because they aren't. Proof: If I execute b[0]=79, b[1] is still [42]. On the other hand, b[0] and b[1] do refer to the same object, and it is that distinction that I am suggesting that it is important to draw. |
|||
msg8635 - (view) | Author: Fred Drake (fdrake) | Date: 2002-01-08 16:49 | |
Logged In: YES user_id=3066 Re-opened for further consideration when I have more time. |
|||
msg8636 - (view) | Author: Guido van Rossum (gvanrossum) * | Date: 2002-01-08 20:10 | |
Logged In: YES user_id=6380 I read everything. :-) Let me butt in here. (I also probably wrote that section in the tutorial. :-) I know Algol-68 and am familiar with its use of the term "reference". Fred probably isn't and thinks of references as equivalent to pointers; but I'm sure he's familiar with the C term "l-value" which is C's name for what Algol-68 cals a reference. (I don't know what C++ calls it these days; isn't reference a specific thing involving an & operator there?) Python just doesn't use the concept of "object reference" in the same way as Algol-68 uses it. I mean it when I say that a namespace maps names to objects! The difference is that I consider assignment a change to the mapping. It can't be a change to a "reference" (in the Algol-68 sense) since the reference may not yet exist (if the name wasn't bound before). Also, Python *definitely* doesn't have the concept of a reference to a reference (C's ** types, Algol-68's ref ref). While there most definitely is a piece of memory holding an object pointer in the *implementation* of Python's namespaces, and in other collections of objects like lists, there's no way in Python to talk about that piece of memory in a unified way. You'd have to say "the name X in mapping Y" or "the index K in sequence L" or something like that. I hope this helps everyone's understanding! |
|||
msg8637 - (view) | Author: Andrew Koenig (arkoenig) | Date: 2002-01-08 20:27 | |
Logged In: YES user_id=418174 Aha! -- Now I understand. You're thinking of a namespace as a collection of named references to objects that can be searched associatively by name :-) Moreover, the name- reference relation is bijective. That is, if I write a = 3 b = 4 then there is a unique entity -- which I have been calling a reference -- associated with `a' and another such entity associated with `b'. Moreover, because the relation is bijective, the entity with which `a' is associated is not associated with any other name, and similarly for `b'. Because of this bijectivity, there is never any reason to think about this entity separately from its name, and therefore you do not need a separate term for it. Incidentally, C++ uses both the term `lvalue' and `reference,' with `lvalue' denoting a syntactic context and `reference' denoting a particular property of types. |
|||
msg8638 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2002-05-14 11:28 | |
Logged In: YES user_id=80475 Any objections to closing this one? |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:04:51 | admin | set | github: 35880 |
2002-01-07 20:15:26 | arkoenig | create |