[previous] [up] [next]     [contents] [index]
Next: Local Variables Up: Binding Forms Previous: Binding Forms

Global Variables

Top-level variables are bound with the standard Scheme define form. Multiple values are bound to multiple variables at once with define-values:

  (define-values (variable  tex2html_wrap_inline12550 ) expr) 
The number of values returned by expr must match the number of variables provided.

All of the variables are bound sequentially after expr is evaluated. If an error occurs while binding one of the definitions (perhaps because the variable is a constant that is already defined), then the definitions for the preceding variables will have already completed, but definitions for the remaining variables will never complete.

Examples:

  (define x 1) 
  x ; => 1 
  (define-values (x) 2) 
  x ; => 2 
  (define-values (x y) (values 3 4)) 
  x ; => 3 
  y ; => 4 
  (define-values (x y) (values 5 (add1 x))) 
  y ; => 4 
  (define-values () (values)) ; same as (void) 
  (define x (values 7 8)) ; => exn:application:arity, 2 values for 1-value context
  (define-values (x y) 7) ; => exn:application:arity, 1 value for 2-value context
  (define-values () 7) ; => exn:application:arity, 1 value for 0-value context



PLT