concept body in category clojure

appears as: body, body, bodies, The body, The body, bodies
Clojure: The Essential Reference

This is an excerpt from Manning's book Clojure: The Essential Reference.

  • "body" contains the expressions evaluated when calling the function. It is implicitly wrapped in a do block. It is assumed to be nil when there is no body. An additional "<metamap>" (without caret prefix "^") is allowed before other expressions in the body. When both the argument vector and the body contain "<metamap>", the one in the body takes precedence in case of clashing keys. Note that pre- and post-condition (see below) are allowed only in "<metamap>" after the argument vector.
  • (let [bindings & body])

    let returns the evaluation of the last expression in "body" (if multiple are present) allowing expressions to refer the bound names set by the binding pairs. It returns nil when "body" is empty.

    Get Programming with Clojure

    This is an excerpt from Manning's book Get Programming with Clojure.

  • The body of the function: a succession of Clojure expressions.
  • Figure 13.2  The structure of function definition with a body that is made of two expressions illustrated by an example

    EXTENSION

    The println-and-return function is a nice example for the fact that when a function has side effects, it makes sense to have several expressions inside the body of a function, in opposition to functions with no side effects whose body is usually made of a single expression.

    Clojure in Action, Second Edition

    This is an excerpt from Manning's book Clojure in Action, Second Edition.

    (when test & body)

    This convenient macro is an if (without the alternative clause), along with an implicit do. This allows multiple s-expressions to be passed in as the body. Here’s how it might be used:

    (when (> 5 2)
      (println "five")
      (println "is")
      (println "greater")
      "done")
    
    five
    is
    greater
    ;=> "done"

    Note that there’s no need to wrap the three functions in the body inside a do, because the when macro takes care of this. You’ll find this a common pattern, and it’s a convenience that most macros provide to their callers.

    This replaces the symbol b with the symbol binding, keeping everything else the same. You aren’t interested in the vars being bound, or the body itself, which is why you lump everything into stuff.

    (defmacro in-session [consumer-id & body]
      `(binding [*session* (find-session ~consumer-id)]
         (do ~@body)))