Palindrome detection: Difference between revisions

added Emacs Lisp code that works with inexact palindromes
(added Emacs Lisp code that works with inexact palindromes)
Line 2,018:
<syntaxhighlight lang="lisp">(defun palindrome (s)
(string= s (reverse s)))</syntaxhighlight>
 
The version below will work correctly with inexact palindromes, as defined in this exercise:
 
<pre>
(defun test-if-palindrome (text)
(setq text (replace-regexp-in-string "[[:space:][:punct:]]" "" text)) ; remove spaces and punctuation, by replacing them with nothing
(string-equal-ignore-case text (reverse text))) ; ignore case when looking at reversed text
</pre>
{{out}}
 
<pre>
(test-if-palindrome "A man, a plan, a canal, Panama")
t
</pre>
 
=={{header|Erlang}}==
31

edits