Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.9 #11

Open
FengLi666 opened this issue Oct 23, 2016 · 1 comment
Open

4.9 #11

FengLi666 opened this issue Oct 23, 2016 · 1 comment

Comments

@FengLi666
Copy link

FengLi666 commented Oct 23, 2016

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)))
@jiacai2050
Copy link
Owner

jiacai2050 commented Oct 23, 2016

看了下我的代码,这道题中的whilefor实现方式确实都错了, 正确的方法应该是构造一个lambda,然后调用这个lambda来实现迭代。

其次,你提到的的(proc start)求值需要环境,我觉得是不需要的,因为procstart在传递给expand-range的时候已经求好值了,这里直接用就好了。

等几天抽空,我把这个题重新做一遍,谢谢指出错误。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants