Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93758

Re: Possibly Pythonic Tail Call Optimization (TCO/TRE)

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <antoon.pardon@rece.vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'needed,': 0.05; 'received:134': 0.05; 'indicated': 0.07; 'python': 0.10; 'stack': 0.13; 'accidental': 0.16; 'general.': 0.16; 'iteration': 0.16; 'marker': 0.16; 'processed.': 0.16; 'received:ac.be': 0.16; 'wrote:': 0.16; 'later': 0.16; 'instance,': 0.18; 'stick': 0.18; '>>>': 0.20; 'machine': 0.21; 'please?': 0.22; 'programming': 0.22; '(or': 0.23; 'seems': 0.23; 'written': 0.24; 'header:In- Reply-To:1': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'chris': 0.26; 'function': 0.28; 'measure': 0.29; 'solution,': 0.29; 'tail': 0.29; 'subject:/': 0.30; 'connection': 0.30; 'code': 0.30; 'received:be': 0.30; 'functional': 0.32; 'problem': 0.33; 'usually': 0.33; 'programming,': 0.33; 'next': 0.35; 'could': 0.35; 'text': 0.35; 'done': 0.35; 'direction': 0.35; 'easiest': 0.35; 'sometimes': 0.35; 'but': 0.36; 'needed': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'doing': 0.38; 'means': 0.39; 'data': 0.39; 'does': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'your': 0.60; 'avoid': 0.61; 'making': 0.62; 'more': 0.63; 'limit': 0.65; 'natural': 0.67; 'state.': 0.72; 'connection.': 0.76; 'iterative': 0.84; 'recursion,': 0.84; 'comment.': 0.91; 'problems?': 0.91
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result Ah8HAEbCo1WGuA9G/2dsb2JhbABbhCwBg0a9PoJUAoF+AQEBAQEBhS4BAQEDASNVEQsYAgIFFgsCAgkDAgECAUUTCAIXiAsItCyQaIR4AQEIAiCBIooqhC5fFoJSgUMBBJQxh0eEPYE/hBiCXoxXg18mY4MagXKBRgEBAQ
Date Mon, 13 Jul 2015 15:55:50 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Possibly Pythonic Tail Call Optimization (TCO/TRE)
References <CAD+URuj-4e62-9hvpiLsrBP1M6kXRyZhZ6XyL01gWWnDoShvNg@mail.gmail.com> <CAPTjJmrnd2cdA75ROZUKsJfYMdYUXkxRbEN50UE_-r0Jg=c5nQ@mail.gmail.com> <55A3A853.4040006@rece.vub.ac.be> <CAPTjJmr92j+2DDPsZxynoHyZTTCpc-48cWCVrx_fT3dA0j_Osg@mail.gmail.com>
In-Reply-To <CAPTjJmr92j+2DDPsZxynoHyZTTCpc-48cWCVrx_fT3dA0j_Osg@mail.gmail.com>
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
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.466.1436795752.3674.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1436795752 news.xs4all.nl 2821 [2001:888:2000:d::a6]:60086
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93758

Show key headers only | View raw


On 07/13/2015 02:34 PM, Chris Angelico wrote:
>
>>> Warping your code around a recursive solution
>>> to make it into a perfect tail call usually means making it look a lot
>>> less impressive; for instance,
>> And sometimes your problem is very easily solved by a number of functions
>> that tail call each other but in python you will need to warp your code
>> around an iterative solution, in order to avoid the stack limit.
> Example, please? In all my Python programming, I've never hit the
> stack limit outside of deliberate playing around (or accidental
> infinite recursion, which means it's doing its job).

I have had to process text coming from a network connection. The data
was mosly unstructered text with some lines that could be used as markers
to proceed through some kind of state machine that indicated how the
following lines needed to be processed. That was easiest written by having
a function for each "state" that would process the next lines until
a marker line was encountered and then call the function corresponding
with the next state. However since a connection could stay active for
days, sooner or later a stack limit would occur if done the natural
recursive way.

>> It seems warping your code is only seen as a problem when going in the
>> functional direction. Going into the iterative direction may take all
>> the warping that is needed, without comment.
> That's because I've never seen code that warps more for iteration than
> it does for programming in general. Again, example please?

And since when is your experience the measure stick for what other people
encounter as problems?

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-13 15:55 +0200

csiph-web