--- title: 'Lispの問題 from L-99: Ninety-Nine Lisp Problems' author: kazu634 date: 2010-09-03 url: /2010/09/03/_1561/ wordtwit_post_info: - 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:5335;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}' categories: - gauche - Lisp ---
「前回」の続きです:
;; 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))