Information about Metaprogramming
This article is about the programming technique. For the management technique, see Metaprogramming (management).
Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data or that do part of the work during compile time that is otherwise done at run time. In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually.
The language in which the metaprogram is written is called the metalanguage. The language of the programs that are manipulated is called the object language. The ability of a programming language to be its own metalanguage is called reflection or reflexivity.
Reflection is a valuable language feature to facilitate metaprogramming. Having the programming language itself as a first-class data type (as in Lisp) is also very useful. Generic programming invokes a metaprogramming facility within a language, in those languages supporting it.
Metaprogramming usually works through one of two ways. The first way is to expose the internals of the run-time engine to the programming code through application programming interfaces (APIs). The second approach is dynamic execution of string expressions that contain programming commands. Thus, "programs can write programs". Although both approaches can be used, most languages tend to lean toward one or the other.
Examples of metaprogramming
A simple example of a metaprogram is this bash script, which is an example of generative programming:- !/bin/bash
- metaprogram
This script (or program) generates a new 993 line program which prints out the numbers 1–992. This is only an illustration of how to use code to write more code, not the most efficient way to print out a list of numbers. Nonetheless, a good programmer can write and execute this metaprogram in just a couple of minutes, and will have generated exactly 1000 lines of code in that amount of time.
Not all metaprogramming involves generative programming. If programs are modifiable at runtime (such as in Lisp, Python, Smalltalk, Ruby, PHP, Perl, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.
The most common metaprogramming tool is a compiler which allows a programmer to write a relatively short program in a high-level language and uses it to write an equivalent assembly language or machine language program. This is a fundamental tool for programming since, in most cases, it is impossible or vastly impractical to write the machine language program directly.
Another still fairly common example of metaprogramming might be found in the use of lex and yacc, two tools used to generate lexical analyzers and parsers. Yacc is often used as a compiler compiler, a tool to generate a tool for translating high-level language programs to machine language.
A quine is a special kind of metaprogram that has its own source as its output.
One style of programming which focuses heavily on metaprogramming is called language-oriented programming which is done via domain-specific programming languages.
See also
- Source code generation
- Compile-time reflection
- Forth (programming language)
- Interpreted language
- Introspector (program)
- Metaobject
- MetaOCaml, multi-stage extension of OCaml
- Maude system, reflecive language based on rewriting programming
- Nemerle
- OpenC++
- Partial evaluation
- REBOL
- Recoder
- Self-interpreter
- Self-modifying code
- Template Haskell, extension to Haskell 98 for type-safe compile-time metaprogramming
- Template metaprogramming, a C++ compile-time example
- XL Programming Language
External links
- Metaprogramming and Free Availability of Sources by François-René Rideau
- MetaL - Metaprogramming language with source code in XML that is used to generate code in several target languages: Java, Perl, PHP, etc.
- DSLEngine - Scheme macro metaprogramming example
- MetaML - A version of ML with homogeneous (same-language) metaprogramming
- MetaOcaml - The language currently in development that descended from MetaML
- RECODER - Framework for source code metaprogramming in Java
- Metaprogramming Weblog - At Lambda the Ultimate
- Moka, a Java-to-Java extensible compiler
- why’s (poignant) guide to ruby - Metaprogramming in Ruby
- The art of metaprogramming, Part 1 - Introduction to metaprogramming, with codes in several languages
- David Mertz. A Primer on Python Metaclass Programming. ONLamp. Retrieved on June 28, 2006.
Types of Programming languages |
|---|
| Array Assembly Compiled Concurrent Curly bracket Data-structured Declarative Esoteric Data-oriented Extension Functional Interpreted Logic Machine Macro Metaprogramming Multi-paradigm Non-English-based Object-oriented Prototype-based Off-side rule Procedural Reflective Rule-based Synchronous Scripting Domain-specific Visual Dataflow Imperative |
Metaprogramming is the name of a management technique invented by Charles Simonyi (who also developed Hungarian notation) for organizing the work of a team of programmers. In a 2002 news item [1] , The Age noted:
..... Click the link for more information.
..... Click the link for more information.
A computer program is one or more instructions that are intended for execution by a computer. Specifically, it is a symbol or combination of symbols forming an algorithm that may or may not terminate, and that algorithm is written in a programming language.
..... Click the link for more information.
..... Click the link for more information.
In computer science, compile time refers to either the operations performed by a compiler (ie, compile-time operations) or programming language requirements that must be met by source code for it to be successfully compiled (ie, compile-time requirements).
..... Click the link for more information.
..... Click the link for more information.
- Run time: In the movie and television industry "run time" (also known as running-time) is the length of the film or program in minutes.
- Runtime: In computer science, runtime describes the operation of a computer program, the duration of its execution,
..... Click the link for more information.
metalanguage is a language used to make statements about other languages (object languages). Formal syntactic models for the description of grammar, e.g. generative grammar, are a type of metalanguage.
..... Click the link for more information.
..... Click the link for more information.
Object language has meaning in contexts of computer programming and operation, and in linguistics and logic.
..... Click the link for more information.
Programming
At their basic level, computers act on what is given to them through a limited set of instructions which are understood by their CPUs...... Click the link for more information.
In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior.
..... Click the link for more information.
..... Click the link for more information.
In computing, a first-class object (also value, entity, and citizen), in the context of a particular programming language, is an entity which can be used in programs without restriction (when compared to other kinds of objects in the same language).
..... Click the link for more information.
..... Click the link for more information.
Generic programming is a style of computer programming where algorithms are written in an extended grammar and are made adaptable by specifying variable parts that are then somehow instantiated later by the compiler with respect to the base grammar.
..... Click the link for more information.
..... Click the link for more information.
An application programming interface (API) is a source code interface that an operating system or library provides to support requests for services to be made of it by computer programs.
..... Click the link for more information.
..... Click the link for more information.
Bash is a Unix shell written for the GNU Project. The name of the actual executable is bash. Its name is an acronym for Bourne-again shell, a pun on the name of the Bourne shell (sh) (i.e.
..... Click the link for more information.
..... Click the link for more information.
- Scripting redirects here. For other uses, see script.
Scripting languages (commonly called script languages) are computer programming languages that are typically interpreted and can be typed directly from a keyboard.
..... Click the link for more information.
In computer science, the term automatic programming[1] identifies a type of computer programming in which some mechanism generates a computer program rather than have human programmers write the code.
..... Click the link for more information.
..... Click the link for more information.
Lisp
Paradigm: multi-paradigm: functional, procedural, reflective
Appeared in: 1958
Designed by: John McCarthy
Developer: Steve Russell, Timothy P. Hart, and Mike Levin
Typing discipline: dynamic, strong
Dialects: Common Lisp, Scheme, Emacs Lisp
..... Click the link for more information.
Paradigm: multi-paradigm: functional, procedural, reflective
Appeared in: 1958
Designed by: John McCarthy
Developer: Steve Russell, Timothy P. Hart, and Mike Levin
Typing discipline: dynamic, strong
Dialects: Common Lisp, Scheme, Emacs Lisp
..... Click the link for more information.
Python
Paradigm: Multi-paradigm
Appeared in: 1991
Designed by: Guido van Rossum
Developer: Python Software Foundation
Latest release: 2.5.1/ April 18 2007
Latest unstable release: 3.
..... Click the link for more information.
Paradigm: Multi-paradigm
Appeared in: 1991
Designed by: Guido van Rossum
Developer: Python Software Foundation
Latest release: 2.5.1/ April 18 2007
Latest unstable release: 3.
..... Click the link for more information.
Smalltalk
Paradigm: object-oriented
Appeared in: Development started in 1969
Publicly available in 1980
Designed by: Alan Kay, Dan Ingalls, Adele Goldberg
Developer: Alan Kay, Dan Ingalls, Adele Goldberg, Ted Kaehler, Scott Wallace, and Xerox PARC
..... Click the link for more information.
Paradigm: object-oriented
Appeared in: Development started in 1969
Publicly available in 1980
Designed by: Alan Kay, Dan Ingalls, Adele Goldberg
Developer: Alan Kay, Dan Ingalls, Adele Goldberg, Ted Kaehler, Scott Wallace, and Xerox PARC
..... Click the link for more information.
Ruby
Paradigm: multi-paradigm (functional, imperative, logic, object-oriented (class-based))
Appeared in: 1995
Designed by: Yukihiro Matsumoto
Developer: Yukihiro Matsumoto (among others)
Latest release: 1.8.
..... Click the link for more information.
Paradigm: multi-paradigm (functional, imperative, logic, object-oriented (class-based))
Appeared in: 1995
Designed by: Yukihiro Matsumoto
Developer: Yukihiro Matsumoto (among others)
Latest release: 1.8.
..... Click the link for more information.
PHP
Paradigm: imperative, object-oriented
Appeared in: 1995
Designed by: Rasmus Lerdorf
Developer: The PHP Group
Latest release: 5.2.4/ 30 August 2007
Typing discipline: Dynamic, weak (duck typing)
Influenced by: C, Perl
Java, C++, Python
..... Click the link for more information.
Paradigm: imperative, object-oriented
Appeared in: 1995
Designed by: Rasmus Lerdorf
Developer: The PHP Group
Latest release: 5.2.4/ 30 August 2007
Typing discipline: Dynamic, weak (duck typing)
Influenced by: C, Perl
Java, C++, Python
..... Click the link for more information.
Perl
Paradigm: Multi-paradigm
Appeared in: 1987
Designed by: Larry Wall
Latest release: 5.8.8/ January 31 2006
Typing discipline: Dynamic
Influenced by: AWK, BASIC, BASIC-PLUS, C, C++, Lisp, Pascal, Python, sed, Unix shell
..... Click the link for more information.
Paradigm: Multi-paradigm
Appeared in: 1987
Designed by: Larry Wall
Latest release: 5.8.8/ January 31 2006
Typing discipline: Dynamic
Influenced by: AWK, BASIC, BASIC-PLUS, C, C++, Lisp, Pascal, Python, sed, Unix shell
..... Click the link for more information.
TCL may mean:
..... Click the link for more information.
- Tcl (Tool Command Language), a computer programming language
- Terminal Control Language, used to program VeriFone devices
- Terminal Control Language, a Pick operating system command language
..... Click the link for more information.
compiler is a computer program (or set of programs) that translates text written in a computer language (the source language) into another computer language (the target language).
..... Click the link for more information.
..... Click the link for more information.
A high-level programming language is a programming language that, in comparison to low-level programming languages, may be more abstract, easier to use, or more portable across platforms.
..... Click the link for more information.
..... Click the link for more information.
assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture.
..... Click the link for more information.
..... Click the link for more information.
Machine code or machine language is a system of instructions and data directly executed by a computer's central processing unit. Machine code is the lowest-level of abstraction for representing a computer program.
..... Click the link for more information.
..... Click the link for more information.
In computer science, lex is a program that generates lexical analyzers ("scanners" or "lexers"). Lex is commonly used with the yacc parser generator. Lex, originally written by Eric Schmidt and Mike Lesk, is the standard lexical analyzer generator on many Unix systems, and a tool
..... Click the link for more information.
..... Click the link for more information.
The computer program yacc is a parser generator developed by Stephen C. Johnson at AT&T for the Unix operating system. The name is an acronym for "Yet Another Compiler Compiler.
..... Click the link for more information.
..... Click the link for more information.
In computer science, lexical analysis is the process of converting a sequence of characters into a sequence of tokens. Programs performing lexical analysis are called lexical analyzers or lexers. A lexer consists of a scanner and a tokenizer.
..... Click the link for more information.
..... Click the link for more information.
parsing (more formally syntactic analysis) is the process of analyzing a sequence of tokens to determine its grammatical structure with respect to a given formal grammar. A parser is the component of a compiler that carries out this task.
..... Click the link for more information.
..... Click the link for more information.
In computing, a quine is a program, a form of metaprogram, that produces its complete source code as its only output. For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language.
..... Click the link for more information.
..... Click the link for more information.
Language oriented programming is a style of computer programming, via metaprogramming in which, rather than solving problems in general-purpose programming languages, the programmer creates one or more domain-specific programming languages for the problem first, and solves the
..... Click the link for more information.
..... Click the link for more information.
This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus