Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.033 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'exist,': 0.07; 'linear': 0.07; 'cc:addr:python-list': 0.09; 'lines:': 0.09; 'python': 0.10; 'python.': 0.11; 'do,': 0.15; 'languages.': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'haskell,': 0.16; 'lisp': 0.16; 'loops': 0.16; 'rule.': 0.16; 'thought.': 0.16; 'wrote:': 0.16; 'element': 0.18; 'nested': 0.18; 'stick': 0.18; 'language': 0.19; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'enforce': 0.22; 'explicit': 0.22; '(you': 0.23; 'header:In-Reply-To:1': 0.24; 'paul': 0.24; "doesn't": 0.26; 'chris': 0.26; 'comfortable': 0.27; 'message-id:@mail.gmail.com': 0.27; '14,': 0.27; 'tend': 0.27; 'transition': 0.27; 'arguments,': 0.29; 'assembly': 0.29; 'feature,': 0.29; 'separated': 0.29; 'style.': 0.29; 'tail': 0.29; 'array': 0.29; "i'm": 0.30; 'subject:/': 0.30; 'code': 0.30; 'programmers': 0.30; 'another': 0.32; "can't": 0.32; 'functional': 0.32; 'generally': 0.32; 'maybe': 0.33; 'problem': 0.33; "i'll": 0.33; 'case,': 0.34; 'languages': 0.34; 'tue,': 0.34; 'previous': 0.34; 'add': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'ones': 0.35; 'programming.': 0.35; 'protocol': 0.35; 'something': 0.35; 'express': 0.35; 'but': 0.36; 'instead': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'say': 0.37; 'stuff': 0.38; 'mean': 0.38; 'means': 0.39; 'why': 0.39; 'sure': 0.39; 'does': 0.39; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'side': 0.62; 'needing': 0.63; 'more': 0.63; 'you.': 0.64; 'other.': 0.64; 'worth': 0.67; 'jul': 0.72; 'chrisa': 0.84; 'completes': 0.84; 'discipline,': 0.84; 'expresses': 0.84; 'idiom': 0.84; 'iterative': 0.84; 'nicely.': 0.84; 'recursive.': 0.84; 'glad': 0.87; 'to:none': 0.91; '"one': 0.91; 'maybe,': 0.91; 'from.': 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=kO2yGRvI7EpsbuziLw/hl875OvRkuRAg56JtQjCgCmQ=; b=KBdzXkwj4oXXuzkoIq5V8YEYKvJgGBpI1emk774t950liGIjvFRw5wMv3SedOWhXZl EP5jQ30J4lx+C9jm1HG1s2wXm39hlsx7r7CriJ5EHbBmcP/GFjpNMZKJMdWfjcRa9NJo KckFdCIISxgAEQQjhPT5QfNIyJw3jG5UlSCT5BNHbDkhzVLv/aoMN7TrbvRriYcSQlto HHDxXa5b3YPBMVAwgyfkZdljtJ185awRkSczV+jrv0LYfJj6an6Zu0wOzPpZNyWFafqr 9cVXY3nDlXTRyDI+rdnnaGK9II+DGTZUNmX1jIvO5ch/jopK3/90MYXyHZRYCTo2xuDl fOxg== MIME-Version: 1.0 X-Received: by 10.107.159.66 with SMTP id i63mr52949929ioe.68.1436851920039; Mon, 13 Jul 2015 22:32:00 -0700 (PDT) In-Reply-To: <87fv4r1fre.fsf@jester.gateway.sonic.net> References: <55A3A853.4040006@rece.vub.ac.be> <55A3C366.6060602@rece.vub.ac.be> <87fv4r1fre.fsf@jester.gateway.sonic.net> Date: Tue, 14 Jul 2015 15:31:59 +1000 Subject: Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) 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.20+ 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436851929 news.xs4all.nl 2878 [2001:888:2000:d::a6]:48812 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:93783 On Tue, Jul 14, 2015 at 3:15 PM, Paul Rubin wrote: > Chris Angelico writes: >> I'm not sure why the transition to another state has to be recursive. > > It's not recursive: it's more like a goto with arguments, and a tail > call expresses it nicely. Hmm, maybe, but I'm not sure that the transition to another state is a goto with arguments. What triggers the transition? Is it a linear protocol? Is it a nested protocol that completes some operation and returns to a base state? How are these transitions recognized, and why is that needing a "goto with arguments" to express it? >> Maybe this is something where previous experience makes you more >> comfortable with a particular style, which will mean that functional >> idioms will never feel more comfortable to me than iterative ones do, >> and vice versa for you. If that's the case, then I'll stick with >> Python and Pike, and you can happily use Lisp and Haskell, and neither >> of us need be a problem to the other. > > Do you also use explicit loops instead of list comprehensions? They are > another nice functional idiom adapted into Python. I use list comprehensions, but that's not the same thing as using functional programming. What that means is that there's nothing that we can't learn from. I'm glad functional languages exist, where people try to make everything have no side effects and be deterministic; it's a good discipline, and worth being aware of even when your language doesn't enforce it. But just because functional languages like to say "take this array and multiply every element by 4" and I like using that same feature, that doesn't mean that I want to do everything in a functional style. Here's an alternative way of expressing that thought. Do you write code such that each line does one simple thing? That's a nice assembly language practice that's been adapted into Python. Assembly languages tend to enforce a "one line, one operation" rule. Python programmers often adhere to that (you don't generally see a bunch of stuff separated by semicolons, and even "for line in lines: print(line)" is frowned upon - add a newline!), but that doesn't mean we want all the other trappings of assembly languages. ChrisA