Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'expressions': 0.07; 'subject:test': 0.09; 'python': 0.11; '-1,': 0.16; 'bitwise': 0.16; 'boolean': 0.16; 'conditional': 0.16; 'expression.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'logical.': 0.16; 'programmers.': 0.16; 'string).': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'basically': 0.19; 'print': 0.22; 'header:User-Agent:1': 0.23; 'logical': 0.24; '(or': 0.24; "i've": 0.25; 'this:': 0.26; 'read,': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'appear': 0.29; 'chris': 0.29; '(like': 0.30; 'returned': 0.30; 'lines': 0.31; 'comparison': 0.31; 'operators': 0.31; 'this.': 0.32; 'run': 0.32; 'linux': 0.33; 'trouble': 0.34; 'maybe': 0.34; 'basic': 0.35; 'common': 0.35; 'convert': 0.35; 'but': 0.35; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'days': 0.60; 'read': 0.60; 'introduced': 0.61; 'matter': 0.61; 'topic,': 0.81; 'truth': 0.81; 'dialect': 0.84; 'idiom': 0.84; 'subject::': 0.85; 'tricks.': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sat, 25 Oct 2014 19:04:52 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: (test) ? a:b References: <54476af8$0$21651$426a74cc@news.free.fr> <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414285521 news.xs4all.nl 2849 [2001:888:2000:d::a6]:57592 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79698 On 10/22/2014 09:46 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> I've seen much MUCH worse... where multiple conditional >> expressions get combined arithmetically, and then the result used >> somewhere... > > In the days of old-school BASIC it was common to > exploit the fact that boolean expressions evaluated > to 0 or 1 (or -1, depending on your dialect :) to > achieve conditional expressions or other tricks. As far as I can tell, no BASIC dialect I've looked at (DOS and Linux worlds only), has ever had any logical operators like AND (&&), OR (||), and NOT (!). They only appear to have bitwise operators (&,|,~ C equivalent). The fact that comparison operators returned 0 and -1 made the bitwise operators function the same as logical. But you can run into trouble if you tried to use a common python idiom like this: x = read_some_lines() 'returns number of lines read, or zero if none are if not x: print ("I couldn't read any lines") exit(1) Basically any value other than -1 for x would cause the not x to be true. Off topic, and no matter to python programmers. But for BASIC you need to watch out for this. One BASIC dialect introduced a set of functions, istrue() and isfalse() to convert a non-zero truth value to -1, and any falsish value to zero (like maybe an empty string). That way the bitwise operators would always function as logical operators in a conditional expression.