homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jason.Baker
Recipients Jason.Baker, eric.araujo, ncoghlan, rhettinger
Date 2011年01月26日.03:52:55
SpamBayes Score 0.00025701677
Marked as misclassified No
Message-id <1296013978.17.0.320781243661.issue11011@psf.upfronthosting.co.za>
In-reply-to
Content
I'm not sure I understand how Raymond's alternative for trampoline works. Let's take the factorial algorithm from wikipedia's page on tail recursion[1]. I've implemented the tail recursive version of the algorithm in Python using trampoline:
 from functools import trampoline, partial
 def factorial(n):
 def fact(i, acc):
 if i:
 return partial(fact, (i-1), (acc * i))
 else:
 return acc
 return trampoline(fact, n, 1)
 >>> factorial(5)
 120
How would I implement this using Raymond's alternative?
[1] http://en.wikipedia.org/wiki/Tail_call#Example_programs 
History
Date User Action Args
2011年01月26日 03:52:58Jason.Bakersetrecipients: + Jason.Baker, rhettinger, ncoghlan, eric.araujo
2011年01月26日 03:52:58Jason.Bakersetmessageid: <1296013978.17.0.320781243661.issue11011@psf.upfronthosting.co.za>
2011年01月26日 03:52:55Jason.Bakerlinkissue11011 messages
2011年01月26日 03:52:55Jason.Bakercreate

AltStyle によって変換されたページ (->オリジナル) /