2016-09-25 64 views
1
arrayA = ["arrayA_1", "arrayA_2", "arrayA_3", "arrayA_4", "arrayA_5"] 
arrayB = ["arrayB_1", "arrayB_2", "arrayB_3", "arrayB_4", "arrayB_5"] 
arrayC = ["arrayC_1", "arrayC_2", "arrayC_3", "arrayC_4", "arrayC_5"] 


arrayA.length.times do |x| 
    p list = [ [arrayA[x]] , [arrayB[x]] , [arrayC[x]] ]                               
end 

如何在elisp中複製這個簡單的Ruby代碼塊?elisp數據結構/構建列表的工作流程

+0

也看到了庫[dash.el] (https://github.com/magnars/dash.el)和[seq.el](https://github.com/NicolasPetton/seq.el)來操作列表。 – Ehvince

+0

太棒了!我注意到他們之前,但因爲我不是與elisp的經驗,我的本能是忽略生態系統的噪音,而不是專注於基礎知識。但現在當你提到它們以及其他人時,它們對我來說似乎很受歡迎,也許值得把它放進兔子洞!謝謝:) –

+0

我不會使用dash.el,因爲它有一個奇怪的調用接口。 –

回答

4
ELISP> (cl-mapcar 'concat 
     '("firstA" "secondA" "thirdA") 
     '("firstB" "secondB" "thirdB") 
     '("firstC" "secondC" "thirdC")) 
("firstAfirstBfirstC" "secondAsecondBsecondC" "thirdAthirdBthirdC") 
1

更新 的幫助形式真棒#emacs IRC頻道@ freenode.net(非常感謝wgreenhouse,櫃子,paluche,和其他人)

(setq listA '("firstA" "secondA" "thirdA")) 
(setq listB '("firstB" "secondB" "thirdB")) 
(setq listC '("firstC" "secondC" "thirdC")) 

(setq mylist (cl-loop for a in listA 
         for b in listB 
         for c in listC 
         collect (concat a b c))) 

(print mylist (current-buffer))