为什么没有这个循环工作为metacircular解释器。我如何在我的交互窗口中运行它?
((while? exp) (eval (while->combination exp) env))
(define (while-condition expr) (cadr expr))
(define (while-body expr) (caddr expr))
(define (while->combination exp)
(sequence->exp
(list (list 'define
(list 'while-iter)
(make-if (while-condition exp)
(sequence->exp (list (while-body exp)
(list 'while-iter)))
'true))
(list 'while-iter))))
答案 0 :(得分:1)
为了回答这个问题,我使用了metacircular评估器described in SICP 4.1.1,因为你的代码缺少一些程序才能运行。
因此,如果你有一个像(while (call-something) (do-something-1) (do-something-2)))
这样的测试表单,你可以将它发送到while->combination
,如下所示:
;; NB: notice I quote the code
(while->combination '(while (call-something)
(do-something-1)
(do-something-2)))
如果您正在使用DrRacket,您只需将其放在定义窗口的末尾,然后点击 Debug> | 并轻松浏览您的代码。
我从运行中获得的输出是:
(begin
(define (while-iter)
(if (call-something)
(begin (do something-1)
(while-iter))
true))
(while-iter))