Search code examples
clojuremacroslisp

In Clojure, what does `&` mean in function/macro signature?


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?


Solution

  • 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.