Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.91.MISMATCH!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.056 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; '(b)': 0.07; 'stack': 0.13; '10:00': 0.16; 'call?': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; '(a)': 0.22; 'am,': 0.23; 'needed.': 0.23; 'implemented': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "doesn't": 0.26; 'example': 0.26; 'sense': 0.26; 'chris': 0.26; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; '13,': 0.29; 'tail': 0.29; 'subject:/': 0.30; 'code': 0.30; 'problem': 0.33; 'call,': 0.33; 'received:google.com': 0.35; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'matter': 0.63; 'more': 0.63; 'worth': 0.67; 'jul': 0.72; 'pardon': 0.84; 'to:name:python': 0.84 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=Oar57V5ozWx+WQZxCvEvOlVU+uqyGgWT0dV7wzmC/S8=; b=tRQ85kwOaESt0wL3ItZbRuVpdVsEqXCB8mcQgJmW69Ry12rGYbA0AV1wykM1m9YQqv 6ai7jCuP+ZO3yUHVXA+TyW2+vruuObncN43c7zl3Cw9O++2XD1ucb5JbLpsijDnRg0Z4 JccfL3F8/fsGuZNJWJRvxu9ydxpKF1BybN1W1r6eH0l+tu91wStism0Vnu/XukFMfcuw AmPlLkefFbe+2zGcvt8jBOmk+eU2ZsTAN/LwNE7WLYL6lIpDGmeWvJPuf09/kNfNizq9 Q12J0a+Kx9kmfAAn3yOZDS+s+qWXz54veJaunWjZxfNey4ERL39kHkttJb6vxgMgxy8v /5HA== X-Received: by 10.129.36.14 with SMTP id k14mr37758613ywk.64.1436795202851; Mon, 13 Jul 2015 06:46:42 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <55A3A853.4040006@rece.vub.ac.be> From: Ian Kelly Date: Mon, 13 Jul 2015 07:46:03 -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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436795213 news.xs4all.nl 2878 [2001:888:2000:d::a6]:57227 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93757 On Mon, Jul 13, 2015 at 6:34 AM, Chris Angelico wrote: > On Mon, Jul 13, 2015 at 10:00 PM, Antoon Pardon > wrote: >> On 07/13/2015 01:28 PM, Chris Angelico wrote: >>> Why is it worth writing your code recursively, only to have it be >>> implemented iteratively? >> >> Because sometimes, it is easier to think about the problem recursively. > > Can you give me an example that (a) makes a lot more sense recursively > than iteratively, and (b) involves just one tail call? Why does (b) matter? If the function has more than one tail call, it doesn't matter which one you hit -- either way it's a tail call and the stack frame is no longer needed.