2016-09-25 52 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))