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.11 add-binding-to-frame! #16

Open
wdanxna opened this issue Jul 3, 2018 · 0 comments
Open

4.11 add-binding-to-frame! #16

wdanxna opened this issue Jul 3, 2018 · 0 comments

Comments

@wdanxna
Copy link

wdanxna commented Jul 3, 2018

您好
练习4.11 的add-binding-to-frame! 我觉得你实现错了
(define (add-binding-to-frame! var val frame) (cons (cons var val) frame))

这里不应该是简单的返回一个新的frame,而是要修改原来的frame

(define (add-binding-to-frame! var val frame)
  (let ((old-car (car frame)))
    (set-car! frame (cons var val))
    (set-cdr! frame (cons old-car (cdr frame)))))

;;test
(let ((frame (make-frame '(a b c) '(1 2 3))))
  (add-binding-to-frame! 'd 4 frame)
  (display frame))
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

1 participant