A set holds each value once. contains? tests membership. conj and disj return a new set. clojure.set has the usual set algebra. Printed sets have no stable order, so this program sorts the results it displays.
contains?
conj
disj
clojure.set
(require '[clojure.set :as sets]) (def colors #{:red :green :blue}) (println (contains? colors :green)) (println (count (disj colors :green))) (println (sort (sets/union #{1 2} #{2 3}))) (println (sort (sets/difference #{1 2 3} #{2}))) (println (sort (sets/intersection #{1 2} #{2 3})))
Union, difference, and intersection.
$ glj sets.glj true 2 (1 2 3) (1 3) (2)
Next example: Sequences.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.