2013-10-10 38 views
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)))) 
    )) 

錯誤:

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))

回答

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,但是你的代碼已經足夠讓人困惑了,我猜不出在缺少的內容中寫什麼,這取決於你。

+0

非常感謝您的幫助! – user2852171

+0

@ user2852171不客氣!如果我的回答對你有幫助,請點擊左側的複選標記,考慮[接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) ;) –

相關問題