ruandao / blog

0 stars 0 forks source link

[16.1.2] [sicp 4.1] #136

Closed ruandao closed 8 years ago

ruandao commented 8 years ago
(define (list-of-values exps env)
  (if (no-operands? exps)
      '()
      (cons (eval (first-operand exps) env)
        (list-of-values (rest-operands exps) env))))

(define (list-of-values-rl exps env)
  (define (rl left-exp vals env)
    (cons (eval left-exp env)
      vals))
  (if (no-operands? exps)
      '()
      (rl (first-operand exps)
      (list-of-values-lr (rest-operands exps) env)
      env)))

(define (list-of-values-lr exps env)
  (define (lr left-val right-exps env)
    (cons left-val
      (list-of-values-lr right-exps env)))
  (if (no-operands? exps)
      '()
      (lr (eval (first-operand exps) env)
      (rest-operands exps)
      env)))
ruandao commented 8 years ago
Exercise 4.1.  Notice that we cannot tell whether the metacircular evaluator 
evaluates operands from left to right or from right to left. Its evaluation order
 is inherited from the underlying Lisp: If the arguments to cons in list-of-values 
are evaluated from left to right, then list-of-values will evaluate operands from 
left to right; and if the arguments to cons are evaluated from right to left, 
then list-of-values will evaluate operands from right to left.

Write a version of list-of-values that evaluates operands from left to right 
regardless of the order of evaluation in the underlying Lisp. 
Also write a version of list-of-values that evaluates operands from right 
to left.
ruandao commented 8 years ago

观察了下 这个需要有辅助函数 然后 方法是, 先求值的, 需要先求值再传入辅助函数 后求值的,则需要在辅助函数里面求值