Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Soundex/Common-Lisp/soundex.lisp
Normal file
22
Task/Soundex/Common-Lisp/soundex.lisp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(defun get-code (c)
|
||||
(case c
|
||||
((#\B #\F #\P #\V) #\1)
|
||||
((#\C #\G #\J #\K
|
||||
#\Q #\S #\X #\Z) #\2)
|
||||
((#\D #\T) #\3)
|
||||
(#\L #\4)
|
||||
((#\M #\N) #\5)
|
||||
(#\R #\6)))
|
||||
|
||||
(defun soundex (s)
|
||||
(if (zerop (length s))
|
||||
""
|
||||
(let* ((l (coerce (string-upcase s) 'list))
|
||||
(o (list (first l))))
|
||||
(loop for c in (rest l)
|
||||
for cg = (get-code c) and
|
||||
for cp = #\Z then cg
|
||||
when (and cg (not (eql cg cp))) do
|
||||
(push cg o)
|
||||
finally
|
||||
(return (subseq (coerce (nreverse `(#\0 #\0 #\0 ,@o)) 'string) 0 4))))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue