syntax | since v0.0-1853 | in clojure | in edn | Edit |
A vector is the most commonly used form for creating literal sequences.
[...]
[1 2 3]
Vectors also serve an important language role to prevent you from interpreting
sequences as function calls. Whether it's for literal data or for binding forms
inside let
and fn
, vectors provide an
important syntax cue not found in other Lisps.
Elements are inserted at the end via conj
, and can be looked up
via index. See PersistentVector
for data structure details.
Vectors are the conventional form for representing binding forms, that is, when local names are created and bound to values. Examples:
[a b]
as function arg bindings in (fn [a b] ...)
[a 1 b 2]
as let bindings in (let [a 1 b 2] ...)
[1 2 3]
;;=> [1 2 3]
(defn- read-vector
[rdr _ opts pending-forms]
(let [[start-line start-column] (starting-line-col-info rdr)
the-vector (read-delimited :vector \] rdr opts pending-forms)
[end-line end-column] (ending-line-col-info rdr)]
(with-meta the-vector
(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})))))
(defn- macros [ch]
(case ch
\" read-string*
\: read-keyword
\; read-comment
\' (wrapping-reader 'quote)
\@ (wrapping-reader 'clojure.core/deref)
\^ read-meta
\` read-syntax-quote ;;(wrapping-reader 'syntax-quote)
\~ read-unquote
\( read-list
\) read-unmatched-delimiter
\[ read-vector
\] read-unmatched-delimiter
\{ read-map
\} read-unmatched-delimiter
\\ read-char*
\% read-arg
\# read-dispatch
nil))