问题描述
该程序使用Scheme条件并重新启动以循环执行程序10次,并返回程序成功的次数。
这里程序每次 n 是 3 的倍数时都会抛出一个错误。
出于某种原因,第一个错误 (n=3) 被捕获,但循环无法在 n=4 时恢复:
(define (handle! thunk)
(bind-condition-handler
'() (lambda (condition)
(display "resuming...")
(invoke-restart (find-restart 'next)))
thunk))
(let loop((n 1) (count 0))
(display n)(display #\,)
(if (> n 10) count
(handle!
(call/cc
(lambda (cc)
(with-restart
'next "restart here"
(lambda ()
(cc (loop (1+ n) count)))
#f
(lambda ()
(if (= 0 (modulo n 3))
(error n "is multiple of 3!")
(loop (1+ n) (1+ count))))))))))
我未能找到条件示例,并在 the MIT Scheme Reference 之外重新启动。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)