2013-01-18 88 views
1

我有一個assoc命令列表如下:Common Lisp的回報協會

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

我正在尋找一種方式,從密鑰提取值=>值列表,並把它們放在一個新名單如

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

有什麼建議嗎?謝謝你的幫助。

問候

回答

3

這似乎產生你想要的答案,但它似乎並不很漂亮:

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

這幫助。非常感謝你! –

0

塞繆爾·埃德溫·沃德的回答作品,但這裏的另外一個(現在編輯實際做你需要什麼)。所以,你想,爲*experts2*的每一個元素,取其cdr,然後從返回的列表中取值並將它們組合成一個列表:

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

這工作,第一次。我甚至在我回答的路上嘗試過。但是這裏可能有些陰險的事情是它改變了'* expert2 *'。這可能與對「新列表」的請求不一致。這可能是在某些情況下使用的最佳方法,但絕對值得一提的是缺點。 –

+0

啊,當。我忘了'mapcan'是破壞性的。我想到了一種我認爲比你的答案更直接的方式,但不一定更好。 – zck