Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LISP list Clisp函数小于_Lisp - Fatal编程技术网

LISP list Clisp函数小于

LISP list Clisp函数小于,lisp,Lisp,我想写一个包含两个参数的函数 原子x和列表L,并返回列表L中小于x的数字列表 例如: 列表是(2103948)和x是5 输出应为:(2 3 4) 我想我可以使用小于函数 (defun less-than (x y) (or (< x y)) (定义小于(x y) (或(

我想写一个包含两个参数的函数 原子
x
和列表
L
,并返回列表
L
中小于
x
的数字列表

例如:

列表是
(2103948)
x
5

输出应为:
(2 3 4)

我想我可以使用小于函数

(defun less-than (x y)
  (or (< x y))
(定义小于(x y)
(或(

但是它返回的值比列表中的要少:(

过滤列表的代码是什么?你看过
(如果反转pred列表,则删除)
?相关:@reto不必反转,因为你有
如果没有,则删除
@sylvester对,谢谢!@sylvester但是反转谓词很容易:
(如果(补码#'pred)…
)因为
remove if not
适用于一般序列,所以答案也适用于向量。
(小于5#(2103948))
(defun less-than (x L)
  (remove-if-not
   (lambda (e) (< e x))
   L))

(less-than 5 '(2 10 3 9 4 8))
=> (2 3 4)
(defun less-than (x L)
  (remove-if
   (lambda (e) (>= e x))
   L))