Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74268

Re: Proposal: === and !=== operators

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'operator': 0.03; 'sufficient': 0.05; '[1,': 0.09; 'language.': 0.14; 'changes': 0.15; 'compares': 0.16; 'equal.': 0.16; 'nan': 0.16; 'nans': 0.16; 'semantics': 0.16; 'subject:operators': 0.16; 'token,': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'written': 0.21; '>>>': 0.22; 'proposed': 0.22; 'nearly': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'comparison': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'though.': 0.31; 'supposed': 0.32; "we're": 0.32; 'up.': 0.33; 'used,': 0.33; 'could': 0.34; 'problem': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'data,': 0.36; 'false': 0.36; "he's": 0.36; 'doing': 0.36; 'should': 0.36; 'two': 0.37; 'requiring': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'solve': 0.60; 'most': 0.60; 'talking': 0.65; 'equals': 0.68; 'jul': 0.74; 'subject:Proposal': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=GtMVYE/eqY3vK6fTmbW/4LGPLwvm9lcvaQ/xTXrqIt8=; b=hslGDG7y/Qq6qI2oPi7UtDKnf/XIOYyvTFEDrJJPBPrxaP+OF2Zt8ez/lYHSrNKPo/ YSl7kQ78X4YQhz/54je3zJBmZcKjjH2AN+rMxU92QedoyktWufB5ncn6+RKYlL0YuI5K +RVaBvomgVx3PZPon+AkhqCsLEb/SQ5WMrt3F8+Ko1+4g9F/J2+k7J/pGaWZFQL28CJ4 nTi+clh5s8vJD3Da8qmT7uV1/Tj6ms+FcHPmCrrI4fmT0DiXQy7FWrLPwALeipnI/6L1 cfWXHjvNjcbMdEU2e67LAkJnevosdO7BS1+jP3GYo5YBYCpncQy8Ed5pRncBlNG0ebep uYUQ==
X-Received by 10.66.136.131 with SMTP id qa3mr41722106pab.77.1404928241620; Wed, 09 Jul 2014 10:50:41 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <53bd08b4$0$2746$c3e8da3$76491128@news.astraweb.com>
References <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> <mailman.11675.1404890483.18130.python-list@python.org> <53bd08b4$0$2746$c3e8da3$76491128@news.astraweb.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 9 Jul 2014 11:50:01 -0600
Subject Re: Proposal: === and !=== operators
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11702.1404928249.18130.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1404928249 news.xs4all.nl 2918 [2001:888:2000:d::a6]:41009
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:74268

Show key headers only | View raw


On Wed, Jul 9, 2014 at 3:17 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> People are already having problems, just listen to Anders. He's
> (apparently) not doing NAN-aware computations on his data, he just wants
> to be able to do something like
>
> this_list_of_floats == that_list_of_floats
>
> without NANs screwing it up. But by the same token, if I want to use NANs
> the way they're supposed to be used, I should still be able to use an
> equals operator (rather than a function or method).

Well, if we're talking about *lists*, then the comparison operator
already compares identity of individual elements:

>>> nan = float('nan')
>>> l1 = [1.0, 2.0, nan, 4.0]
>>> l2 = [1.0, 2.0, nan, 4.0]
>>> l1 == l2
True

So the comparison "x is y or x == y" could also be written "[x] ==
[y]", without requiring any changes to the language.

I suspect that just adding identity comparison is not sufficient to
solve Anders' problem, though.

> But the problem is, most people will need to us "x is y or x == y" nearly
> everywhere! And that doesn't help with containers:
>
> py> alist = [1.0, 2, float('NAN'), 4]
> py> blist = [1, 2.0, float('nan'), 4]
> py> alist is blist or alist == blist
> False

The only reason this fails is because the two nans are neither
identical nor equal. The proposed == semantics would also fail here.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Proposal: === and !=== operators Steven D'Aprano <steve@pearwood.info> - 2014-07-09 07:00 +0000
  Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-09 17:21 +1000
    Re: Proposal: === and !=== operators Steven D'Aprano <steve@pearwood.info> - 2014-07-09 09:17 +0000
      Re: Proposal: === and !=== operators Rustom Mody <rustompmody@gmail.com> - 2014-07-09 09:20 -0700
      Re: Proposal: === and !=== operators Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-09 11:50 -0600
      Re: Proposal: === and !=== operators Cameron Simpson <cs@zip.com.au> - 2014-07-10 09:16 +1000
      Re: Proposal: === and !=== operators Johannes Bauer <dfnsonfsduifb@gmx.de> - 2014-07-12 13:54 +0200
        Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-12 16:35 +0000
          Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-13 02:54 +1000
            Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-12 16:39 -0400
          Re: Proposal: === and !=== operators Johannes Bauer <dfnsonfsduifb@gmx.de> - 2014-07-12 20:14 +0200
            Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-13 09:01 +1000
              Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-12 19:06 -0400
                Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-13 09:15 +1000
            Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-13 04:48 +0000
  Re: Proposal: === and !=== operators Cameron Simpson <cs@zip.com.au> - 2014-07-09 18:17 +1000
    Re: Proposal: === and !=== operators Steven D'Aprano <steve@pearwood.info> - 2014-07-09 09:02 +0000
      Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-09 19:23 +1000
  Re: Proposal: === and !=== operators Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-09 05:01 -0700
  Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-09 08:27 -0400
    Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-09 12:48 +0000
      Re: Proposal: === and !=== operators Tim Chase <python.list@tim.thechases.com> - 2014-07-09 13:05 -0500
        Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-10 01:10 +0000
      Re: Proposal: === and !=== operators Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-09 12:31 -0600
      Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-09 16:47 -0400
  Re: Proposal: === and !=== operators Ethan Furman <ethan@stoneleaf.us> - 2014-07-09 05:43 -0700
  Re: Proposal: === and !=== operators Robert Kern <robert.kern@gmail.com> - 2014-07-09 16:27 +0100
  Re: Proposal: === and !=== operators Alex Burke <alexjeffburke@gmail.com> - 2014-07-10 18:33 +0200
  Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-12 03:30 +0000
    Re: Proposal: === and !=== operators Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2014-07-12 01:07 -0400
      Re: Proposal: === and !=== operators Torsten Bronger <bronger@physik.rwth-aachen.de> - 2014-07-12 08:05 +0200
        Re: Proposal: === and !=== operators Torsten Bronger <bronger@physik.rwth-aachen.de> - 2014-07-12 08:14 +0200
      Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-12 16:06 +1000
      Re: Proposal: === and !=== operators Ethan Furman <ethan@stoneleaf.us> - 2014-07-11 23:11 -0700
      Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-12 16:39 +1000
        Re: Proposal: === and !=== operators Marko Rauhamaa <marko@pacujo.net> - 2014-07-12 10:06 +0300
      Re: Proposal: === and !=== operators Ethan Furman <ethan@stoneleaf.us> - 2014-07-11 23:53 -0700
      Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-12 17:25 +1000
      Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-12 08:33 +0000

csiph-web