Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89759
| Path | csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'anyway.': 0.05; 'guido': 0.05; 'subject:Python': 0.06; 'abuse': 0.07; 'debugging.': 0.09; 'exist,': 0.09; 'naturally': 0.09; 'optimizing': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'abusing': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iteration': 0.16; 'said.': 0.16; 'statement.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'version.': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'replace': 0.24; "shouldn't": 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'converting': 0.30; 'strongly': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'parameters.': 0.31; 'maintaining': 0.32; 'actively': 0.33; 'cases': 0.33; 'could': 0.34; 'usual': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; "i'll": 0.36; 'should': 0.36; 'implement': 0.38; 'actions': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'does': 0.39; 'sure': 0.39; 'dave': 0.60; 'simple,': 0.60; "you're": 0.61; 'further': 0.61; 'information': 0.63; 'skip:n 10': 0.64; 'optimized': 0.68; 'integrity': 0.74; 'manner.': 0.74; '2015': 0.84; 'iterative': 0.84; 'recursion,': 0.84; 'angel': 0.91; 'to:none': 0.92 |
| 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=fn9MaVH+TtBVWFUQH4cprqWZXjtvDeOHegJ2bN3zGic=; b=G6i6N+eH6rtlp/V1V2P64MLLD8onumdpvpK6wOomGJUtZvUw/j6DKYOdN94VOHxwRF hBhWFG66erbL3EFn7lpxhuCh4X6EANkqz4wpZuUVhvB5dgpGSXYqaxmv+NC57cJLH8XA 0q1DwTTbbnZrsFS5nN+U+fDT4wnupr6SGB/WyEV2lTKDl7eUfPGr3MJMO7O/NUZAcumv OuC/G8LGMOJ5SXoInGx0XBmGe9VGfiPvdKsQ8WWJ1lymY1fnl32U14md3XXxQspHOlQF hWV4+QxHC32/on6y9pNQVhcxKrQQJjwvUwDoASL4YjbvdV1mxOhSUqGOgdNd0nEnger+ PZ/A== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.134.206 with SMTP id q75mr10949618ioi.27.1430563334464; Sat, 02 May 2015 03:42:14 -0700 (PDT) |
| In-Reply-To | <5544A55C.2070504@davea.name> |
| References | <87mw1q9jqw.fsf@Equus.decebal.nl> <mailman.121.1430385051.3680.python-list@python.org> <87383hj4zj.fsf@elektro.pacujo.net> <87d22lx38x.fsf@Equus.decebal.nl> <55432557$0$12994$c3e8da3$5496439d@news.astraweb.com> <87383fo062.fsf@Equus.decebal.nl> <87egmzl4yr.fsf@elektro.pacujo.net> <mailman.4.1430558719.12865.python-list@python.org> <87a8xnl2r6.fsf@elektro.pacujo.net> <5544A55C.2070504@davea.name> |
| Date | Sat, 2 May 2015 20:42:14 +1000 |
| Subject | Re: Python is not bad ;-) |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7.1430563337.12865.python-list@python.org> (permalink) |
| Lines | 57 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430563337 news.xs4all.nl 2941 [2001:888:2000:d::a6]:38888 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89759 |
Show key headers only | View raw
On Sat, May 2, 2015 at 8:22 PM, Dave Angel <davea@davea.name> wrote:
> On 05/02/2015 05:58 AM, Marko Rauhamaa wrote:
>>
>> Chris Angelico <rosuav@gmail.com>:
>>
>>> Guido is against anything that disrupts tracebacks, and optimizing
>>> tail recursion while maintaining traceback integrity is rather harder.
>>
>>
>> Tail recursion could be suppressed during debugging. Optimized code can
>> play all kinds of non-obvious tricks with the execution frame.
>>
>>> In the situations where it really is simple, you can always make the
>>> change in your own code anyway. Often, the process of converting
>>> recursion into tail recursion warps the code to the point where it's
>>> abusing recursion to implement iteration anyway, so just make it
>>> iterative.
>>
>>
>> While you shouldn't actively replace Python iteration with recursion, I
>> strongly disagree that naturally occurring tail recursion is abuse or
>> should be avoided in any manner.
>>
>
> When you strongly disagree, make sure you're disagreeing with what Chris
> actually said. The key phrase in his message was
> "converting recursion into tail recursion"
>
> NOT "converting iteration into recursion"
> and NOT "naturally occurring tail recursion"
Indeed. I'll clarify my statement.
When a function needs to do further actions after the tail call, the
usual solution is to carry the information through parameters.
def stupid_sum_iter(x):
"""Calculate sum(range(x+1))"""
tot = 0
while x:
tot += x
x -= 1
return tot
def stupid_sum_recur(x):
return x and x + stupid_sum_recur(x - 1)
def stupid_sum_tail_recur(x, tot=0):
if not x: return tot
return stupid_sum_tail_recur(x - 1, tot + x)
Converting the recursive form into optimizable tail recursion requires
an accumulator parameter, which means it's virtually the same as the
iterative version. Naturally-occurring tail recursion does exist, but
it's far from all cases of recursion.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 09:07 +0200
Re: Python is not bad ;-) Ben Finney <ben+python@benfinney.id.au> - 2015-04-30 19:10 +1000
Re: Python is not bad ;-) Marko Rauhamaa <marko@pacujo.net> - 2015-04-30 13:16 +0300
Re: Python is not bad ;-) Chris Angelico <rosuav@gmail.com> - 2015-04-30 20:52 +1000
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 13:30 +0200
Re: Python is not bad ;-) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-01 17:03 +1000
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-05-01 09:47 +0200
Re: Python is not bad ;-) Christian Gollwitzer <auriocus@gmx.de> - 2015-05-01 19:56 +0200
Re: Python is not bad ;-) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-02 19:44 +1200
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-05-02 10:26 +0200
Re: Python is not bad ;-) Marko Rauhamaa <marko@pacujo.net> - 2015-05-02 12:10 +0300
Re: Python is not bad ;-) Chris Angelico <rosuav@gmail.com> - 2015-05-02 19:25 +1000
Re: Python is not bad ;-) Marko Rauhamaa <marko@pacujo.net> - 2015-05-02 12:58 +0300
Re: Python is not bad ;-) Dave Angel <davea@davea.name> - 2015-05-02 06:22 -0400
Re: Python is not bad ;-) Chris Angelico <rosuav@gmail.com> - 2015-05-02 20:42 +1000
Re: Python is not bad ;-) Christian Gollwitzer <auriocus@gmx.de> - 2015-05-02 13:07 +0200
Re: Python is not bad ;-) Chris Angelico <rosuav@gmail.com> - 2015-05-02 21:21 +1000
Re: Python is not bad ;-) Christian Gollwitzer <auriocus@gmx.de> - 2015-05-02 13:32 +0200
Re: Python is not bad ;-) Marko Rauhamaa <marko@pacujo.net> - 2015-05-02 14:42 +0300
Re: Python is not bad ;-) Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-02 09:45 -0600
Re: Python is not bad ;-) Chris Angelico <rosuav@gmail.com> - 2015-05-03 01:55 +1000
Re: Python is not bad ;-) Joonas Liik <liik.joonas@gmail.com> - 2015-05-02 16:50 +0300
Re: Python is not bad ;-) Joonas Liik <liik.joonas@gmail.com> - 2015-05-02 18:53 +0300
Re: Python is not bad ;-) Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-02 11:00 -0600
Re: Python is not bad ;-) Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-02 11:17 -0600
Re: Python is not bad ;-) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-02 18:22 +0100
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-05-02 12:29 +0200
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-05-02 11:33 +0200
Re: Python is not bad ;-) Dave Angel <davea@davea.name> - 2015-05-02 06:35 -0400
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-05-02 13:12 +0200
Re: Python is not bad ;-) Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-02 09:31 -0600
Re: Python is not bad ;-) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-01 15:56 +1000
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 13:10 +0200
Re: Python is not bad ;-) Michael Torrie <torriem@gmail.com> - 2015-04-30 08:03 -0600
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 18:11 +0200
Re: Python is not bad ;-) Christian Gollwitzer <auriocus@gmx.de> - 2015-04-30 19:59 +0200
Re: Python is not bad ;-) Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 22:05 +0200
csiph-web