Soundex: Difference between revisions

Content deleted Content added
→‎{{header|Common Lisp}}: Graceful behavior on empty string.
Line 212: Line 212:


(defun soundex (s)
(defun soundex (s)
(let* ((l (coerce (string-upcase s) 'list))
(if (zerop (length s))
""
(o (list (first l))))
(loop for c in (rest l)
(let* ((l (coerce (string-upcase s) 'list))
for cg = (get-code c) and
(o (list (first l))))
for cp = #\Z then cg
(loop for c in (rest l)
when (and cg (not (eql cg cp))) do
for cg = (get-code c) and
(push (get-code c) o)
for cp = #\Z then cg
finally
when (and cg (not (eql cg cp))) do
(return (subseq (coerce (nreverse `(#\0 #\0 #\0 #\0 ,@o)) 'string) 0 4)))))
(push (get-code c) o)
finally
(return (subseq (coerce (nreverse `(#\0 #\0 #\0 #\0 ,@o)) 'string) 0 4))))))

</lang>
</lang>