- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想做的事:
(mapcar #'assoc '(a s) '((a . b) (c . d) (s . f)))
让它返回
((A . B) (S . F))
这似乎很合理,考虑到 (assoc 'a '((a . b) (c . d) (s . f)))
返回 (A . B)
和 (assoc 's '((a . b) (c . d) (s . f)))
返回 (S . F)
。但可惜它不起作用:
*** - ASSOC: A is not a list
The following restarts are available:
ABORT :R1 Abort main loop
有什么想法吗?
最佳答案
当与两个列表一起使用时,mapcar
将函数成对地应用到列表(对于三个列表,它应用它们三重等)。所以
(mapcar #'assoc '(a s) '((a . b) (c . d) (s . f)))
与
相同( (assoc 'a (a . b)) (assoc 's (c . d)) )
(当与不同长度的列表一起使用时,mapcar
使用最小列表的大小)。为了得到你想要的,你应该这样做:
(mapcar (lambda (x) (assoc x '((a . b) (c . d) (s . f)))) '(a s))
关于lisp - Mapcar 和 assoc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4840173/
查看Practical Common Lisp ,我们正在寻找一个简单的自动化单元测试框架。我们正在尝试编写一个这样使用的宏: (check (= (+ 1 2) 3) (= (- 1 4) 9))
我是 Lisp 的新手,我遇到了以下问题。 我正在尝试交换多个列表中的数字并生成一个列表列表作为结果,以便每个列表中第一个数字的所有数字都将收集在一个列表中,该列表是第一个元素结果列表;并且每个列表中
我有一个函数,它接受一个列表并替换一些元素。我将它构建为一个闭包,这样自由变量就不能在函数外被修改。 (defun transform (elems) (lexical-let ( (elems
我是 lisp 的新手。我正在编写一个递归函数来删除列表中所有出现的元素。 这是我尝试编写的内容,仅删除列表中出现的原子。 (defun my-remove(x list) (if(null li
我正在尝试创建一个函数,使用 apply 和 mapcar 来计算它。 在使用第一个 mapcar 获取列表中 p-q 的所有差异后,我被卡住了。如何对列表中的所有元素求平方并求和? (defun e
我需要写一个powerset的递归函数,但是我不会用mapcar,loop。 到目前为止,这是我的代码: (defun parts (L) (cond ((null L)'(nil))
例如,我有一个“字符串”列表:("First""second""third.")。 我需要将所有“s”替换为“a”->((“Firat”)...等我发现了一个非常漂亮的函数,叫做 substitute
我想做的事: (mapcar #'assoc '(a s) '((a . b) (c . d) (s . f))) 让它返回 ((A . B) (S . F)) 这似乎很合理,考虑到 (assoc '
我确定这是 lisp 中的一个非常初学者的问题,因为我只是在学习这门语言。 我在 clisp 中有一个名为 count 的函数。它计算给定原子在列表中出现的次数。我想要做的是能够使用不同的参数多次调用
到目前为止,我一直在使用 mapcar 将函数应用于列表的所有元素,例如: (mapcar (lambda (x) (* x x)) '(1 2 3 4 5)) ;; => '(1 4
我想合并两个列表的所有可能组合,为此我使用 mapcar CL-USER> (mapcar #'(lambda (x) (mapcar #'(lambda (y) (list x y)) '(aa b
我的任务是查找给定元素是否包含在列表(非线性列表)中。这是我现在写的,但是这个函数的返回值是一个列表,我真的不明白为什么。 (setq E 4) (defun IsMember (L) (cond
我正在尝试使用宏生成函数: (defmacro make-my-emacs-command-region (cmd name) (list 'defun (intern (format "my-e
(defun describe-paths (location edges) (apply #'append (mapcar #'describe-path (cdr (assoc location
像下面这样使用#x ...获取十六进制值的十进制 > #xB1 177 > #xA5 165 > #xFF 255 假设我们有一个十六进制列表,那么在列表上使用mapcar #x ...的正确语法是什
在 Lisp Koans 中,使用以下形式 here转置矩阵: (defun transpose (L) (apply #'mapcar (cons #'list L))) 当我解析这个函数时,(co
我正在寻找 matlab 中的映射函数。所以这里是我正在考虑的例子: kvec = 0:1:16 kvec = 0 1 2 3 4 5 6 7
我正在寻找 matlab 中的映射函数。所以这里是我正在考虑的例子: kvec = 0:1:16 kvec = 0 1 2 3 4 5 6 7
我正在 Linux 中运行 clisp,并进行书中的练习,ANSI Common Lisp。其中之一说使用 mapcar 创建一个函数,该函数接受一个整数列表并返回一个列表,其中每个元素都是原始元素加
我的代码输出有问题,我想是在我检查列表是否为 null 的条件时。 我试图完成的问题是:编写一个函数 vecmul,它将两个简单的数字列表作为输入。 vecmul 应该按坐标乘以这些列表,就像乘以向量
我是一名优秀的程序员,十分优秀!