summaryrefslogtreecommitdiff
path: root/palindrome/palindrome.scm
blob: 276e62824947f30903e3b50b2ac2f15bc21f9414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(define-module (palindrome))


(define-public (pp str)
  "Pretty-printer wrapper for
palindrome?"
  (format #f "String ~a is ~aa palindrome!\n"
          str
          (if (palindrome? str)
              "" "not ")))

(define-public (palindrome? str)
  "Returns #t if STR is a palindrome, false
otherwise. Ignores casing and non-alphabetic
characters."
  (let ((clean (cleanup str)))
    (equal? clean (string-reverse clean))))

(define (cleanup str)
  (string-downcase (string-filter
                    char-set:letter str)))