Go rant

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 22 18:06:33 PST 2009


retard wrote:
> 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;
> }

Hm, I guess I should have been more explicit. The problem isn't defining 
a few more names, but that the explanation completely neglects any 
control flow issues (e.g. conditionals and loops). You can't define a 
new name for each instance of a loop, so everything is recursion etc. I 
mean the consequences are earth-shattering. There is absolutely no doubt 
the author is aware of the fact that single assignment is a lot more 
than just defining a few names, so I find it very questionable that he 
chose to put things that way. And the book has much more allegations 
like that one!

Imagine you'd find this in a book for learning French: "Translating from 
English to French is very easy - just replace English words with the 
corresponding French words."


Andrei



More information about the Digitalmars-d mailing list