Metaprogramming

metameta-programmingmetaprogramC++ metaprogramminglanguage processing programsmeta functionmeta programmingmeta-featuresMeta-functionsmeta-process
Metaprogramming is a programming technique in which computer programs have the ability to treat other programs as their data.wikipedia
201 Related Articles

Homoiconicity

homoiconiccode as datahomoiconic language
Having the programming language itself as a first-class data type (as in Lisp, Prolog, SNOBOL, or Rebol) is also very useful; this is known as homoiconicity.
This makes metaprogramming easier than in a language without this property: reflection in the language (examining the program's entities at runtime) depends on a single, homogeneous structure, and it does not have to handle several different structures that would appear in a complex syntax.

Metalanguage

meta-languagemeta languageMetalanguages
The language in which the metaprogram is written is called the metalanguage.
The act of working with metalanguages in programming is known as metaprogramming.

Elixir (programming language)

ElixirReiaJosé Valim
If programs are modifiable at runtime or if incremental compilation is available (such as in C#, Forth, Frink, Groovy, JavaScript, Lisp, Elixir, Lua, Perl, PHP, Python, REBOL, Ruby, Rust, SAS, Smalltalk, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.
The latter is supported by compile-time metaprogramming with macros and polymorphism via protocols.

Python (programming language)

PythonPython programming languagePython 2
If programs are modifiable at runtime or if incremental compilation is available (such as in C#, Forth, Frink, Groovy, JavaScript, Lisp, Elixir, Lua, Perl, PHP, Python, REBOL, Ruby, Rust, SAS, Smalltalk, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.
Object-oriented programming and structured programming are fully supported, and many of its features support functional programming and aspect-oriented programming (including by metaprogramming and metaobjects (magic methods)).

Self-modifying code

self-modifyingrun-time code generationRuntime Code Generation
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.
Regardless, at a meta-level, programs can still modify their own behavior by changing data stored elsewhere (see metaprogramming) or via use of polymorphism.

Lua (programming language)

LuaLua programming languageLuaJIT
If programs are modifiable at runtime or if incremental compilation is available (such as in C#, Forth, Frink, Groovy, JavaScript, Lisp, Elixir, Lua, Perl, PHP, Python, REBOL, Ruby, Rust, SAS, Smalltalk, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.
In general, Lua strives to provide simple, flexible meta-features that can be extended as needed, rather than supply a feature-set specific to one programming paradigm.

Lisp (programming language)

LispLisp programming languageLisp 1.5
Having the programming language itself as a first-class data type (as in Lisp, Prolog, SNOBOL, or Rebol) is also very useful; this is known as homoiconicity. If programs are modifiable at runtime or if incremental compilation is available (such as in C#, Forth, Frink, Groovy, JavaScript, Lisp, Elixir, Lua, Perl, PHP, Python, REBOL, Ruby, Rust, SAS, Smalltalk, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code. Metaprogramming was popular in the 1970s and 1980s using list processing languages such as LISP.
This allows easy writing of programs which manipulate other programs (metaprogramming).

Ruby (programming language)

RubyRuby programming languageRuby Application Archive
If programs are modifiable at runtime or if incremental compilation is available (such as in C#, Forth, Frink, Groovy, JavaScript, Lisp, Elixir, Lua, Perl, PHP, Python, REBOL, Ruby, Rust, SAS, Smalltalk, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.
It has support for introspection, reflection and metaprogramming, as well as support for interpreter-based threads.

C Sharp (programming language)

C#Visual C#C# programming language
If programs are modifiable at runtime or if incremental compilation is available (such as in C#, Forth, Frink, Groovy, JavaScript, Lisp, Elixir, Lua, Perl, PHP, Python, REBOL, Ruby, Rust, SAS, Smalltalk, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.
Metaprogramming via C# attributes is part of the language.

Nim (programming language)

NimNim programming languageNimrod
It is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C and C++, and compiling to C, C++, Objective-C, and JavaScript.

Template Haskell

It allows compile-time metaprogramming and generative programming by means of manipulating abstract syntax trees and 'splicing' results back into a program.

Aspect weaver

weavingweaveweaves
An aspect weaver is a metaprogramming utility for aspect-oriented languages designed to take instructions specified by aspects (isolated representations of significant concepts in a program) and generate the final implementation code.

Domain-specific language

Domain Specific Languagedomain-specificdomain-specific programming language
One style of metaprogramming is to employ domain-specific languages (DSLs).
A metacompiler is not only useful for generating parsers and code generators for domain-specific languages, but a metacompiler itself compiles a domain-specific metalanguage specifically designed for the domain of metaprogramming.

RascalMPL

Rascal Metaprogramming Language
Rascal is an experimental domain specific language for metaprogramming, such as static code analysis, program transformation and implementation of domain specific languages.

D (programming language)

DD programming languageD language
D supports five main programming paradigms: imperative, object-oriented, metaprogramming, functional and concurrent (actor model).

Nemerle

Compiler-compiler

parser generatorMetacompilercompiler compiler
The minimal input producing a compiler is a metaprogram specifying the object language grammar and semantic transformations into an object program.

Reflection (computer programming)

reflectionreflectivecomputational reflection
The ability of a programming language to be its own metalanguage is called reflection or "reflexivity".
Reflection is also a key strategy for metaprogramming.

Automatic programming

code generationSource code generationgenerative programming
A simple example of a metaprogram is this POSIX Shell script, which is an example of generative programming:
Generative programming and the related term meta-programming are concepts whereby programs can be written "to manufacture software components in an automated way" just as automation has improved "production of traditional commodities such as garments, automobiles, chemicals, and electronics."