0
我試圖修改我在SOF上發現的元音代碼,在下面發表,我試圖把它變成一個單詞列表,以便我可以檢查單詞是否在列表中。不過,我不斷收到錯誤:查找列表中的字符串
;; A list of words
(define words-list (cons #\dog (cons #\pig)
;; split-string : string -> (listof string-pieces)
;; converts a string into a list of string pieces.
(define (split-string a-string)
(string->list a-string))
;; has-word? : string-piece -> boolealn
;; checks whether a string-piece is a vowel
(define (has-word? string-piece words)
(cond ((empty? words) false)
((equal? string-piece (first words)) true)
(else (has-word? string-piece (rest words)))))
;; Test
(check-expect (has-word? #\i word-list) true)
(check-expect (has-word? #\x word-list) false)
;; contains-words-list : (listof string-pieces) -> boolean
;; determines whether any items on a list of string-pieces
;; contains a piece that represents a word, from a list of words.
(define (contains-words-list losp)
(cond ((empty? losp) false)
((false? (has-word? (first losp) words-list))
(contains-words-list (rest losp)))
(else (has-word? (first losp) words-list))))
;; Test
(check-expect (contains-word-list (cons #\h (cons #\i empty))) true)
(check-expect (contains-word-list (cons #\h (cons #\h empty))) false)
;; contains-word? : string -> boolean
;; checks whether a string contains a vowel.
(define (contains-word? a-string)
(contains-word-list (split-string a-string)))
;; Test
(check-expect (contains-word? "pig") true)
我不斷收到類似的錯誤缺點的狗和豬是太大了,它不會產生正確的輸出,任何指導將是巨大的