2.14 Definitions: define, define-syntax, ...
Definitions: define in Guide: PLT Scheme 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 |
At the top level, the top-level binding 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: | ||
| ||
| > x | ||
10 |
| ||||
| ||||
|
| (define-values (id ) expr) |
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: | ||
| ||
| ||
| > z | ||
3 |
| (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.
Examples: | ||||
| ||||
| > (foo 1 2 3 4) | ||||
(1 2 3 4) | ||||
| ||||
| > (bar 1 2 3 4) | ||||
(1 2 3 4) |
| (define-syntaxes (id ) expr) |
Examples: | |||||||||||||
| |||||||||||||
| > (foo1) | |||||||||||||
1 | |||||||||||||
| > (foo2) | |||||||||||||
2 | |||||||||||||
| > (foo3) | |||||||||||||
3 |
| (define-for-syntax id expr) |
| (define-for-syntax (head args) body ) |
Examples: | ||||
| > (define-for-syntax foo 2) | ||||
| ||||
| > (bar) | ||||
foo is 2 | ||||
2 | ||||
| ||||
| > (bar2) | ||||
foo is 2 | ||||
3 |
| (define-values-for-syntax (id ) expr) |
Examples: | |||
| > (define-values-for-syntax (foo1 foo2) (values 1 2)) | |||
| |||
| > (bar) | |||
foo1 is 1 foo2 is 2 | |||
2 |
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.
