Lecture overview -- Keyboard shortcut: 'u'  Previous page: An overview of Scheme constructs -- Keyboard shortcut: 'p'  Next page: The  <kbd>eval</kbd>  and  <kbd>apply</kbd>  primitives -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Lecture 6 - Page 21 : 22
Functional Programming in Scheme
Linguistic abstraction
Scheme in Scheme

It is possible to write a relatively full, but brief meta circular Scheme interpreter in Scheme

(define (eval exp env)
  (cond ((self-evaluating? exp) exp)
        ((quoted? exp) (text-of-quotation exp))
        ((variable? exp) (lookup-variable-value exp env))
        ((definition? exp) (eval-definition exp env))
        ((assignment? exp) (eval-assignment exp env))
        ((lambda? exp) (make-procedure exp env))
        ((conditional? exp) (eval-cond (clauses exp) env))
        ((application? exp)  (apply (eval (operator exp) env)
                                          (list-of-values (operands exp) env)))
        (else (error "Unknown expression type -- EVAL" exp))))


(define (apply procedure arguments)
  (cond ((primitive-procedure? procedure
            (apply-primitive-procedure procedure arguments)))
        ((compound-procedure? procedure)
            (eval-sequence (procedure-body procedure)
                                  (extend-environment
                                     (parameters procedure)
                                     arguments
                                     (procedure-environment procedure))))
        (else  (error "Unknown procedure type -- APPLY" procedure))))

The eval and apply functions (procedures) of the Scheme interpreters. The full interpreter needs a lot of relatively small helping functions (procedures) that we do not show here.