2 ms·
Macros violate the property that any subexpression can be evaluated and understood on its own. This is meant to be one of the benefits of functional programmin
by amalcon 17y ago
Macros violate the property that any subexpression can be evaluated and understood on its own. This is meant to be one of the benefits of functional programming. I agree here.
The counterpoint to this is that they don't break this property as severely as side effects do, because these violations can be algorithmically understood at compile time. While understanding macros is not a computable task in the general case, it is in the specific case where the program successfully compiles after only a finite amount of time.
This raises the question: is there some abstraction that can give us some of the power of macros with less violation of the above property? Scheme-style syntax-case macros and Ruby-style code block parameters help with shortening common idioms. Python-style compile mechanism subversion (metaclasses) and user-defined infix operators help with DSLs.
Nothing else is quite as powerful as the macro (pretty much by definition). We might be able to get something almost as good, and a lot cheaper in terms of semantic overhead.