0

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

错误:

定义:语法错误(标识符后有多个表达式)在:(定义助手(lambda(列表对))(定义助手2(lambda(列表对上下文)(cond((null?列表对)) cond ((null?list-of-pairs) (quote ())) ((any-good-fragments? (cue-part (car list-of-pairs)) 句子) (helper2 (cdr (car list-of- pair)) context)) (else (helper (cdr list-of-pairs)))))))))) (helper weak-cues ))

4

1 回答 1

8

问题是,当您在 a 的主体内定义内部过程时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在那个时候调用,但是您的代码已经足够令人困惑,我无法猜测在缺少的正文中要写什么,这取决于您。

于 2013-10-10T18:45:44.033 回答