History of Metaprogramming
Brian Harvey
Teaching Professor Emeritus
University of California, Berkeley
What’s “Metaprogramming”?
Metaprogramming is a programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyze or transform other programs, and even modify itself while running. In some cases, this allows programmers to minimize the number of lines of code to express a solution, in turn reducing development time. It also allows programs greater flexibility to efficiently handle new situations without recompilation.
Metaprogramming can be used to move computations from run-time to compile-time, to generate code using compile time computations, and to enable self-modifying code. The ability of a programming language to be its own metalanguage is called reflection. Reflection is a valuable language feature to facilitate metaprogramming.
—Wikipedia
Are higher order functions metaprogramming?
“the ability to treat other programs as data.”
“to generate code”
Metaprogramming out in the real world: text macros.
#define foo(x) #x)
#include <stdio.h>
#define foo(x) #x)
prints 87
main(){
printf("%s\n",foo(87);
}
Lisp 1.5 FEXPRs
Macro evaluation environments
Eval-twice macros
(define-macro (cons-stream . args)
`(cons ,(car args) (delay ,(cadr args))))
Snap! isn’t self-reflective.
Metaprogramming in Snap! 8.0