簡體   English   中英

Common Lisp將alist的關聯返回為新列表

[英]Common Lisp return associations from alist as new list

我有一個關聯列表如下:

(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列表中提取值並將它們放入一個新的列表中

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

有什么建議么? 謝謝你的幫助。

問候

這似乎產生了你想要的答案,但它看起來不是很漂亮:

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

塞繆爾·埃德溫·沃德的答案有效,但這是另一個(現在編輯實際上做你需要的)。 因此,對於*experts2*每個元素,您希望獲取其cdr ,然后從返回的列表中獲取值並將它們組合成一個列表:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM