Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Operator Precedence/Boolean Logic Date: Wed, 29 Jun 2016 21:06:36 +1000 Lines: 37 Message-ID: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de WPUdvDZnikCU5vX3eyJRWACJZAqCYTYK9VH1hZVReTpQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'true,': 0.04; '[],': 0.07; 'expressions': 0.07; 'objects,': 0.07; 'pretend': 0.07; 'cc:addr :python-list': 0.09; 'empty,': 0.09; 'none.': 0.09; 'python': 0.10; 'syntax': 0.13; 'def': 0.13; 'wed,': 0.15; '2016': 0.16; 'container,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instance:': 0.16; 'non-empty': 0.16; 'object()': 0.16; 'perl.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'stick': 0.18; '>>>': 0.20; 'all,': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'explicit': 0.22; '(or': 0.23; 'header:In-Reply-To:1': 0.24; 'helpful': 0.27; 'define': 0.27; 'message-id:@mail.gmail.com': 0.27; 'regular': 0.29; 'argue': 0.29; 'objects': 0.29; 'subject:/': 0.30; "i'd": 0.31; 'probably': 0.31; 'skip:_ 10': 0.32; 'related': 0.32; '[1]': 0.32; 'true.': 0.33; 'definition': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'easiest': 0.35; "isn't": 0.35; 'but': 0.36; 'too': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'rather': 0.39; 'still': 0.40; 'default': 0.61; 'show': 0.62; 'between': 0.65; 'wanting': 0.66; 'special': 0.73; 'chrisa': 0.84; 'distinguish': 0.84; 'not)': 0.84; 'to:none': 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:cc; bh=8ZztwmOlRCAY9fONOEYAouEu06PT63dNGpHY+TarWuM=; b=aTMcsYeLSgZR1MxpHGynHRs+3JLe3mUmCGBHxFc6dZuSpYsc6r9TYqgBJMZUe+s6tK yCis0MFvS75habKBM3VioME3nyUDjYUuRz0JibXUy8mtKE7CKM/QKfJJzTUnJk11+TjC s08TxZhqZDchlqf8SDEjWcARna2ofZMhEEo15Aawb1M1yV6f2j7daaPjQXw2sdxyK8ix U5qbE5Ww5aGp+0lFxCCWpCoa/1CyLNlU/5nVbUZT+K0OSN6PuSBMsv/CYq7QWM2c4BOz UHGQa2WvQi/nklH8POL4osnYWMluI6tqpG5/H1yPIYbL4a3PjVThCRB5rzlQ5IgSTmOd glug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=8ZztwmOlRCAY9fONOEYAouEu06PT63dNGpHY+TarWuM=; b=RyjjntCkBiK5IGihUOc+F0i69JyV8e7Xm+yNgsRzSFSMli2E/X9xwdan6H1Iz6QdB1 7x9oCZmqvgk53zVu31mscomHPpWFG3ababj/Y7DnX4qlod4m3rgAk18xn9ymFNIhDsIK 15PS9Xhh2GZEOHa/IfQMdwEeN2T5QM1PtWyoCM46sktL4xHJP5iGGFKuqIznNlFI5qpA Tkde+7FWzSLCLCMugyxDTCQv8hVXAVWMTV7LO201pbkSMFbtusTKYm5vr7biM/UYkUJ6 MVMGlLq5Kl2ksrUSrFv2Qz9/C2YaEaX6vL7kNnwGZ29WXQNQhJISPlEE+nI732ZLVgRe ogVA== X-Gm-Message-State: ALyK8tJmhh6aLn3MagAkiDEXeVTnn1j2tDTux9zzT6GxVggussDUksVlRzS9W3xlSAWBMmsUwe6r+x/wYQW4Fg== X-Received: by 10.28.223.215 with SMTP id w206mr20302581wmg.61.1467198398080; Wed, 29 Jun 2016 04:06:38 -0700 (PDT) In-Reply-To: <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> Xref: csiph.com comp.lang.python:110771 On Wed, Jun 29, 2016 at 8:21 PM, Rustom Mody wrote: > > Please show me how we would define __bool__ for > > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a graph..." > > 2. Automata which in a way are special kinds of graphs > > 3. Regular Expressions which mathematically are related to automata > And pragmatically are (more) present in python than the first two > > It may (or may not) be helpful to pretend that python which already has > a regexp module/type also has explicit regexp syntax a la Perl. Probably the easiest way, for each of these objects, is to not define __bool__ at all, or to define it thus: def __bool__(self): return True If an object isn't a container, but is just a "thing", then it is by definition true. The contrast isn't between [1] and [], but rather between object() and None. It's perfectly reasonable for an object to be always true - that's what the default object type does. You could perhaps argue that a graph can be empty, but unless you're frequently wanting to distinguish between empty graphs and non-empty graphs, I'd stick with the default and make them always true. Note, for instance: >>> bool(re.compile("")) True I think that's about as empty as a regex can be, and it's still true. And regex match objects are always true, too - the match functions will all return None if there's no match. Not all objects need to be able to be falsey. ChrisA