ArticleslgStudy

science

Meta-circular evaluator

Meta-circular evaluator is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Meta-circular evaluator rather than just read about it. In short: In computing, a meta-circular evaluator (MCE) or meta-circular interpreter (MCI) is an interpreter which defines each feature of the interpreted language using a similar facility of the interpreter's host language. For example, interpreting a lambda application may be implemented using function application.

Key takeaways

  • Meta-circular evaluator belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Meta-circular evaluator to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Meta-circular evaluator from memory before moving on to harder problems.

Reference excerpt

In computing, a meta-circular evaluator (MCE) or meta-circular interpreter (MCI) is an interpreter which defines each feature of the interpreted language using a similar facility of the interpreter's host language. For example, interpreting a lambda application may be implemented using function application. Meta-circular evaluation is most prominent in the context of Lisp. A self-interpreter is a meta-circular interpreter where the interpreted language is nearly identical to the host language; the two terms are often used synonymously.

History

The dissertation of Corrado Böhm describes the design of a self-hosting compiler. Due to the difficulty of compiling higher-order functions, many languages were instead defined via interpreters, most prominently Lisp. The term itself was coined by John C. Reynolds, and popularized through its use in the book Structure and Interpretation of Computer Programs.

Self-interpreters A self-interpreter is a meta-circular interpreter where the host language is also the language being interpreted. A self-interpreter displays a universal function for the language in question, and can be helpful in learning certain aspects of the language. A self-interpreter will provide a circular, vacuous definition of most language constructs and thus provides little insight into the interpreted language's semantics, for example evaluation strategy. Addressing these issues produces the more general notion of a "definitional interpreter".

From self-interpreter to abstract machine This part is based on Section 3.2.4 of Danvy's thesis. Here is the core of a self-evaluator for the λ calculus. The abstract syntax of the λ calculus is implemented as follows in OCaml, representing variables with their de Bruijn index, i.e., with their lexical offset (starting from 0):

The evaluator uses an environment:

Values (of type value) conflate expressible values (the result of evaluating an expression in an environment) and denotable values (the values denoted by variables in the environment), a terminology that is due to Christopher Strachey. Environments are represented as lists of denotable values. The core evaluator has three clauses:

It maps a variable (represented with a de Bruijn index) into the value in the current environment at this index. It maps a syntactic function into a semantic function. (Applying a semantic function to an argument reduces to evaluating the body of the corresponding syntactic function in its lexical environment, extended with the argument.) It maps a syntactic application into a semantic application. This evaluator is compositional in that each of its recursive calls is made over a proper sub-part of the given term. It is also higher order since the domain of values is a function space. In "Definitional Interpreters", Reynolds answered the question as to whether such a self-interpreter is well defined. He answered in the negative because the evaluation strategy of the defined language (the source language) is determined by the evaluation strategy of the defining language (the meta-language). If the meta-language follows call by value (as OCaml does), the source language follows call by value. If the meta-language follows call by name (as Algol 60 does), the source language follows call by name. And if the meta-language follows call by need (as Haskell does), the source language follows call by need. In "Definitional Interpreters", Reynolds made a self-interpreter well defined by making it independent of the evaluation strategy of its defining language. He fixed the evaluation strategy by transforming the self-interpreter into continuation-passing style, which is evaluation-strategy independent, as later captured in Gordon Plotkin's Independence Theorems. Furthermore, because logical relations had yet to be discovered, Reynolds made the resulting continuation-passing evaluator first order by (1) closure-converting it and (2) defunctionalizing the continuation. He pointed out the "machine-like quality" of the resulting interpreter, which is the origin of the CEK machine since Reynolds's CPS transformation was for call by value. For call by name, these transformations map the self-interpreter to an early instance of the Krivine machine. The SECD machine and many other abstract machines can be inter-derived this way. It is remarkable that the three most famous abstract machines for the λ calculus functionally correspond to the same self-interpreter.

Self-interpretation in total programming languages Total functional programming languages that are strongly normalizing cannot be Turing complete, otherwise one could solve the halting problem by seeing if the program type-checks. That means that there are computable functions that cannot be defined in the total language. In particular it is impossible to define a self-interpreter in a total programming language, for example in any of the typed lambda calculi such as the simply typed lambda calculus, Jean-Yves Girard's System F, or Thierry Coquand's calculus of constructions. Here, by "self-interpreter" we mean a program that takes a source term representation in some plain format (such as a string of characters) and returns a representation of the corresponding normalized term. This impossibility result does not hold for other definitions of "self-interpreter". For example, some authors have referred to functions of type πτ→τ as self-interpreters, where πτ is the type of representations of τ-typed terms. To avoid confusion, we will refer to these functions as self-recognizers. Brown and Palsberg showed that self-recognizers could be defined in several strongly-normalizing languages, including System F and System Fω. This turned out to be possible because the types of encoded terms being reflected in the types of their representations prevents constructing a diagonal argument. In their paper, Brown and Palsberg claim to disprove the "conventional wisdom" that self-interpretation is impossible (and they refer to Wikipedia as an example of the conventional wisdom), but what they actually disprove is the impossibility of self-recognizers, a distinct concept. In their follow-up work, they switch to the more specific "self-recognizer" terminology used here, notably distinguishing these from "self-evaluators", of type πτ→πτ. They also recognize that implementing self-evaluation seems harder than self-recognition, and leave the implementation of the former in a strongly-normalizing language as an open problem.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Meta-circular evaluator

Start with the simplest possible case. Write down what Meta-circular evaluator claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Meta-circular evaluator before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Meta-circular evaluator ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Meta-circular evaluator

In research
Meta-circular evaluator appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Meta-circular evaluator in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Meta-circular evaluator is common in secondary-school and first-year university syllabi. It links to neighbouring topics Programming language implementation, so understanding it makes those chapters shorter.
In everyday life
Look for Meta-circular evaluator outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Meta-circular evaluator” →

How to study Meta-circular evaluator in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Meta-circular evaluator means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Meta-circular evaluator out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Meta-circular evaluator in simple terms?

In computing, a meta-circular evaluator (MCE) or meta-circular interpreter (MCI) is an interpreter which defines each feature of the interpreted language using a similar facility of the interpreter's host language. For example, interpreting a lambda application may be implemented using function app…

Why does Meta-circular evaluator matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Meta-circular evaluator?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Meta-circular evaluator.

Tags

  • Programming language implementation

Keep exploring