Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: A new module for performing tail-call elimination Date: Thu, 16 Jul 2015 22:45:09 +0300 Organization: A noiseless patient Spider Lines: 30 Message-ID: <87lhefanui.fsf@elektro.pacujo.net> References: <55a3dcd9$0$3024$426a34cc@news.free.fr> <55A6280C.3090602@rece.vub.ac.be> <55A76116.7070708@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="18939"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dBkz7ubI9/XvRGcOvetyz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:ZAa6tRv2V7jRbGQdB04/VlAOO+c= sha1:lPZ2FwKOWeuDB0qjon16y01eKWQ= Xref: csiph.com comp.lang.python:93956 Nobody seemed to notice that I just posted a fairly typical tail call function: ======================================================================== def setvalue(self, keyseq, value, offset=0): try: next = keyseq[offset] except IndexError: self.value = value return if next is Node.ANY: raise KeyError() try: child = self.children[next] except KeyError: self.children[next] = child = Node() child.setvalue(keyseq, value, offset + 1) ======================================================================== In the context, the tail call is at least as clear as the corresponding while/for loop. In the case of this function, tail call elimination is hardly needed because the key sequence is probably not all that long (and if it were, the accompanying lookup function would overflow the stack anyway). At any rate, it demonstrates how the idiom has its place in Python. Marko