Clojure - conj函式



將元素新增到集合中並返回新的元素集合。

語法

以下是語法。

(conj setofelements x)

引數 − ‘setofelements’ 是元素集合。 ‘x’ 是需要新增到元素集合中的元素。

返回值 − 返回包含已新增元素的新集合。

示例

以下是 Clojure 中 conj 的示例。

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (println (conj (set '(3 2 1)) 5)))
(example)

輸出

以上程式碼產生以下輸出。

#{1 3 2 5}
clojure_sets.htm
廣告