Next: , Previous: Definitions, Up: Definitions



5.2.1 Top level definitions

At the top level of a program, a definition

     
     (define <variable> <expression>)
     

has essentially the same effect as the assignment expression

     
     (set! <variable> <expression>)
     

if <variable> is bound. If <variable> is not bound, however, then the definition will bind <variable> to a new location before performing the assignment, whereas it would be an error to perform a set! on an unbound variable.

     
     (define add3
       (lambda (x) (+ x 3)))
     (add3 3)                               ==>  6
     (define first car)
     (first '(1 2))                         ==>  1
     

Some implementations of Scheme use an initial environment in which all possible variables are bound to locations, most of which contain undefined values. Top level definitions in such an implementation are truly equivalent to assignments.