Bodies

The body of a lambda, let, let*, let-values, let*-values, letrec, or letrec* expression, or that of a definition with a body consists of zero or more definitions or expressions followed by a final expression. (Standard Scheme requires that all definitions precede all expressions.)

body ::= statement ... expression
statement ::= definition | expression

Each identifier defined by a definition is local to the body. That is, the identifier is bound, and the region of the binding is the entire body. Example:

(let ((x 5))
  (define foo (lambda (y) (bar x y)))
  (define bar (lambda (a b) (+ (* a b) a)))
  (foo (+ x 3)))
⇒ 45

When begin, let-syntax, or letrec-syntax forms occur in a body prior to the first expression, they are spliced into the body. Some or all of the body, including portions wrapped in begin, let-syntax, or letrec-syntax forms, may be specified by a macro use.

An expanded body containing variable definitions can be converted into an equivalent letrec* expression. (If there is a definition following expressions you may need to convert the expressions to dummy definitions.) For example, the let expression in the above example is equivalent to

(let ((x 5))
  (letrec* ((foo (lambda (y) (bar x y)))
            (bar (lambda (a b) (+ (* a b) a))))
    (foo (+ x 3))))