循环遍历lisp中的字符串,用于alpha字符OR空格

Mit*_*lin 7 lisp string space common-lisp

我正在寻找如何循环LISP中的字符串来检查alpha char或空格.像"咖啡是朋友"这样的句子我想要检查为有效.但是当我这样做时(每个#'alpha-char-p"咖啡都是最好的"')它会在空间上失败,因为空间在技术上不是alpha-char.建议?

谢谢!

Ren*_*nzo 8

只需测试alpha-char 空格:

 (every 
   (lambda (c) (or (alpha-char-p c) (char= c #\Space))) 
   "coffee is best")
Run Code Online (Sandbox Code Playgroud)

every 将第二个参数的每个元素必须返回非nil的函数作为第一个参数.


Rai*_*wig 8

使用LOOP:

CL-USER > (loop for c across "tea is best"
                always (or (alpha-char-p c)
                           (char= c #\space)))
T
Run Code Online (Sandbox Code Playgroud)