Lisp 错误语法(标识符后有多个表达式)
我正在编写一个函数,尝试弱提示,从大量响应中选择一个响应。该程序本质上是与用户的对话Lisp 错误语法(标识符后有多个表达式),lisp,scheme,racket,Lisp,Scheme,Racket,我正在编写一个函数,尝试弱提示,从大量响应中选择一个响应。该程序本质上是与用户的对话 (define try-weak-cues (lambda (sentence context) (define helper (lambda(list-of-pairs) (define helper2 (lambda(list-of-pairs context) (cond((nul
(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))))
))
错误:
define:语法错误标识符后面有多个表达式in:define
helper lambda对列表定义helper2 lambda对列表
上下文条件为空?配对列表是否为空?成对列表
引用一些好的片段?球杆零件车对列表
句子帮助器2 cdr车辆对列表上下文帮助器
弱提示对的cdr列表
问题是,当您在lambda主体内定义内部过程时,必须在定义之后编写表达式,通常调用内部过程。例如,这是错误的:
(define f
(lambda (x)
(define g
(lambda (y)
<body 1>))))
此外,如果避免这种类型的过程定义,则代码将更易于调试:
(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*))
现在,回到你的代码。修复格式并切换到较短的过程定义语法后,代码将如下所示:
(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,但您的代码已经够混乱的了,我猜不出在缺少的正文中应该写什么,这取决于您。非常感谢您的帮助@用户2852171不客气!如果我的回答对你有帮助,请点击左边的检查标记来考虑。