;;; The FACT procedure computes the factorial
;;; of a non-negative integer.
(if (= n 0)
1 ;Base case: return 1
(* n (fact (- n 1))))))
Man, now that's introspective!
The same code written in a proven, widely used, respectable, expressive language like C would sound a little bit like this:
Much cleaner eh? Compare that to 1-2-3-4-5-SIX parenthesis. And their code screws up bigtime for negative numbers assuming n is a signed integer (I don't know, I hate lambda-anything, I suck), while mine doesn't. (Who would want to be using unsigned numbers by default anyway??) Mine also warns the careless programmer who feeds negative numbers to the factorial function. So not only is their canonical "hello world plus a little bit more" example ugly, it's also an infinite loop if my perfectly reasonable assumption of n being allowed to be negative as well as positive holds. Well, it might not be infinite because the hardware might not let it, but that's fucking bad practice. And after 5 more minutes of searching it seems that my assumption indeed holds, because according to the MIT documentation (- 3 4) gives -1. After another 5 minutes I opened up a GIMP script console and entered the code, then called the function with -1. It froze.
/* If you do not know what a factorial is
you should search it on Wikipedia or Google. */
int fact (int n)
assert(n >= 0); //jackass!
return n > 1 ? n * fact(n-1) : 1;
This more complicated example does the same shit but without (rather idiotically) wasting stack space with recursive function calls:
(define (fact n)
(define (fact2 n m)
(if (= n 0)
(fact2 (- n 1) (* m n))))
(fact2 n 1))
Here's the same shit in C, which also does not choke on negatives, unlike the code above.
int fact (int n)Fuck lambda calculus and fuck computational linguistics.
for (f = 1; n > 1; f *= n--);