Definitions: define in The Racket Guide introduces definitions.
(define (head args) body ...+) head = id | (head args) args = arg ... | arg ... . rest-id arg = arg-id | [arg-id default-expr] | keyword arg-id | keyword [arg-id default-expr](define id expr)
The first form
binds
idto the result of
expr, and the second form
binds
idto a procedure. In the second case, the generated procedure is
(CVT (head args) body ...+), using the
CVTmeta-function defined as follows:
(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, a define form introduces a local binding; see Internal Definitions. 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.
In a context that allows liberal expansion of define, id is bound as syntax if expr is an immediate lambda form with keyword arguments or args include keyword arguments.
Examples:
(define x 10) > x10
> (f 10)11
> ((f 10) 30)40
> ((f 10))30
Evaluates the
expr, and
binds the results to the
ids, in order, if the number of results matches the number of
ids; if
exprproduces a different number of results, the
exn:fail:contractexception is raised.
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:
If a define-values form for a function definition in a module body has a 'compiler-hint:cross-module-inline syntax property with a true value, then the Racket treats the property as a performance hint. See Function-Call Optimizations in The Racket Guide for more information, and see also begin-encourage-inline.
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:
> (foo 1 2 3 4)(1 2 3 4)
> (bar 1 2 3 4)(1 2 3 4)
Like
define-syntax, but creates a
transformerbinding for each
id. The
exprshould produce as many values as
ids, and each value is bound to the corresponding
id.
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:
> (foo1)1
> (foo2)2
> (foo3)3
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-for-syntax helper 2) > (make-two)helper is 2
2
; ‘helper' is not bound in the runtime phase > helperhelper: undefined;
cannot reference an identifier before its definition
in module: top-level
> (let ([a 1] [b 2] [c 3]) (show-variables a 5 2 b c))'(1 2 3)
Examples:
3.14.1 require Macros🔗ℹThe first form is like
define-syntax, but for a
requiresub-form. The
proc-exprmust produce a procedure that accepts and returns a syntax object representing a
requiresub-form.
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 proc-expr is a lambda form.
Changed in version 6.90.0.29 of package base: Made equivalent to syntax-local-introduce.
3.14.2 provide Macros🔗ℹThe first form is like
define-syntax, but for a
providesub-form. The
proc-exprmust produce a procedure that accepts and returns a syntax object representing a
providesub-form.
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.
Changed in version 6.90.0.29 of package base: Made equivalent to syntax-local-introduce.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4