gpt4 book ai didi

clojure - 在 Clojure 中,如何 cons 或 conj 集合的元素而不是集合本身?

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:40 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com