gpt4 book ai didi

lisp - 语法错误(标识符后有多个表达式)

转载 作者:太空宇宙 更新时间:2023-11-03 18:56:21 26 4
gpt4 key购买 nike

我正在编写一个函数 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))))
))

错误:

define: bad syntax (multiple expressions after identifier) in: (define helper (lambda (list-of-pairs) (define helper2 (lambda (list-of-pairs context) (cond ((null? list-of-pairs) (cond ((null? list-of-pairs) (quote ())) ((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))

最佳答案

问题在于,当您在 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在这一点上,但你的代码已经够困惑了,我猜不出在丢失的 body 中写什么,这取决于你。

关于lisp - 语法错误(标识符后有多个表达式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19303099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com