The Metacircular Evaluator

              While reading one of the classical texts in the field of   computer science,  
‘Structure and Interpretation of Computer Programs’  (also known as the ‘Wizard’ book), I went through the concept of  ‘Metacircular Evaluator ‘ in the fourth chapter of the book ,where a ‘language interpreter’ for lisp is implemented and language used for
 this purpose is lisp itself.That sounded a bit confusing to me at first ….. but as i went through the structure of the program, it really amazed me as here in program the syntactic simplicity of the language ‘lisp ‘ was exploited to its best. As each and every expression in the language lisp was written as an S-expression (in prefix format, where the operation was written at first in the rest of the list),  the expression recognition was made simpler .   
                            The program in the book is the lisp formulation of environmental model of evaluation. There are two main things done here
  •               A complex procedure is evaluated by splitting it up into simpler subexpression which can be evaluated and the value is applied to the operand subexpression.

  •              2) A compound or user defined procedure is evalauted in a new environment, which can be created by extending the current environment by adding a frame.   
                      The environment here means that the variables are bound to a specific environment which helps to diffrentiate the local variables from global one’s. This is a great way to simulate the evaluation environment where a variable is assigned a value in a specific environment . Here the environment is implemented using  list data structure .

The Core of the Evaluator
                     The two main procedures in the evaluation processs are ‘eval‘ and ‘apply’

  •                ‘eval’  procedure is responsible for  evaluating an expression in it’s environment. This procedure takes the expression and the environment as input parameters. It is this function where the determination of type of expression is done and the corresponding action is invoked.
  •                 ‘apply’ procedure takes the operation and the parameters as the input and it applies the operation to it. This procedure diffrentiates between a primitive procedure to apply the primitives and a compound procedure , the body of whose is evaluated sequentially.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: