「前回」の続きです:
;; P04 (*) Find the number of elements of a list.
(define (my-length l)
(letrec ((temp (lambda (count l)
(cond
[(null? l) count]
[else (temp (+ count 1) (cdr l))]))))
(temp l)))
(my-length '(1 2 3 (4 5) 4 5))
;; P05 (*) Reverse a list.
(define (my-reverse l)
(letrec ((temp (lambda (result l)
(cond
[(null? l) result]
[else (temp (cons (car l) result)
(cdr l))]))))
(temp '() l)))
(my-reverse '(1 2 3 4 5))
;; P06 (*) Find out whether a list is a palindrome.
;; A palindrome can be read forward or backward; e.g. (x a m a x).
(define (palindrome? l)
(equal? l
(my-reverse l)))
(palindrome? '(1 2 3 2 1))