首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Common Lisp将list中的关联作为新列表返回

Common Lisp将list中的关联作为新列表返回
EN

Stack Overflow用户
提问于 2013-01-19 05:19:11
回答 2查看 129关注 0票数 1

我有一个如下的assoc列表:

代码语言:javascript
复制
(defparameter *experts2*
  `(
    ;; direction
    (:direction . ( (nn-direction-expert (process-signal) :number-of-neighbors 10)
                    (fn-direction-expert (process-signal) :number-of-neighbors 10) ))



    ;; evaluation
    (:evaluation . ( 

                    ;(avoid-line-crossing-evaluation-expert (process-signal))
                    (nn-single-evaluation-expert (candidate-point))
                    (fn-single-evaluation-expert (candidate-point))
                    ;(nn-all-evaluation-expert (ranking))
                    ))

    ;; coordination
    (:coordination . (
                      ;(ranking-process (candidate-point))
                      (action-process (candidate-point ranking))))))

我正在寻找一种方法,从key=>value列表中提取值并将它们放入一个新的列表中,如下所示

代码语言:javascript
复制
(defparameter *experts*
  `(
    ;; direction
    (nn-direction-expert (process-signal) :number-of-neighbors 10)
    (fn-direction-expert (process-signal) :number-of-neighbors 10)

    ;eher als evaluationsexperte
    ;(avoid-line-crossing-evaluation-expert (process-signal) )

    ;; evaluation
    (nn-single-evaluation-expert (candidate-point))
    (fn-single-evaluation-expert (candidate-point))
    ;(nn-all-evaluation-expert (ranking))

    ;; coordination
    ;(ranking-process (candidate-point))
    (action-process (candidate-point ranking))
    ))

有什么建议吗?谢谢你的帮助。

问候

EN

回答 2

Stack Overflow用户

发布于 2013-01-19 05:55:06

这似乎产生了你想要的答案,但它看起来并不是很漂亮:

代码语言:javascript
复制
(mapcan #'copy-list (mapcar #'cdr *experts2*))
票数 3
EN

Stack Overflow用户

发布于 2013-01-19 13:42:47

塞缪尔·埃德温·沃德的答案是有效的,但这里有另一个答案(现在进行编辑,以实际执行您需要的操作)。因此,对于*experts2*的每个元素,您需要获取其cdr,然后从返回的列表中获取值,并将它们组合到一个列表中:

代码语言:javascript
复制
(apply #'append (mapcan #'cdr *experts2*))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14407812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档