'is not' or '!='

Marko Rauhamaa marko at pacujo.net
Tue Aug 19 17:00:22 EDT 2014


Marko Rauhamaa <marko at pacujo.net>:

> That's circular reasoning. When you are defining Python's execution
> model, you can't refer back to Python's execution model.
>
> For a good example of what I'm after, take a look how Java specifies its
> crucial happens-before relation:
>
>    <URL:
>    http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5>

However, Java does *not* do a particularly good job defining object
identity (<URL:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.21.3>):

   At run time, the result of == is true if the operand values are both
   null or both refer to the same object or array; otherwise, the result
   is false.

   The result of != is false if the operand values are both null or both
   refer to the same object or array; otherwise, the result is true.

For a more worthy attempt, we'll have to take a look at Scheme (<URL:
http://www.scheme.com/tspl2d/objects.html>):

   * Two objects of different types (booleans, the empty list, pairs,
     numbers, characters, strings, vectors, symbols, and procedures) are
     distinct. The Revised4 Report (but not the ANSI/IEEE standard)
     permits one exception to this rule: the empty list and the boolean
     #f may be identical.

   * Two objects of the same type with different contents or values are
     distinct.

   * The boolean object #t is identical to itself wherever it appears,
     and #f is identical to itself wherever it appears, but #t and #f
     are distinct.

   * The empty list () is identical to itself wherever it appears.

   * Two symbols (created by read or by string->symbol) are identical if
     and only if they have the same name (by string=?).

   * A quoted pair, vector, or string is identical to itself, as is a
     pair, vector, or string created by an application of cons, vector,
     string, etc. Two pairs, vectors, or strings created by different
     applications of cons, vector, string, etc., are distinct. One
     consequence is that cons, for example, may be used to create a
     unique object distinct from all other objects.

   * Two procedures that may behave differently are distinct. A
     procedure created by an evaluation of a lambda expression is
     identical to itself. Two procedures created by the same lambda
     expression at different times, or by similar lambda expressions,
     may or may not be identical.


Marko



More information about the Python-list mailing list