cons 目前的行为如下:
(cons '(1 2) '(3))
;=> ((1 2) 3)
我想实现:
(magic-cons '(1 2) '(3))
;=> (1 2 3)
我找不到这方面的资源,但这看起来很简单,我觉得应该有一个内置函数。
或者我只是不知道用什么词来描述这种情况。无论哪种方式,请让我知道。谢谢!
编辑: 请不要用“flatten”回答 :P 即
(flatten (cons '(1 2) '(3)))
最佳答案
你必须使用 concat
:
clojure.core/concat
([] [x] [x y] [x y & zs])
Returns a lazy seq representing the concatenation of the elements in the supplied colls.
示例使用:
user> (concat '(1 2) '(3))
(1 2 3)
关于clojure - 在 Clojure 中,如何 cons 或 conj 集合的元素而不是集合本身?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7652141/