summaryrefslogtreecommitdiff
path: root/palindrome/palindrome.scm
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2024-05-18 19:12:47 -0600
committerbd <bdunahu@operationnull.com>2024-05-18 19:12:47 -0600
commitf6d333ef67fa2c9c199d4c401322fc31d90867da (patch)
treea97b33ec3f7bbac6b5174cbb30cf8f93ad19c885 /palindrome/palindrome.scm
parent05a303de6c8cf8e8acb00b2107f7a66c363140b3 (diff)
Adapt palindrome into a ttd approach
Diffstat (limited to 'palindrome/palindrome.scm')
-rwxr-xr-xpalindrome/palindrome.scm21
1 files changed, 21 insertions, 0 deletions
diff --git a/palindrome/palindrome.scm b/palindrome/palindrome.scm
new file mode 100755
index 0000000..276e628
--- /dev/null
+++ b/palindrome/palindrome.scm
@@ -0,0 +1,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)))