Top-Level Definitions - MIT/GNU Scheme 9.1
Description: MIT/GNU Scheme 9.1

Next: Internal Definitions, Previous: Definitions, Up: Definitions

#### 2.4.1 Top-Level Definitions

A top-level definition,

         (define variable expression)

has essentially the same effect as this assignment expression, if variable is bound:

         (set! variable expression)

If variable is not bound, however, `define` binds variable to a new location in the current environment before performing the assignment (it is an error to perform a `set!` on an unbound variable). If you omit expression, the variable becomes unassigned; an attempt to reference such a variable is an error.

         (define add3
            (lambda (x) (+ x 3)))                =>  unspecified
         (add3 3)                                =>  6

         (define first car)                      =>  unspecified
         (first '(1 2))                          =>  1

         (define bar)                            =>  unspecified
         bar                                     error--> Unassigned variable