Headline

A program that manipulates programs

Illustration

Consider the following simplify for arithmetic expressions, written in Language:Haskell:

-- Simple arithmetic expressions
data Expr = Const Int | Add Expr Expr
  deriving (Eq, Show)

-- Simplification for unit law of addition
simplify :: Expr -> Expr
simplify t@(Const c) = t
simplify (Add (Const 0) x) = simplify x
simplify (Add x (Const 0)) = simplify x
simplify t@(Add x y) = 
   if t==t'
     then t
     else simplify t'
  where
    t' = Add (simplify x) (simplify y)

For instance, the simplifier works as follows:

> simplify (Add (Const 20) (Const 22))
Add (Const 20) (Const 22)
> simplify (Add (Const 0) (Const 42))
Const 42

The simplifier is a metaprogram, as it is a program that manipulates another program. The metalanguage used here is Language:Haskell. The object language used here is Expr, the language of expression.

See the concept of reflection for a more specific form of metaprogramming for further illustrations.


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.