0

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))
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Unknown user
  • 44,551
  • 16
  • 38
  • 42
  • 2
    you might find helpful the exercise 4.6 on [SICP, 4.1 The Metacircular Evaluator](http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1) – Nick Dandoulakis Feb 16 '11 at 10:06
  • hey, thanks. are there solutions to those exercises anywhere? – Unknown user Feb 16 '11 at 10:20
  • 2
    check out http://eli.thegreenplace.net/category/programming/lisp/sicp/ – Nick Dandoulakis Feb 16 '11 at 10:30
  • 1
    Per this answer: http://meta.stackexchange.com/questions/10811/how-to-ask-and-answer-homework-questions/10812#10812 please mention that your question pertains to school homework when asking, instead of leaving us to infer that it's a homework question. – Alex Pretzlav Apr 13 '11 at 23:17

1 Answers1

3

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.

Daniil
  • 637
  • 4
  • 12