Skip to content

4.9 #11

@FengLi666

Description

@FengLi666

while 的实现你没有写完,一次就停了:

(define (expand-predicate predicate i body)
  (if (predicate i)
    (cons 'begin body)))

(define (while->combination exp)
  (expand-predicate
    (while-predicate exp)
    (while-variable exp)
    (while-body exp)))

此外,for的实现我有疑问:

(define (expand-range start end proc)
  (cond
    ((< start end)
      (proc start)
      (expand-range (+ start 1) end proc))))

在这里面 (proc start)的求值需要环境吧?
是否需要写成这样?

(define (expand-range start end proc env)
  (cond
    ((< start end)
      (eval (lambda () (proc start)) env)
      (expand-range (+ start 1) end proc env)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions