Meta-circular evaluator
Encyclopedia
A meta-circular evaluator is a special case of a self-interpreter
Self-interpreter
A self-interpreter, or metainterpreter, is a programming language interpreter written in the language it interprets. An example would be a BASIC interpreter written in BASIC...

 in which the existing facilities of the parent interpreter are directly applied to the source code being interpreted, without any need for additional implementation. Meta-circular evaluation is most common in the context of homoiconic languages.

The idea goes back at least to the definition of Lisp 1.5 (1961) by John McCarthy
John McCarthy (computer scientist)
John McCarthy was an American computer scientist and cognitive scientist. He coined the term "artificial intelligence" , invented the Lisp programming language and was highly influential in the early development of AI.McCarthy also influenced other areas of computing such as time sharing systems...

. He describes the evaluation rules of Lisp as a Lisp program.

A translator or interpreter (evaluator) is just a special kind of program, which can be processed like any other; and can therefore certainly be translated or interpreted by another translator or interpreter.
Meta-circular evaluation is discussed at length in section 4.1, titled The Metacircular Evaluator, of the
MIT
Massachusetts Institute of Technology
The Massachusetts Institute of Technology is a private research university located in Cambridge, Massachusetts. MIT has five schools and one college, containing a total of 32 academic departments, with a strong emphasis on scientific and technological education and research.Founded in 1861 in...

 university textbook Structure and Interpretation of Computer Programs (SICP)
Structure and Interpretation of Computer Programs
Structure and Interpretation of Computer Programs is a textbook published in 1984 about general computer programming concepts from MIT Press written by Massachusetts Institute of Technology professors Harold Abelson and Gerald Jay Sussman, with Julie Sussman...

. The core idea they present is two functions:
  • Eval which takes as arguments an expression and an environment (bindings for variables) and produces either a primitive or a procedure and a list of arguments
  • Apply which takes two arguments, a procedure and a list of arguments to which the procedure should be applied and produces an expression and an environment

The two functions then call each other in circular fashion to fully evaluate a program.

Ramifications

Meta-circular implementations are suited to extending the language they are written in. They are also useful for writing tools that are tightly integrated with the programming language, such as sophisticated debuggers. A language designed with a meta-circular implementation in mind is often more suited for building languages in general, even ones completely different from the host language.

Examples

Many languages have one or more meta-circular implementation.

Languages with a meta-circular implementation designed from the bottom up, in grouped chronological order:
  • Lisp, 1958
    • Scheme, 1975
      • Pico, 1997
      • ActorScript, 2009?
  • Forth, 1968
    • PostScript, 1982
  • Prolog
    Prolog
    Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in terms of...

    , 1972
  • Smalltalk
    Smalltalk
    Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...

    , 1980
  • REBOL
    REBOL
    REBOL is a cross-platform data exchange language and a multi-paradigm dynamic programming language originally designed by Carl Sassenrath for network communications and distributed computing. The language and its official implementation, which is a proprietary freely redistributable software are...

    , 1997
  • Factor
    Factor (programming language)
    Factor is a stack-oriented programming language created by Slava Pestov. Factor is dynamically typed and has automatic memory management, as well as powerful metaprogramming features. The language has a single implementation featuring a self-hosted optimizing compiler and an interactive development...

    , 2003


Languages with a meta-circular implementation via third-parties:
  • Java
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

     via Jikes RVM, Squawk
    Squawk virtual machine
    Squawk is a Java micro edition virtual machine for embedded system and small devices. Most virtual machines for the Java platform are written in low level native languages such as C/C++ and assembler; what makes Squawk different is that Squawk's core is mostly written in Java...

     or Maxine
  • JavaScript
    JavaScript
    JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

     via Narcissus
    Narcissus (JavaScript engine)
    Narcissus is an open source JavaScript engine. It was written by Brendan Eich, who also wrote the first JavaScript engine, SpiderMonkey. Its name is based on the mythical figure of Narcissus, who fell in love with himself...

  • Oz
    Oz (programming language)
    Oz is a multiparadigm programming language, developed in the Programming Systems Lab at Université catholique de Louvain, for programming language education. It has a canonical textbook: Concepts, Techniques, and Models of Computer Programming....

     via Glinda
  • Python
    Python (programming language)
    Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

     via PyPy
    PyPy
    PyPy is a Python interpreter and JIT compiler. PyPy focuses on speed, efficiency and 100% compatibility with the original CPython interpreter.- Details and motivation :...

  • Ruby
    Ruby (programming language)
    Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

     via Rubinius
    Rubinius
    Rubinius is an alternative Ruby programming language implementation created by Evan Phoenix. Based loosely on the Smalltalk-80 Blue Book design, Rubinius seeks to"provide a rich, high-performance environment for running Ruby code."-Goals:...



Languages with a meta-circular implementation via other means:
  • Perl
    Perl
    Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

    via eval

External links

Structure and Interpretation of Computer Programs (SICP), online version of full book, accessed 2009-01-18.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK