Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Statements as expressions [was Re: Undefined behaviour in C] Date: Tue, 29 Mar 2016 20:09:39 +1100 Lines: 31 Message-ID: References: <56f55e2e$0$1619$c3e8da3$5496439d@news.astraweb.com> <87wpoq1omm.fsf@elektro.pacujo.net> <56f5f81d$0$1585$c3e8da3$5496439d@news.astraweb.com> <87io0a6j1w.fsf@nightsong.com> <56f67ee3$0$1583$c3e8da3$5496439d@news.astraweb.com> <87poug5t0c.fsf@nightsong.com> <1344e2bf-15d2-412e-9512-b0aba800dada@googlegroups.com> <56f880ba$0$1617$c3e8da3$5496439d@news.astraweb.com> <87h9fr5qig.fsf@nightsong.com> <56fa3c2a$0$1591$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de rdPx2D77E+HjPPuTajSs7QpjLDu9zrz0zdYxWm8NQsyA== 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; 'received:209.85.223': 0.03; 'value,': 0.03; 'false,': 0.07; 'cc:addr:python-list': 0.09; 'deletes': 0.09; 'garbage': 0.09; 'semantics': 0.09; 'python': 0.10; 'useful,': 0.13; '(note:': 0.16; '2016': 0.16; '42.': 0.16; 'advocating': 0.16; 'dictionary.': 0.16; 'executed,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imo,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:expressions': 0.16; 'which,': 0.16; 'wrote:': 0.16; 'obviously': 0.16; 'string': 0.17; 'else,': 0.18; 'instance,': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saying': 0.22; 'names.': 0.22; 'defined': 0.23; 'consistent': 0.23; "python's": 0.23; 'header:In-Reply-To:1': 0.24; 'rest': 0.26; 'skip:_ 20': 0.26; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this.': 0.28; 'subject: [': 0.29; 'certainly': 0.30; 'normally': 0.30; 'query': 0.30; 'primary': 0.31; 'useful': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'tue,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'false': 0.35; 'returning': 0.35; 'but': 0.36; 'should': 0.36; 'needed': 0.36; 'received:209.85': 0.36; 'evaluation': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'expect': 0.37; 'received:209': 0.38; 'anything': 0.38; 'someone': 0.38; 'where': 0.40; 'mar': 0.65; 'low': 0.83; 'chrisa': 0.84; 'deleted?': 0.84; 'destructive': 0.84; "it'd": 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:date:message-id:subject:from:cc; bh=3NrF4JYDXCsM9bgdDM+UO4DGR02cQFUGcFvweo0i6uQ=; b=plxcUmO1dgOKdfhK1ozUr1ByDTTU5AazsRbK3hKu4eUZ/6Vya+Pi/LOASeTmc1ve+C eVcHXYRPuaBineviekihaguf/p5Y/1rEBR+IZ179MPap5ku0neSlqclknq4v8QjtcA4/ CFx6Y2U3L1KX1svGo4mFsYS8nnTNiF0qyQhJGEJyXuWE2R05+MdZCt2cokWyvKchYvGP NQn7GolR4bwq+biSknLbRHAhtzvRvkKdHz2Q9FpKomVpRzGnmkEkVj+kq2UHxivRtzJ6 NGT7e6q7c0HoUuSYrROIuv4vDnjc1tYi/nAH5L/+nKH2NPwKA4xPYg5Jfm0KfImw4YSU 97Rw== 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:date :message-id:subject:from:cc; bh=3NrF4JYDXCsM9bgdDM+UO4DGR02cQFUGcFvweo0i6uQ=; b=LNZ4oLAA40ocS+ADwNwLRFFGUbLHdD0Nqgomno4wobjq3YeWFkZTCem9XfefbXfRuW trWTLr9rx51ygrHKUPQtcIADEq78QIJAp3b7pJ64OB8i82PsAdeQeS/sZ5LeDfuMP5Co KAEcTwsg+0uUr3s7/YvzRnOjhY/ToYbtpbfnioc9bniVsBmQi5nuXApOpo0eWpVHsJYn 65gGbmrtqOTaIOVD6cDmYd7wLoh0fWJu19Yi4TTmhRuYxz8LJzYRzZLTjawpPApgqMfE 276slvrWNtDO7KAg2OiG8S3mzaxPoxgwdHHdy1TDrSy17o5qIbSs8qsrlaGowPzyILEt rNPQ== X-Gm-Message-State: AD7BkJJIEI6Vh9EnyqxLVvSHJebesDFYcGUFT1TZFdWcQHQ6Q8fecmFcOc96S59VkkRvO8av7WQB2zDYoirrKA== X-Received: by 10.107.137.221 with SMTP id t90mr1451263ioi.31.1459242579807; Tue, 29 Mar 2016 02:09:39 -0700 (PDT) In-Reply-To: <56fa3c2a$0$1591$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105966 On Tue, Mar 29, 2016 at 7:26 PM, Steven D'Aprano wrote: > del x > > Should it return None? The string 'x'? How about the value that x had just > before it was deleted? True if that allowed the value to be garbage > collected, False if it wasn't? Or the other way around? None of these > suggests feel either useful or obviously right. Returning the value x had just before being deleted is certainly useful - consider the case where x is not a simple name but a subscripting, which makes this into a destructive lookup. Saying whether the object was garbage collected or not could also be useful, but feels very low level. But if Python were to make 'del' into an expression, the only semantics needed would be for simple names. For everything else, the value of 'del x[y]' or 'del x.y' would simply be 'whatever __delitem__/__delattr__ returns'. And even for simple names, the semantics could be defined by the enclosing scope's dictionary. It'd be like Python's operators; yes, you normally expect "x < y" to return a truthy or falsy value, and for most built-in types it'll return either True or False, but you can return anything at all - including a lazy evaluation object for a DSL. Someone could, for instance, make "del User[42]" return a Query object which, when executed, deletes the user with primary key 42. (Note: I am not advocating this. Just saying what would, IMO, be consistent with the rest of Python.) ChrisA