スキームで回文リストを検出しようとしています。これが私のコードです:
;- 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))))
入力 '(aba) を試すと、次のエラーが表示されます。
The object (a b a) is not applicable
誰でもこのエラーで私を助けることができますか? ありがとう