3 ms·
Isn't this missing the joke? The Haskell article code ended with the "Tenured Professor" implementation (`fac n = product [1..n]`) as a nod to the old trope of
by roenxi 2y ago
Isn't this missing the joke? The Haskell article code ended with the "Tenured Professor" implementation (`fac n = product [1..n]`) as a nod to the old trope of not needing to implement anything. This article ends with `(define factorial (dynamic-require 'math/number-theory 'factorial (lambda () lambda (n) (error 'factorial "Cannot import library: ~a" 'math/number-theory)))))`.
Surely there is a lazier implementation than a define and 2x lambdas to use a library function. Although I did get a chuckle about not feeling a need to add brackets to the Scheme example.
- Y_Y 2y agoBut the extra code is for handling the error, you could just `require` it and be done if you want to assume the library is available.
- shawn_w 2y agoNormal Racketeers would just `(require math/number-theory)` and be done. No idea why they're loading the module at runtime like that instead, unless it's a deliberately over complicated joke solution like some of the others. Which would as you noted miss the point of the original.
- qart 2y agoThankfully, the tenured professor version works in Julia like so: prod(1:63) For bigger numbers, factorial(n) = 1:n .|> BigInt |> prod
- soegaard 2y agoIt's not the best algorithm for computing factorials though. A better strategy is to pair small and large factors together in order to avoid bignum computations (or to reduce the size og bignum computations). https://people.eecs.berkeley.edu/~fateman/papers/factorial.pdf https://people.eecs.berkeley.edu/~fateman/papers/factorial.p... Also: It's more fun to use the name `fact` in benchmarks...
- MaxBarraclough 2y agoThe rabbit-hole goes much deeper than that. https://en.wikipedia.org/wiki/Factorial#Computation https://en.wikipedia.org/wiki/Factorial#Computation