📜  Clojure-集

📅  最后修改于: 2020-11-05 04:01:22             🧑  作者: Mango


Clojure中是一组唯一值的。借助set命令在Clojure中创建集合。

以下是在Clojure中创建集合的示例。

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

输出

上面的代码产生以下输出。

#{1,2}

以下是Clojure中可用于集合的方法。

Sr.No. Sets & Description
1 sorted-set

Returns a sorted set of elements.

2 get

Returns the element at the index position.

3 contains?

Finds out whether the set contains a certain element or not.

4 conj

Appends an element to the set and returns the new set of elements.

5 disj

Disjoins an element from the set.

6 union

Return a set that is the union of the input sets

7 difference

Return a set that is the first set without elements of the remaining sets.

8 intersection

Return a set that is the intersection of the input sets.

9 subset?

Is set1 a subset of set2?

10 superset?

Is set1 a superset of set2?