Advertisement
brilliant_moves

palindrome-test.lisp

Aug 2nd, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.70 KB | None | 0 0
  1. ; palindrome-test.lisp is a (Common) LISP program by Chris Clarke
  2. ; version: removes spaces and punctuation from input string (30.07.2018)
  3.  
  4. (defun ispalindrome (txt)
  5.    (setq txt1 (string-downcase txt)) ; convert to lower case
  6.    ; punctuation set
  7.    (setq punct '(vector #\SPACE #\COMMA #\. #\! #\- #\: #\; #\" #\' #\( #\) ))
  8.    (loop for ch in punct
  9.       do (setq txt1 (remove ch txt1)) ; remove punctuation characters from txt1
  10.    )
  11.    (return-from ispalindrome (string= txt1 (reverse txt1)))
  12. )
  13.  
  14. (terpri)
  15. (princ "Enter text: ")
  16. (setq txt (read-line))
  17. (terpri)
  18. (princ #\")
  19. (princ txt)
  20. (princ #\")
  21. (if (ispalindrome txt)
  22.   (princ " is a palindrome.")
  23.   (princ " is not a palindrome!")
  24. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement