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

标签 clojure lisp

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/

相关文章:

clojure - 使用 core.async 等待 n 个 channel

lisp - LISP 如何适应业务挑战的示例

scheme - lisp vs scheme 中的 true 和 false 空值

lisp - 检查lisp中的循环性-通过递归函数相同的变量

clojure - 如何在单独的行clojure中打印列表的每个项目?

clojure - 为 Clojure 项目设置 CLASSPATH

exception-handling - 如何捕获并重新抛出异常

clojure liberator - 从 put 请求返回 json

haskell - 延续传递风格——函数组合

emacs - 无法使用 make-symbol 生成的名称调用宏中定义的函数