Ели*_*кая 3 string common-lisp lowercase
我需要返回True或False
True 如果至少一个小写字符False 没有小写字符我试图用循环和lambda函数做到这一点
(defun check-lower-word (word)
(loop
for ch across word
((lambda (c) (if (lower-case-p c) return T) ch)
)
)
Run Code Online (Sandbox Code Playgroud)
如果从未使用过“如果”,我需要False
有了预定义的功能,您可以使用some(manual):
CL-USER> (some #'lower-case-p "AbC")
T
CL-USER> (some #'lower-case-p "ABC")
NIL
Run Code Online (Sandbox Code Playgroud)
loop语法有一个类似的操作(manual):
CL-USER> (loop for x across "AbC" thereis (lower-case-p x))
T
CL-USER> (loop for x across "ABC" thereis (lower-case-p x))
NIL
Run Code Online (Sandbox Code Playgroud)
最后,请注意,loop总是nil在迭代终止时返回而没有产生结果,因此使用的简洁性loop可能是:
CL-USER> (loop for x across "AbC" if (lower-case-p x) do (return t))
T
CL-USER> (loop for x across "ABC" if (lower-case-p x) do (return t))
NIL
Run Code Online (Sandbox Code Playgroud)