Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'discard': 0.05; 'omit': 0.07; 'bug': 0.10; 'python': 0.10; '"this': 0.13; 'explicitly': 0.15; 'result.': 0.15; 'confusion': 0.16; 'entirely.': 0.16; 'keyword.': 0.16; 'mistake.': 0.16; 'wrote:': 0.16; 'pointed': 0.18; 'programmer': 0.18; '>>>': 0.20; '2015': 0.20; 'explicit': 0.22; 'function,': 0.22; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "doesn't": 0.26; 'chris': 0.26; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; '13,': 0.29; 'tail': 0.29; 'subject:/': 0.30; 'another': 0.32; "can't": 0.32; 'point': 0.33; 'call,': 0.33; 'optimize': 0.33; 'received:google.com': 0.35; 'but': 0.36; 'keyword': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'responsible': 0.37; 'say': 0.37; 'mean': 0.38; 'means': 0.39; 'to:addr:python.org': 0.40; 'side': 0.62; 'jul': 0.72; 'led': 0.72; 'miss': 0.77; '(also,': 0.84; 'lacks': 0.84; 'to:name:python': 0.84; 'mistakenly': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=IK8Ffsj+/FNHYNWa7CBiUvbqLEMucoHTaqK95EOF7y4=; b=HoUQfCNR4jC4j2RylZ39WUvuWVsG5t5wMtgcSxjl+y/hCL375NtrtaxIHBYqL/q+k3 7bJ3jKiMCYmsuycaYhURDye5r/gWF2gUhNxUpL/EfoeQdmneYqQGTBw8QnYT1ldzBJlm njmXgkGqjq5al9TmmFI+ECj8QR20GwJKCGkklOgyTsnEWkof2Op68erH9GpDKl83CNXM XQnKL+nN3qummENq+kNoLNA0kaMf//5BDB3yk7R3E5rd0H1Xyi9SLUWPZbHkJRy6P+gP Pd6XaDvpCcwskn9FxR8FZhkVkaoi4u/9wVLYtMkSYgEZz8d7wWBiU6BhL/o7owFurRmT FK+w== X-Received: by 10.170.42.85 with SMTP id 82mr43696442ykk.18.1436861657113; Tue, 14 Jul 2015 01:14:17 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <877fq3nuwo.fsf@elektro.pacujo.net> References: <55A3A853.4040006@rece.vub.ac.be> <55A3C366.6060602@rece.vub.ac.be> <87fv4r1fre.fsf@jester.gateway.sonic.net> <877fq3nuwo.fsf@elektro.pacujo.net> From: Ian Kelly Date: Tue, 14 Jul 2015 02:13:37 -0600 Subject: Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) To: Python 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436861666 news.xs4all.nl 2874 [2001:888:2000:d::a6]:38796 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93795 On Mon, Jul 13, 2015 at 11:57 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Mon, Jul 13, 2015 at 11:25 PM, Chris Angelico wrote: >>> (Also, side point: Python can't actually optimize the above function, >>> because it actually means "call quicksort, then discard its return >>> value and return None". A true tail call has to return the result of >>> the recursive call, and Python lacks a way to say "this function will >>> always return None". But that's trivial.) >> >> Another point in favor of an explicit tail-call keyword. Then one >> couldn't make that mistake. > > How about "return"? I think you miss my point entirely. "return" doesn't mean tail-call optimize; it just means to return the result. This is what led to the confusion responsible for the bug that Chris pointed out in the first place. With a keyword that explicitly means "perform tail-call optimization *and* return", the association of the keyword with the optimization is much clearer, and the programmer is much less likely to mistakenly omit it.