The LISP macros make me jealous. What non-LISP-like languages have macros? Nemerle does and looks fairly neat. It'd seem like somehow passing the AST to user-defined modules would get ya pretty far, but there must be a ton of complications, otherwise more languages would offer it.
I suppose we can consider converting quoted code to another target (like GPU, or database) as metaprogramming. I guess I had filed that under "just reflection".
1. super-easy development of new parsers/compilers (lisp macros)
2. shenanigans with dynamicism and first class functions.
Both of those are cool! But I can't figure out what they have to do with each other, other than that you don't get much of that sort of thing in Java/C.
One nice example of modifying code on the fly I just remembered is goto decorator in Python: http://code.activestate.com/recipes/576944-the-goto-decorato... As for code generation, if I recall correctly, Salt (http://docs.saltstack.com/en/latest/) uses YAML and Jinja2 to generate shell scripts. These are very different techniques, but the thing they have in common is that they manipulate code, which makes them both examples of meta-programming.
At least that's how I understand the term :)
- corporate sponsorship dried up
- it wasn't open source, and by the time squeak came around, usage had dried up considerably
- it was actually too hard to learn
Although, it's unfair to judge it by today's standards. The sheer number of open source programmers just didn't exist when Smalltalk was popular.
You see some vestigial remnants of smalltalk in modern languages (in ruby, everything is an object, dart allows you to snapshot the object memory, the idea of a virtual machine, etc, etc) but having all of them together made smalltalk quite groundbreaking. We haven't really learned all the lessons quite yet, either. (Just my opinion). One of the biggest misunderstandings was that object oriented programming is really about message passing, not about encapsulation.
For more: http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html
Anyway, Smalltalk still exists and not only as an inspiration for Ruby. Pharo and Squeak are very nice image-based environments, VisualWorks has "enterprise grade" support, GNU Smalltalk is small and lightweight and works well for scripts. There is Amber, which tries to recreate Smalltalk image inside the browser and there's (forgot the name) which tries to implement ST on JVM (it was on kickstarter I think). There's also Newspeak, which is highly experimental, and LivelyKernel (by Dan Ingals) which again transplants some of the more important ST ideas into the browser. And all that on top of mainstream languages gaining more and more features which Smalltalkers are used to. It's certainly an interesting time to be a part of Smalltalk community.
There's a chapter in pg's "On Lisp" about continuation-passing-style transformation (from sequential code to CPS) done with meta-programming. Worth reading, too.
If you're an Emacs user, the source code of EIEIO is a good read. It's an object system implemented on top of Elisp using it's meta-programming capabilities.
In Smalltalk-land the most impressive example of meta-programming is certainly a debugger. You get to inspect the state of objects while they are running, you can modify it, and you can modify method bodies while they are running. Scary stuff.
In Python some nice meta-programming code lives in Django ORM, in Model metaclass, and in Fields. This is the code which allows you to declaratively define your models as classes. Similar code is used in Django Forms.
The talk "Five years of bad ideas" by Armin Ronacher is a 40-minuted tour of some of the most advanced meta-programming available in Python.
In JavaScript every library which implements "classical classes" on top of objects and prototypes uses meta-programming. You can read about it more in depth in Raganwald "the art of javascript meta-object protocol" and his other talks and posts.
Angular.js dependency injection framework is based on meta-programming; actually I had a mixed reaction when I saw the code for this, where they rewrite a user supplied function as a string and compile a new function out of this string. It's a good example of meta-programming, but it's also very crude compared to hygienic macros in Schemes for example. It lives here: https://github.com/angular/angular.js/blob/master/src/auto/i...
Generally, meta-programming is a vast and varied set of techniques. It's worth knowing about them, because most of the time you don't need them, but when you do, you really, really need them very much.