Common Lisp将alist的关联返回为新列表

时间:2013-01-18 21:19:11

标签: list lisp common-lisp key-value-store

我有一个关联列表如下:

(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 =>值列表中提取值并将它们放入一个新列表,如

(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))
    ))

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

此致

2 个答案:

答案 0 :(得分:3)

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

(mapcan #'copy-list (mapcar #'cdr *experts2*))

答案 1 :(得分:0)

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

(apply #'append (mapcan #'cdr *experts2*))