Here comes the source code to the file-reversion program as promised.
It's Scheme. Cool, innit?
I am reading a book called "Gödel, Escher, Bach: An eternal golden braid". The first part is interesting, it's much about complexity and formal systems, and Gödels theorems of undecidability in particular. The second part seems to me to be mostly about AI. It's a little disappointing to see the presiscion of the first part give way to the wishful thinking of the second. I am reminded of something my father says: "Mathemathics books never become outdated, physics books become outdated in fifty years, computer science books become outdated in ten years at best". Lots of my comments in the reversed text applies to this second part of the book: It seems to me that they believe that if they make something so complex that they don't really understand it, perhaps it'll think. Lisp is a different way of looking at things, but beware, lest it seduces you onto a trail that leads nowhere.
Thirty years after the book I read was written, LISP has not delievered on it's promises. The world chess champion has been beaten by a computer (the author believed we wouldn't see that in our time), but the program was not written in lisp. In fact, the programs that try to "think like humans" have proved inefficient and weak compared to those that make direct use of computer's strength in number crunching.
But I try to learn Scheme anyway, just as I try to learn Esperanto, even though I don't believe it will solve all the world's linguistic troubles (like some of its adherents believe). It's just that they are fascinating ideas in their own right, even if they are not entirely correct.
(define reverse-file
(lambda (filename) ;x må være en string
(call-with-input-file filename
(lambda (i)
(let loop ((in (read-char i)) (l (list)))
(if (eqv? in eof)
(list->string l)
(begin
(set! l (cons in l))
(loop (read-char i) l))))))))