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!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'memory.': 0.05; 'dynamically': 0.07; 'sized': 0.07; 'wrapper': 0.07; 'cc:addr :python-list': 0.09; 'semantics': 0.09; 'stack,': 0.09; 'stack': 0.13; 'def': 0.13; 'argument': 0.15; 'detects': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'joonas': 0.16; 'liik': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'memory': 0.17; 'instance,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'not,': 0.22; 'terminate': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'disk': 0.27; 'accidentally': 0.29; 'subject:/': 0.30; "can't": 0.32; 'run': 0.33; 'quickly': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'trouble': 0.35; 'could': 0.35; 'acceptable': 0.35; 'possible': 0.36; 'subject:: ': 0.37; 'virtual': 0.38; 'some': 0.40; 'care': 0.60; 'your': 0.60; 'default': 0.61; 'side': 0.62; 'back': 0.62; 'more': 0.63; 'limit': 0.65; 'finally': 0.70; 'jul': 0.72; 'grow': 0.75; 'chrisa': 0.84; 'devoted': 0.84; 'to:none': 0.91 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=iUCGUlq4wx12O9foZhP9tEZhsit3TiltYOOt8KjapM0=; b=eSQTk7TtbPCZaX2L0ts3ovXT9oOCn6zb+aKq96qRhcI3oOTEXLX+Yi130ZPM8Zotyi WUZFIcC4chURm2sRFMdHmoP5RU8u23dz2KpypFDXwYf8EqlqcCbIaN5DMju9l9gFHlPD k5Ca3noETeJAt3y80T6XwU02QcNPFpPXUm2tHe7ZrhWLldxNOFva4KYIzCtP5aXvfkK7 eriYslruVSf3aZOmibXTsY1ac1KAiyrhpkAKvPDN2ExNpp5sogmYxd54xHpHCnWhdZAV yBb+798Z5xeDYB7s/98yQw43YKYf7c44L2MdiYwNWApYfaR+LuLNR6EsVMEoP2wCHECO bv4Q== MIME-Version: 1.0 X-Received: by 10.50.36.72 with SMTP id o8mr5509159igj.16.1437066228933; Thu, 16 Jul 2015 10:03:48 -0700 (PDT) In-Reply-To: References: <55A3C366.6060602@rece.vub.ac.be> <87fv4r1fre.fsf@jester.gateway.sonic.net> <87bnff1eks.fsf@jester.gateway.sonic.net> <87d1zunctp.fsf@elektro.pacujo.net> <87k2u2eu67.fsf@elektro.pacujo.net> <55A51662.4090007@rece.vub.ac.be> <55A75DE0.1070101@rece.vub.ac.be> <55A7B80B.6090905@rece.vub.ac.be> <55A7C094.7060604@rece.vub.ac.be> Date: Fri, 17 Jul 2015 03:03:48 +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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437066231 news.xs4all.nl 2946 [2001:888:2000:d::a6]:45822 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93937 On Fri, Jul 17, 2015 at 2:50 AM, Joonas Liik wrote: > Wouldn't it be possible to have like a dynamically > sized stack so that you can grow it endlessly > with some acceptable overhead.. > > That would pretty much take care of the stack-overflow > argument without many painful side effects on > the semantics at least.. The trouble with that is that it can quickly run you out memory when you accidentally trigger infinite recursion. A classic example is a simple wrapper function... def print(msg): print(ctime()+" "+msg) With the recursion limit at its default of 1000, this can't do more than 1000 iterations before the system detects that it's stuck. With an infinite stack, this could destroy your system memory and then finally terminate with MemoryError... if you're lucky. If you're not, the whole system could get wedged before this gets killed. (Imagine, for instance, a computer with a large hard disk devoted to virtual memory. Long before that's exhausted, the system will be practically unusable, because every little operation will require going back to the disk.) ChrisA