It’s been a while since Paul Graham wrote his revenge of the nerds an essay exploring the differences between lisps and other languages, in it he explores 9 ideas that were originated in lisps and were gradually copied to other languages (or maybe reinvented) in the last 40 years.
The last 2 ideas are still unique to Lisp:
- A notation for code using trees of symbols and constants. (Code is data)
- The whole language there all the time.
What Paul meant by the whole language being there the whole time, is that even when reading or compiling your program you can execute your own code, this idea combined with the idea that your code is data gives you the ability to change code as it is read or compiled this is what gives us Lisp’s macros!
The interesting bit is that language designers want to be able to modify their own code at compile time more and more, and at last there are efforts in mainstream languages that achieve something similar.
Look at this:
Nice efforts to reinvent the last idea! But people is trying to achieve it without code being data, and that makes things awfully complicated and a lot less powerful.
If you grab a lisp book chances are that you’ll get to macros eventually, even in entry level books. Perhaps you have to get used to a different syntax from the beginning but I do not think it is harder, it’s just that people prefer familiar ideas.
With groovy and scala I’m sure it will be an advanced topic, because you’ll need to understand how the AST works in that particular language.
I believe the lisp way is the best way, but if you don’t want to have a notation for representing code as data what sweet.js has done looks good. It may not be as powerful as being able to modify the complete AST at runtime, but it is simple and easy to reason about.
Anyway, it looks like a new revenge of the nerds is coming.