2016-01-28 42 views
0

例子:如何使兩個列表alist?

(setq foo '("f" "o" "o")) 
(setq bar '("b" "a" "r")) 

(setq foobar `(,foo . ,(list bar))) 
;; Give me a normal list (("f" "o" "o") ("b" "a" "r")) which is not what I want. 

我想(("f" "o" "o") . ("b" "a" "r"))。怎麼樣?

回答

2

使用cons得到一個點對:

(setq foo '("f" "o" "o")) 
(setq bar '("b" "a" "r")) 

(cons foo (list bar)) 
-> (("f" "o" "o") ("b" "a" "r")) 
0

另外,

(setq foobar `(,foo ,bar)) 
(memq foo foobar) 
-> (("f" "o" "o") ("b" "a" "r"))