Clojure - 按索引合并两个列表

rbb*_*rbb 2 clojure

我如何组合两个列表说'(1 2 3 4)'(:a :b :c :d)得到 (1 :a 2 :b 3 :c 4 :d)

因为我不能这样做,concat因为这会将第二个列表添加到第一个列表的末尾.

我想过做点什么

user=> (def a '(1 2 3 4))

user=> (def b '(:a :b :c :d))

user=> (def x (apply conj (second (split-at 1 a)) (nth b 0) (reverse (first (split-at 1 a)))))
(1 :a 2 3 4)

user=> (def y (apply conj (second (split-at 3 x)) (nth b 1) (reverse (first (split-at 3 x)))))
(1 :a 2 :b 3 4)

user=> (def z (apply conj (second (split-at 5 y)) (nth b 2) (reverse (first (split-at 5 y)))))
(1 :a 2 :b 3 :c 4)

user=> (def q (apply conj (second (split-at 7 z)) (nth b 3) (reverse (first (split-at 7 z)))))
(1 :a 2 :b 3 :c 4 :d)
Run Code Online (Sandbox Code Playgroud)

但我认为还有更好的方法

任何帮助将非常感激

Thu*_*ail 6

用途interleave:

(interleave '(1 2 3 4) '(:a :b :c :d))
=> (1 :a 2 :b 3 :c 4 :d)
Run Code Online (Sandbox Code Playgroud)