简体   繁体   中英

elisp data structures/workflow for constructing a list

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

How to replicate this simple Ruby codeblock in elisp?

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

Update With help form the awesome #emacs irc channel @freenode.net (Many thanks to wgreenhouse, forcer, paluche, and others)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM