#{} set

syntaxsince v0.0-1853 in clojure in ednEdit

An unordered set of values. Values must be unique.

  • #{...}
  • #{1 2 3}

Examples:

#{1 2 3}
;;=> #{1 2 3}

Duplicate values will cause an error:

#{1 1 2 3}
;; Error: Duplicate key: 1

See Also:


Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-set
  [rdr _ opts pending-forms]
  (let [[start-line start-column] (starting-line-col-info rdr)
        ;; subtract 1 from start-column so it includes the # in the leading #{
        start-column (if start-column (int (dec (int start-column))))
        the-set (PersistentHashSet/createWithCheck
          (read-delimited :set \} rdr opts pending-forms))
        [end-line end-column] (ending-line-col-info rdr)]
    (with-meta the-set
      (when start-line
        (merge
         (when-let [file (get-file-name rdr)]
           {:file file})
         {:line start-line
          :column start-column
          :end-line end-line
          :end-column end-column})))))

Reader table @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- dispatch-macros [ch]
  (case ch
    \^ read-meta                ;deprecated
    \' (wrapping-reader 'var)
    \( read-fn
    \= read-eval
    \{ read-set
    \< (throwing-reader "Unreadable form")
    \" read-regex
    \! read-comment
    \_ read-discard
    \? read-cond
    \: read-namespaced-map
    \# read-symbolic-value
    nil))