0
我試圖測試一些代碼從教科書「教非確定性和通用自動機使用計劃」。這是Scheme,我將DrRacket配置爲R5RS。計劃R5RS - 未定義的標識符
我複製了定義代碼的一部分,但它仍然抱怨
參考未定義的標識符:只讀磁帶
下面是相關的代碼。
(define tape
(lambda()
(let((blank '$))
(let ((left-part(list blank))
(right-part(list blank)))
(lambda message
(case(car message)
((init!)
(set! left-part(reverse(caadr message)))
(set! right-part(cadadr message)))
((write!)
(if(equal? right-part(list blank))
(set! right-part (cons(cadr message) right-part))
(set! right-part (cons(cadr message)(cdr right-part)))))
((left!)
(set! right-part (cons (car left-part) right-part))
(if(not(equal? left-part (list blank)))
(set! left-part(cdr left-part))))
((right!)
(set! left-part (cons (car right-part) left-part))
(if (not (equal? right-part (list blank)))
(set! right-part (cdr right-part))))
((show)
(list (reverse left-part) right-part))
((read)
(car right-part))
(else (error 'rape "Message ~a cannot be evaluated" (car message)))))))))
(define read-only-tape
(lambda()
(let ((tape-obj (tape)))
(lambda message
(case(car message)
((reconfig!)(tape-obj 'right))
((left! right! write!)
(error 'message "~a is prohibited for read-only-tapes" (car message)))
(else(apply tape-obj message)))))))
而且它在這裏使用只讀磁帶:
(define automaton
(lambda(start)
(eval
'(letrec
((q0(lambda(tape)
(printf "~a~n~a~n" (contents tape) 'q0)
(case (at tape)
((a)(reconfig! tape)(q2 tape))
((b)(reconfig! tape)(q1 tape))
(else #f))))
(q1(lambda(tape)
(printf "~a~n~a~n" (contents tape) 'q1)
(case (at tape)
((a)(reconfig! tape)(q5 tape))
((b)(reconfig! tape)(q5 tape))
(($) #t)
(else #f))))
(q2(lambda(tape)
(printf "~a~n~a~n" (contents tape) 'q2)
(case (at tape)
((a)(reconfig! tape)(q3 tape))
((b)(reconfig! tape)(q6 tape))
(else #f))))
(q3(lambda(tape)
(printf "~a~n~a~n" (contents tape) 'q3)
(case (at tape)
((a)(reconfig! tape)(q3 tape))
((b)(reconfig! tape)(q4 tape))
(else #f))))
(q4(lambda(tape)
(printf "~a~n~a~n" (contents tape) 'q4)
(case (at tape)
((a)(reconfig! tape)(q5 tape))
((b)(reconfig! tape)(q5 tape))
(($) #t)
(else #f))))
(q5(lambda(tape)
(printf "~a~n~a~n" (contents tape) 'q5)
(case (at tape)
((a)(reconfig! tape)(q5 tape))
((b)(reconfig! tape)(q5 tape))
(else #f))))
(q6(lambda(tape)
(printf "~a~n~a~n" (contents tape) 'q6)
(case (at tape)
((a)(reconfig! tape)(q5 tape))
((b)(reconfig! tape)(q6 tape))
(($) #t)
(else #f)))))
(let((t (read-only-tape)))
(lambda(input)
(init! t input)
(eval (list ,start t)
(null-environment 5)))))
(null-environment 5))))
我
(run automaton 'q0 '(($)(a a b $)))
它的教科書的例子運行它。 它忽略了定義代碼嗎?
將此部分關閉:procedure meval:期望2個參數,給出1. 逗號部分雖然很奇怪..但我認爲這是錯誤的,但教科書用「注意逗號! – ercliou 2012-03-31 20:31:40
逗號(「非引號運算符」)應該與quasiquote(反引號)運算符一起使用。 r5rs中的 – erjiang 2012-03-31 23:02:32
:(eval'something(interaction-environment))將評估'具有頂級環境的東西 – FooBee 2012-04-01 03:45:36