I saw the usage of &
in Clojure function signature like this (http://clojure.github.io/core.async/#clojure.core.async/thread):
(thread & body)
And this:
(doseq seq-exprs & body)
Does that means the function/macro can accept a list as variable? I also find *
is often used to mean multiple parameters can be accepted, like this:
(do exprs*)
Does anyone have ideas about the difference between &
and *
in function/macro signature? Is there any documentation to explain this syntax?
In Common Lisp, a "symbol" is a location in memory, a place where data can be stored. The "value" of a symbol is the data stored at that location in memory. In Clojure, a "symbol" is just a name. It has no value.
#: and #:: - Namespace Map Syntax Namespace map syntax was added in Clojure 1.9 and is used to specify a default namespace context when keys or symbols in a map where they share a common namespace.
#_ is the comment reader macro that instructs the Clojure reader to completely ignore the next form, as if it had never been written. No value is returned, so this comment is safe to use within an expression.
In clojure binding forms (let
, fn
, loop
, and their progeny), you can bind the rest of a binding vector to a sequence with a trailing &
. For instance,
(let [[a b & xs] (range 5)] xs) ;(2 3 4)
Uses of *
and other uses of &
are conventions for documenting the structure of argument lists.
It means that there can be multiple parameters after the ampersand, and they will be seen as a seq by the function. Example:
(defn g [a & b]
(println a b))
Then if you call:
(g 1 2 3 4)
it will print out 1 (2 3 4)
(a is 1, b is a sequence containing 2, 3 and 4).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With