I was wandering aimlessly through the murky waters of the interwebs having forgotten my surfboard at home. After hours and hours of swimming around in the dark I stumbled upon
this dude. From what I understood by skimming through the website, the guy is doing artsy spirity things using electromagnetism instead of
classical stuff. Kind of cool because very few people do art and electronics and programming. So his scrying boards are programmable in
Scheme which is supposed to be (his words): novel, highly expressive, dynamic, introspective, elegant, extensible, a {lightweight, mobile, active} means of describing worlds and processes, thus perfect for such stuff as scry-programming. Wow. So if you followed the Wikipedia link you might have seen that ugly lambda starring at you. After a quick skim through the article, I most sincerely can't find the elegance, expressiveness, beauty, simplicity or whatever this language is supposed to have. Before going to Wikipedia I first looked
here, where else but the
famous MIT. There's that damned lambda again. Why do people have to hail lambda calculus and build virtual statues and monuments to lambda calculus and kiss it in the ass like it's somekind of hyper-meta-rational godly piece of abstract shit? So I go to the big famous MIT and what do I see? A crappy black and white logo that's the most noisy logo I've seen in the last 6 months. (shiver!) Why can't people antialias their pictures? Is it so hard? Or is 1-pixel wide monochrome the new fad? There are tons of image editing packages out there that can do a proper picture resize, and many of them are free. But people still put out bad graphics because a)they're lazy or b)they don't care for proper sampling and quantization. Well of course they don't, they care for lambdity (lambdaness? lambdacity?). I took a quick look over the Scheme doxumentation on the MIT site and damn, I really can't call it simple, expressive, elegant, let alone introspective. But of course I can't argue about it not being statically scoped and properly tail-recursive, as its homepage states. So let's take the first decent example of Scheme code (is it called "code"? maybe it has some esoteric, intellectually pretentious name? am I perpetrating a terrible insult by calling it code and not self-referencing internally-reflexive external character-stringy description or something?) - so let's take this piece of code that's found on both Wikipedia and the MIT doxumentation and just post it here:
;;; The FACT procedure computes the factorial
;;; of a non-negative integer.
(define fact
(lambda (n)
(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:
/* 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;
}
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.
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)
m
(fact2 (- n 1) (* m n))))
(fact2 n 1))
Of course it has a pretentious name called proper tail-recursivity and Scheme is such a great, wonderful, revolutionary, INTROSPECTIVE =)) language for supporting it.
Here's the same shit in C, which also does not choke on negatives, unlike the code above.
int fact (int n)
{
int f;
for (f = 1; n > 1; f *= n--);
return f;
}
Fuck lambda calculus and
fuck computational linguistics.
1 comment:
The thing is, lambda calculus and functional programming are quite cool things. In that they are a different way of looking into the problem of programming. After all, a different paradigm. Moreover, functional programming is a useful (and supposedly quite used, now or in the past) tool for demonstrating calculability, recursivity, etc.
The example you display is too simple. Of course, everything that can be written in lambda calculus can also be written in C, as both are Turing equivalent. But I must admit, as having had one semester of functional programming, that it is interesting and provoking to do stuf in lambda calculus.
True, there's nothing like introspection and metaphysics, but it's nice.
Post a Comment