Why Lisp? 3 answers
mattknox.com
mattknox.com
This is one of the most widespread misconceptions about compilers. You don't need to build an AST. All books that give this advice originate from academic environment and are completely out of touch with reality. Unfortunately these books can be credited for the terribly bloated compilers that we are using, including Python and Perl.
We can look at specific examples if you wish.
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.27.3...
> We can look at specific examples if you wish.
Common Subexpression Elimination, for example. Not just syntactically equal expressions but also cases like this:
a1 = b + c
a2 = c + b // eliminated
And how do you do loop fusion & interchange?Edit: I now realise that we may be talking about different abstract syntax trees. I thought that you meant no intermediate data structures. But you probably meant that you don't need a parse tree, you can translate to the intermediate language directly from the source. If that's the case then here's another challenge: how do you produce error messages for type errors?
Can you give an example of an Open Source (so we can learn how it is done) compiler that embodies an alternate strategy?
Turbo Pascal - probably the smallest and the fastest commercial compiler ever made - well, for an imperative language - was inspired by Wirth's book, too (see http://en.wikipedia.org/wiki/Algorithms_%2B_Data_Structures_... )
"The entire fifth chapter of the first Edition has been omitted. It was felt that the subject of compiler construction was somewhat isolated from the preceding chapters and would rather merit a more extensive treatment in its own volume. "
Ur-Scheme (http://canonical.org/~kragen/sw/urscheme/) doesn't have any intermediate representation other than the S-expression representation of the code; it uses that to perform closure analysis. Probably an AST is the easiest form to perform this on. The Lua guys came up with an implementation technique for closures that doesn't require building a parse tree first, but it's quite a bit more complicated.
"best to do X" is clearly a good, though, which is listed as part of the 1st reason.
an important reason not mentioned is library support. for practical reasons many programmers want not just "a good language" but a language where they don't have to re-invent the wheel or forge new territory (of course, that can be satisfying, too, if one has the time). this is likely the case with any language that has been around a while.
i don't know if this is the case with lisp. did that reason seem not important enough for the list, or are libraries/frameworks lacking?
If a certain task or problem arises that isn't directly related to or considered one of the main problems that you're trying to solve with your program, you would consider the use of a library to accomplish that task. If there is such a library available, go ahead and use it. If there isn't, Lisp programmers can spend a short amount of time implementing only what they need without generalizing the task.
This isn't quite re-inventing the wheel since you have a unique set of constraints, and it's certainly not as onerous a task as writing a generalized library. There are those (Edi Weitz for example) who do tend to implement complete libraries, and the Lisp community is of course grateful for that.
Libraries and frameworks can be useful, but they also have the effect of levelling the playing field. Lisp empowers the programmer to `discover' a natural solution to their problem in a unique way.