Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'sufficient': 0.05; 'subject:Python': 0.06; 'compiler': 0.07; 'modified': 0.07; '"if': 0.09; 'false.': 0.09; 'subject:using': 0.09; 'sure,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'all?': 0.16; 'compiler.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'implies': 0.16; 'loop.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; "shouldn't": 0.24; 'simpler': 0.24; 'header': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'too.': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'this.': 0.32; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'list': 0.37; 'easily': 0.37; 'expect': 0.39; 'sure': 0.39; 'enough': 0.39; 'how': 0.40; 'become': 0.64; 'more': 0.64; 'capable': 0.67; 'bothered': 0.68; 'nobody': 0.68; 'will...': 0.84; 'to:none': 0.92; 'hand,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=SEygws9hs6FZh/ry5MbAl9b+/Ys8Gcy1Fc1GdqzhNGI=; b=chsquSAY4TF3UvYTbCmLTWhc/u8shjag/b4HBrvWWx6P3pb53jZ7XzvqNgdzNa+sNf jzNSDMknSJMf2jhP6R0h7FCkw5sFDYr0MSYbW/+RegwWL2xqN5Rx4EgH8dHVu0kZJlLw ghe07Q0e6Zdr4+SdSsXkCw3dDBIgEQXxh3yG2cduHB9rCGMChuHTDGOQmS3BfaC3VKDK egcTlGWv4Tk+4juZXWuuqKO0b8RiaPj4ipUPGCIEVy1T5jUoicbrhBgbEeRpEuxoAxsy zTgCebgZf42fwetkroVyONWrJ7aVkd9DaQcGiDbXZN7DBk7ewcEzzXxi61WnWbaHgv06 zeVA== MIME-Version: 1.0 X-Received: by 10.50.62.104 with SMTP id x8mr23171199igr.2.1418170836550; Tue, 09 Dec 2014 16:20:36 -0800 (PST) In-Reply-To: <54878f8a$0$13010$c3e8da3$5496439d@news.astraweb.com> References: <004e01d01173$e1641c10$a42c5430$@gmail.com> <5484e3d8$0$13013$c3e8da3$5496439d@news.astraweb.com> <54866372$0$12991$c3e8da3$5496439d@news.astraweb.com> <54878f8a$0$13010$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 10 Dec 2014 11:20:36 +1100 Subject: Re: Python Iterables struggling using map() built-in From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418170840 news.xs4all.nl 2958 [2001:888:2000:d::a6]:40356 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82247 On Wed, Dec 10, 2014 at 11:10 AM, Steven D'Aprano wrote: > On the other hand, *premature optimization*. In general, one shouldn't write > more complex code so the compiler can optimize it, one should write simpler > code and have a smarter compiler. If *we* are capable of recognising that > iters is not modified in the body of the loop, then the compiler should be > capable of it too. (If it isn't, it is because nobody has bothered to give > the compiler sufficient smarts, not because it can't be done.) So a good > compiler should be able to compile "while iters" into "if iters: while > True" so long as iters is not modified in the body of the loop. In general, one can't expect the boolification of a Python object to be consistent, so the compiler can't optimize this. How can it be sure the list will never become empty? I'm still of the opinion that a while loop's header implies something about the code; "while iters:" implies that iters might be able to become false. Sure, you can verify easily enough that it never will... but why should you have to verify at all? ChrisA