【发布时间】:2013-04-02 13:16:56
【问题描述】:
我必须编写一个程序,将字符串的元音、辅音和其他符号分别更改为 C、V 0。我已经这样做了,但我想知道是否有更有效和更优雅的方法来做到这一点。不胜感激。
(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)))
另外,我想把它变成一个字符串,我该怎么做呢?我应该定义一个函数来遍历列表并使其成为字符串还是更简单的方法?
【问题讨论】:
-
这个问题最好在codereview.stackexchange.com问
-
改用“地图”。如果您的代码格式和缩进按照典型的约定会有所帮助。
-
我不知道怎么用
MAP,你能帮帮我吗? -
请花几分钟时间到learn how to format Lisp code。
标签: string lisp common-lisp