Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; palindrome-test.lisp is a (Common) LISP program by Chris Clarke
- ; version: removes spaces and punctuation from input string (30.07.2018)
- (defun ispalindrome (txt)
- (setq txt1 (string-downcase txt)) ; convert to lower case
- ; punctuation set
- (setq punct '(vector #\SPACE #\COMMA #\. #\! #\- #\: #\; #\" #\' #\( #\) ))
- (loop for ch in punct
- do (setq txt1 (remove ch txt1)) ; remove punctuation characters from txt1
- )
- (return-from ispalindrome (string= txt1 (reverse txt1)))
- )
- (terpri)
- (princ "Enter text: ")
- (setq txt (read-line))
- (terpri)
- (princ #\")
- (princ txt)
- (princ #\")
- (if (ispalindrome txt)
- (princ " is a palindrome.")
- (princ " is not a palindrome!")
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement