Lisp 可分性

标签 lisp common-lisp

`(disivible '(1 2 3 4 5 6 7))。这是我到目前为止所做的:

(defun divisible(n)
    (cond ((eq n 0) nill) (eq(rem n 3) 0) t )('else 0)))

但我是 lisp 的新手,我不知道如何让它不显示可被 3 整除的数字,而只是添加数字并显示结果。有人可以帮帮我吗?

最佳答案

(defun divisible (num-list)
  (reduce #'+
          (remove-if-not #'zerop
                         num-list
                         :key (lambda (x)
                                (mod x 3)))))

关于Lisp 可分性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20595135/

相关文章:

lisp - 如何将给定八位位组(字节)的最后 n 位设置为零?

lisp - 尝试返回当前列表中偶数位置的值列表

c - 识别 : eyes open/closed, 嘴巴张开/闭合、头部运动的库

格式化列表 : use arguments that aren't in list

lisp 高效的线性代数库

clojure - 为什么 eval 是邪恶的?

functional-programming - 方案模式检查它是否是一个数字

lisp - 查找出现次数最多的列表并返回以出现次数最多的元素开头的列表

scheme - 有人可以解释 : (+2 (if (>b a) b a))?

lisp - 如何从 plist 中获取属性