lisp 中的循环可能有点麻烦,cl-loop
宏大大缓解了这一点。然而,我发现自己反复写一些骇人听闻的东西,比如
(cl-loop for item in some-list
with temp-var do (setf temp-var (some-function-of item))
...)
(cl-loop for item in some-list
for x = (some-function-of item) then (some-function-of item)
...)
是否有一些更优雅的方法可以以相同的方式在每次迭代中计算一些值?请注意,它必须在cl-loop
for 的顶层可见,否则将无法用于执行条件collect
或return
语句。