Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: Statements as expressions [was Re: Undefined behaviour in C] Date: Sun, 27 Mar 2016 18:40:23 -0700 Organization: A noiseless patient Spider Lines: 34 Message-ID: <87h9fr5qig.fsf@nightsong.com> 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ac130717aa033f117b1251f50cb4c61b"; logging-data="21967"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JPpwWjhU4RkpATzkZ7RvG" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:9h7tjmZ/EA9mAgvikZLAa/t5Cg0= sha1:wZKcKhLyu43Ro41b245VeIkvWsk= Xref: csiph.com comp.lang.python:105889 Steven D'Aprano writes: > if condition: > print(1) > print(2) > else: > print(3) > print(4) > what value should it return? Justify your choice. It could whatever value that the last call to print() returns. Lisp has worked like that since the 1950's. > What should be the return value of this statement? > > while True: > x += 1 > if condition: break It could return None, or break(val) could return val. > I don't think that "every statement is an expression" is conceptually > simpler at all. I think it is more difficult to understand. It hasn't been a problem in Lisp or its descendants, Erlang, Haskell, etc. I don't know about Ruby or Javascript. > But it is even harder to understand what it might mean for a while > loop to be a value, and the benefit of doing so seems significantly > less than compelling. It means that you get to use an incredibly simple and beautiful evaluation model. Have you ever used Lisp or Scheme? Give it a try sometime. Excellent free book: https://mitpress.mit.edu/sicp/full-text/book/book.html