8.4 Definitions
[66] definition = variable-definition | procedure-definition
Definitions may take two possible forms.
[67] variable-definition = (define variable expression)
This syntax is primitive.
[68] procedure-definition = (define (variable formal-argument-list) body)
This form is equivalent to
(define variable
  (lambda (
variable formal-argument-listbody)).
A definition that does not occur within an expression is known as a top-level definition.
A top-level definition
(define variable expression)
evaluates expression in the top-level environment and binds variable to the result in the top-level environment.
(define add3
  (lambda (x) (+ x 3)))
(add3 3)                              6
(define first car)
(first '(1 2))                        1
A single variable shall not be defined by more than one top-level definition in any process specification part.  A top-level definition of a variable in a process specification part is ignored if that variable has been defined at the top level in a previous process specification part.  See section 7.1, DSSSL Document Architecture.
The expression in a top-level definition shall not be evaluated until all top-level variables that would be referenced by evaluating the expression have been defined.


This constraint does not prevent the definition of mutually recursive procedures, because evaluating a lambda expression does not reference variables that occur free within it.
It shall be an error if it is impossible to evaluate all the expressions occurring in top-level definitions in such a way that this constraint is not violated.
The built-in definition of a variable may be replaced by a top-level definition.  The replacement definition shall be used for all references to that variable, even those that occur in process specification parts preceding the part that contains the first top-level definition.


This rule is not easy to implement, but it allows built-in procedures to be added in future versions of this International Standard without changing the meaning of any conforming DSSSL specifications.
[69] body = definition* expression
Definitions may also occur at the beginning of a body. These are known as internal definitions. The variable defined by an internal definition is local to the body. The region of the binding is the entire body.  For example,
(let ((x 5))
  (define foo (lambda (y) (bar x y)))
  (define bar (lambda (a b) (+ (* a b) a)))
  (foo (+ x 3)))                  45
A body containing internal definitions may always be converted into a completely equivalent letrec expression.  For example, the let expression in the previous example is equivalent to
(let ((x 5))
  (letrec ((foo (lambda (y) (bar x y)))
           (bar (lambda (a b) (+ (* a b) a))))
    (foo (+ x 3))))
Just as for the equivalent letrec expression, it shall be possible to evaluate each expression of every internal definition in a body without referring to the value of any variable being defined.