() list

syntaxsince v0.0-1853 in clojure in ednEdit

A list is interpreted as a call when evaluated.

  • (...)
  • (foo 1 2 3) - call foo with arguments 1, 2, 3

Details:

In most languages, the parenthesis is on the right side of a function when calling:

// (not ClojureScript)
f(a, b)

In ClojureScript, the parenthesis simply starts on the left side:

;; ClojureScript (comma is optional)
(f a, b)

Thus, when (f a b) is evaluated, it calls f with two arguments a and b.

If f is a function, its arguments a and b will be evaluated before the function receives them.

If f is a special form or macro, it will receive its arguments a and b unevaluated, where they may be evaluated internally.

(See List for data structure details.)


Examples:

The following is a list that is evaluated to create var a:

(def a 1)

An empty list is unevaluated and left as an empty list:

()
;;=> ()

To signify an unevaluated list, precede it with a quote:

'(1 2 3)
;;=> (1 2 3)

See Also:


Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-list
  [rdr _ opts pending-forms]
  (let [[start-line start-column] (starting-line-col-info rdr)
        the-list (read-delimited :list \) rdr opts pending-forms)
        [end-line end-column] (ending-line-col-info rdr)]
    (with-meta (if (empty? the-list)
                 '()
                 (clojure.lang.PersistentList/create the-list))
      (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- 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))