Marko Rauhamaa <ma...@pacujo.net> writes: > Say I implement Python. Say I returned a random number for id(), how > would that violate the language spec?
You could do that, certainly. So long as that randomly-chosen integer was always the same for every object, and never the same for any other concurrently-existing object, it can just as well be assigned randomly. If you're saying that your implementation of ‘id(foo)’ would return a *different* integer when called at different times for the same object, then yes, that violates the specification for that function. > It would violate the spec. But there would have to be a paragraph in > the specification that was violated or a reference test case that > failed. Yes. It would violate this paragraph: Every object has an identity, a type and a value. An object’s identity never changes once it has been created […] the id() function returns an integer representing its identity. <URL:http://docs.python.org/3/reference/datamodel.html> Again, I ask you to read these documents for comprehension. > For example, this test would demonstrate obviously invalid behavior: > > >>> print(id(x)) > 129 > >>> print(id(x)) > 201 Yes. That violates the paragraph above, and so that implementation is not compliant with the Python language reference. -- \ “I watched the Indy 500, and I was thinking that if they left | `\ earlier they wouldn't have to go so fast.” —Steven Wright | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list