#queue literal

tagged literalsince v0.0-1424Edit

A queue is defined by placing #queue before a vector.

  • #queue [...]

Details:

Queues are the only core collection type that requires a tagged literal to create, while the other collections have built-in delimiters () [] {} #{}.

See PersistentQueue for data structure details.


Examples:

#queue []
;;=> #queue []

#queue [1 2 3]
;;=> #queue [1 2 3]

Some operations:

(def q #queue [1 2 3])
;;=> #queue [1 2 3]

(conj q 4)
;;=> #queue [1 2 3 4]

(pop q)
;;=> #queue [2 3]

(peek q)
;;=> 1

See Also:


Reader code @ clojurescript:src/main/clojure/cljs/tagged_literals.cljc
(defn read-queue
  [form]
  (when-not (vector? form)
    (throw
      #?(:clj  (RuntimeException.
                 "Queue literal expects a vector for its elements.")
         :cljs (js/Error.
                 "Queue literal expects a vector for its elements."))))
  (list 'cljs.core/into 'cljs.core.PersistentQueue.EMPTY form))

Reader table @ clojurescript:src/main/clojure/cljs/tagged_literals.cljc
(def ^:dynamic *cljs-data-readers*
  (merge ;; assumes we can read all data_readers
    #?(:clj *data-readers*)
    {'queue read-queue
     'uuid  read-uuid
     'inst  read-inst
     'js    read-js}))