我正試圖檢測方案中的迴文列表。這裏是我的代碼:我的代碼在確定方案中的迴文時出了什麼問題?
;- Input : Takes only one parameter named inSeq
;- Output : It returns the reverse of inSeq if inSeq is a sequence.
; Otherwise it produces an error.
;- Examples :
; (reverse-sequence '(a b c)) --> evaluates to (c b a)
; (reverse-sequence '()) -------> evaluates to()
(define reverse-sequence
(lambda (inSeq)
(if (sequence? inSeq)
(if (null? inSeq)
inSeq
(append (reverse-sequence (cdr inSeq))
(list (car inSeq)))))))
;- Input : Takes only one parameter named inSeq
;- Output : It returns true if inSeq is a sequence and it is a palindrome.
; It returns false if inSeq is a sequence but not a plaindrome.
; Otherwise it gives an error.
;- Examples :
; (palindrome? '(a b a)) --> evaluates to true
; (palindrome? '()) -------> evaluates to true
; (palindrome? '(a 1 a)) --> produces an error
(define palindrome
(lambda (inSeq)
(if (sequence? inSeq)
(if (equal? reverse-sequence(inSeq) inSeq)
#t
#f))))
當我嘗試輸入「(A B A)我得到以下錯誤:
The object (a b a) is not applicable
誰能幫我這個錯誤?由於
謝謝你,那工作 – yrazlik 2013-04-30 19:25:10