(define applicative-eval (lambda (exp) (cond ((atomic? exp) (eval-atomic exp)) ((special-form? exp)...

of 23 /23
(define applicative-eval (lambda (exp) (cond ((atomic? exp) (eval-atomic exp)) ((special-form? exp) (eval-special-form exp)) ((list-form? exp) (eval-list exp)) ((value? exp) exp) ((application? exp) (let ((renamed-exp (rename exp))) ; <- arguments are renamed (apply-procedure ; <- last, the operator is applied (applicative-eval (operator renamed-exp)) ; <- first, the operator is evaluated (list-of-values (operands renamed-exp))))) ; <- then, the arguments are evaluated (else (error "Unknown expression type -- APPLICATIVE-EVAL" exp))))) applicative-eval (substitution-core.scm) 1
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    240
  • download

    4

Embed Size (px)

Transcript of (define applicative-eval (lambda (exp) (cond ((atomic? exp) (eval-atomic exp)) ((special-form? exp)...

  • Slide 1
  • (define applicative-eval (lambda (exp) (cond ((atomic? exp) (eval-atomic exp)) ((special-form? exp) (eval-special-form exp)) ((list-form? exp) (eval-list exp)) ((value? exp) exp) ((application? exp) (let ((renamed-exp (rename exp))) ;
  • Some examples > (applicative-eval 4) ((atomic? exp) (eval-atomic exp)) > (applicative-eval '(list 1 2)) ((atomic? exp) (eval-atomic exp)) ((special-form? exp) (eval-special-form exp)) ((list-form? exp) (eval-list exp)) ((atomic? exp) (eval-atomic exp)) (define list-form? (lambda (exp) (or (tagged-list? exp cons) (tagged-list? exp list) (tagged-list? exp append)))) (define eval-list (lambda (lst) (make-list (apply-primitive-procedure (applicative-eval (operator lst)) (list-of-values (operands lst))))) (define list-form? (lambda (exp) (or (tagged-list? exp cons) (tagged-list? exp list) (tagged-list? exp append)))) (define eval-list (lambda (lst) (make-list (apply-primitive-procedure (applicative-eval (operator lst)) (list-of-values (operands lst))))) (define eval-atomic (lambda (exp) (if (not (variable? exp)) exp (look-up-variable-value exp)) (define eval-atomic (lambda (exp) (if (not (variable? exp)) exp (look-up-variable-value exp)) ASP.scm: Substitution-core.scm: 2
  • Slide 3
  • > (applicative-eval '(lambda (x y) (+ x y 10))); ((atomic? exp) (eval-atomic exp)) ((special-form? exp) (eval-special-form exp)) (define eval-lambda (lambda (exp) (make-procedure (lambda-parameters exp) (lambda-body exp)))) (define eval-lambda (lambda (exp) (make-procedure (lambda-parameters exp) (lambda-body exp)))) (define lambda? (lambda (exp) (tagged-list? exp 'lambda) )) (define lambda? (lambda (exp) (tagged-list? exp 'lambda) )) Substitution-core.scm: (define eval-special-form (lambda (exp) (cond ((quoted? exp) (make-symbol exp)) ((lambda? exp) (eval-lambda exp)) (define eval-special-form (lambda (exp) (cond ((quoted? exp) (make-symbol exp)) ((lambda? exp) (eval-lambda exp)) (define special-form? (lambda (exp) (or (quoted? exp) (lambda? exp) (definition? exp) (if? exp) (begin? exp)))) (define special-form? (lambda (exp) (or (quoted? exp) (lambda? exp) (definition? exp) (if? exp) (begin? exp)))) ASP.scm: Substitution-core.scm: 3
  • Slide 4
  • ((application? exp) (let ((renamed-exp (rename exp)));