osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Explanation of list reference


On Sat, 15 Feb 2014 11:10:46 +0200, Marko Rauhamaa wrote:

> Chris Angelico <rosuav at gmail.com>:
> 
>> On Sat, Feb 15, 2014 at 8:43 AM, Marko Rauhamaa <marko at pacujo.net>
>> wrote:
>>> Unfortunately neither the "everything is a reference" model nor the
>>> "small/big" model help you predict the value of an "is" operator in
>>> the ambiguous cases.
>>
>> Can you give an example of an ambiguous case?
> 
> The "x is y" test may yield different outcomes in different, valid
> Python implementations:
> 
>    4 is 4
>    (x,) is (x,)
>    "hello" is "hello"


But none of those examples are ambiguous. They're merely unspecified by 
the language definition. Any specific implementation of Python will 
return either True or False; it may be predictable, or it might be 
impossible to predict until runtime, but either way we know that every 
non-broken Python virtual machine must either treat the two operands as 
the same object or different objects.

These are ambiguous sentences:

    I saw the man with the binoculars.
    Police help assault victim.
    Once there was a blind carpenter who picked up his hammer and saw.
    Look at that cat with one eye.

"A Python implementation can choose whether or not to re-use immutable 
objects" is not ambiguous. It's just a choice.



-- 
Steven