Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: Throw the cat among the pigeons Date: Sun, 03 May 2015 17:12:21 +0200 Organization: Decebal Computing Lines: 33 Message-ID: <871tixlmp6.fsf@Equus.decebal.nl> References: <87h9rvm576.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="1e75f8f7bcfe2945d0316cb03b0f6951"; logging-data="9556"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lhKmRr//cTj3mzEFCCOxdEMBPxF2/Mk4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E Cancel-Lock: sha1:Rr1SJywZrWUGt7y1sIPF6c/rL34= sha1:HZH2kNV3/uu8CAGpqPOhObEcExk= X-Homepage: http://www.decebal.nl/ Xref: csiph.com comp.lang.python:89871 Op Saturday 2 May 2015 16:20 CEST schreef Cecil Westerhof: > I am throwing the cat among the pigeons. ;-) > > In another thread I mentioned that I liked to have tail recursion in > Python. To be clear not automatic, but asked for. > > Looking at the replies I did hit a nerve. But I still want to > continue. > > Some things are better expressed recursively for the people reading > the code. But there are two problems with that: > - You can get out of stack space > - It is less efficient > > Most of the time the first problem is the most important. > > When I write factorial (I know it is already written, but I use it > as an example to show a point), the recursive variant can not be > called with 1.000 without tail recursion. So for functions that > could go very deep, tail recursion would be a blessing. > > By the way: I think that even if the recursion does not go further > as 500, it is still a good idea to use tail recursion. Why use stack > space when it is not necessary? I pushed the example to GitHub: https://github.com/CecilWesterhof/PythonLibrary/blob/master/mathDecebal.py -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof