The metacircular evaluator

2.2k views Asked by At

I have to write scheme with scheme.. quiet funny, but that's the situation. Any way, Here's an example for trying to write "lambda" expression with all the proucedors that I may use,and I need help in writing "Let" expression also. how can I translate the "Let" expression into lambda using similar way? Thanks.

    (define (lambda? exp) (tag-check exp 'lambda))
 
(define (eval exp env)
  (cond  ((number? exp)       exp)
         ((symbol? exp)      (lookup exp env))
         ((define? exp)      (eval-define exp env))  
         ((if? exp)          (eval-if exp env))
         ((lambda? exp)      (eval-lambda exp env))
         ((application? exp) (apply (eval (car exp) env)
                                 (map (lambda (e) (eval e env))
                                         (cdr exp))))
         (else (error "unknown expression " exp))))
 
(define (eval-lambda exp env) 
      (make-procedure (lambda-parameters exp)
                         (lambda-body exp)
                         env))

(define (lambda-parameters exp) (cadr exp))
(define (lambda-body exp) (cddr exp))

(define (make-procedure parameters body env)
  (list 'procedure parameters body env))
1

There are 1 answers

0
Daniil On

You just need to write a program which would transform.

(let ((e1 v1) (e2 v2) ...) body..) => ((lambda (e1 e2 ...) body..) v1 v2 ...)

And check out SICP chapter 4.