我必须编写一个程序,将字符串的元音,辅音和其他符号分别转换为C,V和0.我已经完成了这项工作,但我想知道是否有更高效和更优雅的方法来执行此操作。将不胜感激输入。LISP - 修改字符串
(defun string-to-list (string)
(loop for char across string collect char))
(defun is-vowel (char) (find char "aeiou" :test #'char-equal))
(defun is-consonant (char) (find char "bcdfghjklmnpqrstvwxyz" :test #'char-equal))
(defun letter-type (char)
(if (is-vowel char) "V"
(if (is-consonant char) "C"
"0")))
(defun analyze-word (word-string)
(loop for char across word-string collect (letter-type char)))
此外,我想使它成为一个字符串,我怎么能做到这一点?我应该定义一个函数来遍历列表并将其设置为一个字符串,还是更简单的方法?
这个问题应该得到更好的http://codereview.stackexchange.com/问 – akluth
使用“地图”来代替。如果你的格式和按照典型惯例缩进你的代码,这将会有所帮助。 –
我不知道如何使用'MAP',你能帮我吗? –