0
僅供參考,我正在使用DrRacket
編程Scheme
。計劃 - 預計非空列表
當我運行該程序,我得到了以下錯誤消息:
check-expect encountered the following error instead of the expected value,
(list false true true true).
:: first: expects a non-empty list; given: string?
我不知道是什麼問題,因爲它似乎代碼應該運行正常。
;; Signature: mymap: (x -> y) listofX -> listofY
;; Purpose: Consumes a function from X –> Y, and a list of X; returns a list of Y;
;; by applying the function to each item in the list of X.
(define (mymap g alist)
(cond
[(empty? alist) empty]
[else
(cons (g (first alist))
(mymap (rest alist) g))]
)
)
;; define 2 other functions using mymap and write
;; one check-expect for each of these functions
(check-expect (mymap string? (list 1 "ab" "abc" "")) (list false true true true))
(check-expect (mymap sqr (list 1 0 -3 4 -5)) (list 1 0 9 16 25))
(define (C2F c)
(+ (* 9/5 c) 32))
(define (cf* alist)
(mymap alist C2F))
(check-expect (mymap C2F (list 100 0 -40)) (list 212 32 -40))
預先感謝您!
@ BBladem83:同樣,一旦你意識到真正的問題,回去重讀錯誤消息再次。看看你是否明白錯誤信息是怎麼說的。這將有助於未來,因爲你一定會不時重複這些錯誤。我知道我是。 :P如果您在DrRacket中運行,單擊該錯誤消息應該將光標移至違規行。 – dyoo 2014-12-03 23:43:15