Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> All you need to do is use the `is` operator to see how even tuples (named or otherwise) are objects, not values.

That is not language feature of Python but an implementation detail. Python implementations are permitted (but not required) to intern any immutable value (which tuples, contrary to your description, are), and "is" is a mechanism for revealing what the implementation has done.

You seem to be equivocating between talk of values as a logical thing (where Python absolutely has compound values, including tuples) and as an implementation feature (where individual Python implementations may or may not implement certain logical values through interning.)



That sounds like basically the same newbie-pitfall that exists with code-literal Strings in Java: Just because a certain comparison operation can work in some circumstances (where the underlying platform makes an optimization) doesn't mean is a safe/sane choice in general.


> That is not language feature of Python but an implementation detail.

So you're saying that the behavior of the `is` operator is implementation-defined?

> values as a logical thing (where Python absolutely has compound values, including tuples)

The (informal, unspecified) metalanguage that you're using to reason about Python programs has compound values. Python itself doesn't.


> So you're saying that the behavior of the `is` operator is implementation-defined?

No, the behavior has a standard definition: it reveals whether the operands refer to the same in-memory construct.

Whether immutable values are stored in the same in-memory construct is, however, AIUI, implementation dependent.


> Whether immutable values are stored in the same in-memory construct is, however, AIUI, implementation dependent.

If I can't bind it to a variable, it isn't a value. You can't bind the list [1,2,3] to a variable, because Python has no such thing as the list [1,2,3].


I don't know why we are talking about lists, here, since (implementation details aside) lists in Python aren't conceptually values; for one thing, they aren't even immutable.

If you meant not to change the subject from tuples, yes, its true that whether the tuple (1,2,3) -- which is logically a value -- has a unique in-memory representation is not guaranteed at the language level in Python (and, in fact, it does not in the most common implementation.)


Err, sorry, yes, pretend I said “the tuple (1,2,3)”.

Regarding in-memory representations, the whole point to using values is that you don't care about the representation. A value may be represented in a myriad different ways, but from within the language (as opposed to, say, using a memory debugger), you can't observe the difference. If you're allowed to probe differences between two representations of the same value, the value abstraction is leaky.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: