XML-Lit is a simple program to perform very basic literate programming with any XML-based markup language. It uses James Clark's Expat XML parser to weave (convert to a form suitable for processing) and tangle (extract the source code from) your XML documents. It has only been tested with DocBook at the moment, but there is no reason why it should not work with any arbitrary XML markup.
> This algorithm always stops even if you
> ask f(-1), you must remember that the C
> int is not an infinit set as the math Z.
> when the counter gets to the value
> MININT it will turn into MAXINT and goes
> down from there tilll it gets in 1. The
> simple code below will show this :
Aye, but you still get wrong code. :P But I'm not just talking about the factorial function, of course. Let's generalize the situation. What if you had a function which for certain unspecified (and probably unknown) inputs goes into an infinite loop through some complex contortions? A compiler presented with code with an application of this function to one of those unspecified constants that induces infinite loops would also loop forever attempting to fold the constant. Remember that there's no algorithm capable of finding infinite loops in their fullest generality (the halting problem again).
Also, for a pure functional language (with no side effects, static binding, and so forth), such a strategy of folding constants from function applications might be feasible (but see above for caveats), but for an imperative language which depends on side effects, the algorithm explodes in complexity. If the value of a function happens to depend on side effects outside of its scope, what do you do? Throw away all of the work you made before figuring out that you have to run the program in its entirety? Jeez, if you're going to all this trouble, don't bother compiling your program. Write an interpreter. :)
> int f (int n)
> if (n==1) return 1;
> return n * f(n-1);
> A super intelligent compiler would
> replace f(3) to the value 6.
Well, you could wind up getting a compiler that goes on a vain attempt at solving the halting problem if you tried to do this. What would your compiler do if it got f(-1), an expression that never halts? It wouldn't be able to figure out that it's doing infinite recursion (if you found an algorithm to determine this in the fullest generality, you would have solved the halting problem, and proved Alan Turing and Kurt Goedel wrong).
Finding the fastest code to perform a certain task is clearly an undecidable problem (this is worse than NP-complete, as it can be mathematically shown that an algorithm simply doesn't exist). The best I think that can be accomplished is a few heuristics that conform to some simple facts we know about how to speed code up.