Go rant
retard
re at tard.com.invalid
Tue Dec 22 14:58:26 PST 2009
Tue, 22 Dec 2009 14:51:55 -0600, Andrei Alexandrescu wrote:
> retard wrote:
>> I use the Okasaki book as my bible when talking about purely functional
>> data structures.
>
> It's an awesome book. It's also very frank and tells things as they are,
> as opposed to others (*cough*) that patronize the reader by artificially
> making it seem so easy, it's amazing how Stoopid People missed the
> point. Un-incidentally, Okasaki does not dabble in qsort. He does
> describe mergesort - a perfectly sound and advantageous sorting methods
> for lists.
>
> Ok, I'm itching to share another gem.
>
> "At this point you might be wondering how it's possible to program
> without variables. How can you express something like X = X + 1 in
> <language erased to protect the guilty>? The answer is easy. Invent a
> new variable whose name hasn't been used before (say X1), and write X1 =
> X + 1".
That's a nasty limitation indeed. From my point of view imperative
languages just pass around the global state with the value of the
computation, and the assignment (X=X+1) shadows the previous value of X.
In some cases this allows optimizing compilers to perform the assignment
in-place! :o) In fact, this is exactly what happens in another pure
functional language (name erased to protect the awesomeness):
foo x
# x = x + 1
x = x * 2
x = x - 5
= x
vs
T foo(T)(T x) {
x = x + 1;
x = x * 2;
x = x - 5;
return x;
}
More information about the Digitalmars-d
mailing list