2.14 Definitions: define, define-syntax, ...
Definitions: define in Guide: Racket introduces definitions.
(define id expr) | ||||||||||||||||||||||||||||||||||||||||||||||||||
(define (head args) body ...+) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
(CVT (id . kw-formals) . datum) = (lambda kw-formals . datum) (CVT (head . kw-formals) . datum) = (lambda kw-formals expr) if (CVT head . datum) = expr
In an internal-definition context (see Internal Definitions), a define form introduces a local binding. At the top level, the top-level binding for id is created after evaluating expr, if it does not exist already, and the top-level mapping of id (in the namespace linked with the compiled definition) is set to the binding at the same time.
Examples: | |||||
|
(define ((f x) [y 20]) (+ x y))
> ((f 10) 30) 40
> ((f 10)) 30
(define-values (id ...) expr) |
In an internal-definition context (see Internal Definitions), a define-values form introduces local bindings. At the top level, the top-level binding for each id is created after evaluating expr, if it does not exist already, and the top-level mapping of each id (in the namespace linked with the compiled definition) is set to the binding at the same time.
Examples: | ||||||||
|
(define-syntax id expr) |
(define-syntax (head args) body ...+) |
The second form is a shorthand the same as for define; it expands to a definition of the first form where the expr is a lambda form.
In an internal-definition context (see Internal Definitions), a define-syntax form introduces a local binding.
Examples: | ||||||||||||||
|
(define-syntaxes (id ...) expr) |
When expr produces zero values for a top-level define-syntaxes (i.e., not in a module or internal-definition position), then the ids are effectively declared without binding; see Macro-Introduced Bindings.
In an internal-definition context (see Internal Definitions), a define-syntaxes form introduces local bindings.
Examples: | ||||||||||||||||||||
|
(define-for-syntax id expr) |
(define-for-syntax (head args) body ...+) |
Within a module, bindings introduced by define-for-syntax must appear before their uses or in the same define-for-syntax form (i.e., the define-for-syntax form must be expanded before the use is expanded). In particular, mutually recursive functions bound by define-for-syntax must be defined by the same define-for-syntax form.
Examples: | |||||||||||||||||||||||||
|
(define-values-for-syntax (id ...) expr) |
Examples: | ||||||||
|
2.14.1 require Macros
(define-require-syntax id expr) |
(define-require-syntax (id args ...) body ...+) |
This form expands to define-syntax with a use of make-require-transformer; see require Transformers for more information.
The second form is a shorthand the same as for define-syntax; it expands to a definition of the first form where the expr is a lambda form.
2.14.2 provide Macros
(define-provide-syntax id expr) |
(define-provide-syntax (id args ...) body ...+) |
This form expands to define-syntax with a use of make-provide-transformer; see provide Transformers for more information.
The second form is a shorthand the same as for define-syntax; it expands to a definition of the first form where the expr is a lambda form.