Oh, how quickly we forget. Or to put it another way, how stupid I am. Or to put it another way, what a fickle language whore I am.
Further to my recent joy regarding Haskell, Stephen Judd appeared from nowhere and reminded me that of course, Python also handles arbitrary-length integers “out of the box”. How the hell did I forget that?
In fact, he went one better and gave me a single line of Python for calculating 10,000 factorial, viz:
reduce(lambda x,y:x*y, range(1,10001))
Admittedly this is harder to grok than the Haskell version:
bigFac :: Integer -> Integer bigFac n | n == 0 = 1 | n > 0 = n * bigFac(n-1)
(at least, without knowing the semantics of reduce) – but it does also seem to run a bit quicker on my box.
Hurrah for Python!
Of course, this all just reminds me that I’m spending too much time lately thinking about theoretical computer science, and not enough time getting my hands dirty programming… :-/
Update 2007-01-26: Of course, the python version is not easier to grok than this alternative Haskell version:
Now that’s beautiful, as is the definition of product.