我正在编写一个函数try-weak-cues
,用于从大量响应中选择响应。该程序本质上是与用户的对话。
(define try-weak-cues
(lambda (sentence context)
(define helper
(lambda(list-of-pairs)
(define helper2
(lambda(list-of-pairs context)
(cond((null? list-of-pairs)
(cond((null? list-of-pairs) '())
((any-good-fragments?(cue-part(car list-of-pairs))sentence) (helper2(cdr(car list-of-pairs))context))
(else(helper(cdr list-of-pairs)))))))))
(helper *weak-cues*))))
以下是该函数应该从中获取的响应列表:
(define *weak-cues*
'( ( ((who) (whos) (who is))
((first-base)
((thats right) (exactly) (you got it)
(right on) (now youve got it)))
((second-base third-base)
((no whos on first) (whos on first) (first base))) )
( ((what) (whats) (what is))
((first-base third-base)
((hes on second) (i told you whats on second)))
((second-base)
((right) (sure) (you got it right))) )
( ((whats the name))
((first-base third-base)
((no whats the name of the guy on second)
(whats the name of the second baseman)))
((second-base)
((now youre talking) (you got it))))
))
错误:
定义:错误的语法(标识符后面的多个表达式):(定义 helper(lambda(列表对))(定义helper2(lambda)(列表对) context)(cond((null?list-of-pairs)(cond((null?list-of-pairs) (quote()))((任何好片段?(提示部分(汽车列表对)) 句子)(helper2(cdr(car list-of-pairs))context))(else(helper (cdr list-of-pairs)))))))))(帮助弱线索))
答案 0 :(得分:5)
问题在于,当您在lambda
的主体内定义内部过程时,必须在定义后编写表达式,通常调用内部过程。例如,这是错误的:
(define f
(lambda (x)
(define g
(lambda (y)
<body 1>))))
但这是正确的,请注意内部lambda
定义之后是如何有<body 2>
部分:
(define f
(lambda (x)
(define g
(lambda (y)
<body 1>))
<body 2>))
此外,如果您避免使用此样式的过程定义,则代码将更容易调试:
(define f
(lambda (x)
<body>))
它会更短更清晰:
(define (f x)
<body>)
现在,回到你的代码。修复格式并切换到较短的过程定义语法后,您的代码将如下所示:
(define (try-weak-cues sentence context)
(define (helper list-of-pairs)
(define (helper2 list-of-pairs context)
(cond ((null? list-of-pairs)
(cond ((null? list-of-pairs) '())
((any-good-fragments? (cue-part (car list-of-pairs)) sentence)
(helper2 (cdr (car list-of-pairs)) context))
(else (helper (cdr list-of-pairs)))))))
<missing body>)
(helper *weak-cues*))
现在很明显helper
的主体在helper2
的内部定义之后没有写任何内容。可能你打算在那时打电话给helper2
,但是你的代码很容易让人感到困惑,我无法猜测在遗失的身体里写什么,这取决于你。