当我在DrRacket中运行它时,我收到错误:“case:错误的语法(在基准序列之后缺少表达式):((else exp))。”
这是代码
(define expand (lambda (exp)
(if (pair? exp)
(case (car exp)
((let) (expand(let-expansion (exp))))
((and) (expand(and-expansion (exp))))
((or) (expand(or-expansion (exp))))
((let*) (expand(let*-expansion (exp))))
((letrec) (expand(letrec-expansion (exp))))
((cond) (expand(cond-expansion (exp))))
((case) (expand(case-expansion (exp))))
((else exp))))
((exp))))
不确定导致错误的原因。我是计划的新手,所以我可能没有正确理解语法。
有人可以向我解释这个功能有什么问题吗?
答案 0 :(得分:1)
看起来像一个括号问题,试试这个:
(define expand
(lambda (exp)
(if (pair? exp)
(case (car exp)
((let) (expand (let-expansion exp)))
((and) (expand (and-expansion exp)))
((or) (expand (or-expansion exp)))
((let*) (expand (let*-expansion exp)))
((letrec) (expand (letrec-expansion exp)))
((cond) (expand (cond-expansion exp)))
((case) (expand (case-expansion exp)))
(else exp))
exp)))