Ich versuche, Code aus einem Lehrbuch zu testen "Lehren nichtdeterministischen und Universal-Automaten mit Scheme". Es ist Schema, ich habe DrRacket als R5RS konfiguriert.Scheme R5RS - Undefinierter Bezeichner
Ich kopierte den Teil des Codes definieren, aber es ist immer noch
Bezug auf undefinierte Kennung beschwert: read-only-Band
Hier ist der entsprechende Code.
(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)))))))
Und es ist mit dem Nur-Lese-Band hier:
(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))))
Ich betreibe es mit
(run automaton 'q0 '(($)(a a b $)))
es dem Beispiel des Textbuch. Wird der Definitionscode ignoriert?
Diesen Teil ablassen: procedure meval: erwartet 2 Argumente, gegeben 1. der Komma Teil ist seltsam, aber .. Ich dachte, es war falsch, aber das Lehrbuch Kommentare mit "Beachten Sie das Komma!" – ercliou
Das Komma ("Unquote Operator") sollte mit einem Quasi-Quot-Operator (Backtick) gehen. – erjiang
in r5rs: (Eval 'etwas (Interaktionsumgebung)) wird' etwas mit Top-Level-Umgebung 'bewerten – FooBee