Clojure - 向量 conj 函式



將元素新增到向量末尾並返回新的向量。

語法

以下是語法。

(conj vec x)

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

返回值 − 返回包含已新增元素的新向量。

示例

以下是在 Clojure 中使用 conj 的示例。

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

輸出

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

[3 2 1 5]
clojure_vectors.htm
廣告