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

修复练习3.6的错误 #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions chp3/6.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
练习 3.6
==========

.. warning:: 本解法有错误,正等待修复中,具体请参考: http://sicp.readthedocs.org/en/latest/chp3/6.html#comment-770974238

这题使用了 3.1.1 和 3.1.2 小节的状态、消息传递和随机数等知识:

.. literalinclude:: code/6-rand.scm
Expand Down
3 changes: 2 additions & 1 deletion chp3/code/6-rand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
(let ((state random-init))
(lambda (mode)
(cond ((eq? mode 'generate) ; 产生随机数
(random state))
(begin (set! state (rand-update state))
state))
((eq? mode 'reset) ; 返回一个过程
(lambda (new-value) ; 这个过程将 state 修改为新值 new-value
(set! state new-value)
Expand Down