-2
我得到了它的打印子(A 3333)(A 4444),但我不能打印出 sub(A 3333)(A 4444) 附加(R 0)(R 1)不是程序;預期的程序,可以適用於以下參數:#<void>在方案
(define tree '("S" (("-"("A" 3333)("A" 4444))) ("W" (("+" ("R" 0) ("R" 1))))))
(define (OperandNode on)
(display on))
(define (TwoOperandNode x)
(car x)
(if(equal? (car x) "-")
((display "sub")
(OperandNode (cadr x))
(OperandNode (caddr x)))))
(TwoOperandNode (caadr tree))
(define (WhileNode h)
(car h)
(if(equal? (car h) "+")
((display "add")
(WhileNode (cadr h))
(WhileNode (caddr h)))))
(WhileNode (caaadr tree))
括號不用於分組。而且,由於您使用的是Racket,因此讓DrRacket會爲您縮進代碼。 – molbdnilo