Because macros let you control code in a way libraries don't^1.
Java now has this way to iterate over a collection of things:
for(String exclamation: exclamations) {
System.out.println("I yell " + exclamation + " at you");
}
But this was only added in 2004!^2 So for almost 10 years, you had to manually iterate over stuff. How would you implement this as a library? Well, you could write a function that lets you write:
iterate_over_collection(exclamations, function(collection) {
System.out.println("I yell " + exclamation + " at you");
}
But this is much uglier than the prior code. Also, it might not act the same. For example:
int highest = ages[0];
for(int age: ages) {
highest = Math.max(highest, age);
}
Would this work in a lambda? Well, if the language you're using has real closures, yes -- but does it? Do you know offhand? With a macro, your code will work.
> Even if you ignore the above, there's probably a good reason why the language designers don't want to approve your language-level feature. ... it can also be that you -- the applications programmer -- simply aren't well-versed in language design and can't think past your particular use case :) This wouldn't mean the feature is worthless (after all, you need it!)
That seems like evidence for my point -- macros let you build the language up for your own use case, not anyone else's. Without macros, your choices are "either everyone can use it, or no one can use it". Macros let you have a choice of "well, I can use it, even if no one else wants it, if I find it useful."
Macros can be viewed as libraries that act on the language itself. There isn't a difference between language-level features and "library functions" in a language with macros.
[1] Without getting into a Turing Tarpit. We're talking about using things in easy ways, not what is technically possible but ugly and kludgy.
[2] It was released in Java 5.0: http://www.java-tips.org/java-se-tips/java.lang/the-enhanced...