Version: 5.0
13 Syntax
This library is
unstable;
compatibility will not be maintained.
See
Unstable for more information.
The current contextual syntax object, defaulting to
#f. It
determines the special form name that prefixes syntax errors created
by
wrong-syntax.
Raises a syntax error using the result of
(current-syntax-context) as the “major” syntax object and
the provided
stx as the specific syntax object. (The latter,
stx, is usually the one highlighted by DrRacket.) The error
message is constructed using the format string and arguments, and it
is prefixed with the special form name as described under
current-syntax-context.
Examples: |
> (wrong-syntax #'here "expected ~s" 'there) |
?: expected there |
|
eval:4:0: look: expected there at: here in: (look over here) |
A macro using
wrong-syntax might set the syntax context at the very
beginning of its transformation as follows:
Then any calls to
wrong-syntax during the macro’s
transformation will refer to
my-macro (more precisely, the name that
referred to
my-macro where the macro was used, which may be
different due to renaming, prefixing, etc).
Definition form of
with-syntax. That is, it matches the
syntax object result of
expr against
pattern and
creates pattern variable definitions for the pattern variables of
pattern.
Evaluates
expr and binds it to
id as a pattern
variable, so
id can be used in subsequent
syntax
patterns.
Evaluates body with each temp-id bound as a pattern
variable to a freshly generated identifier.
Generates one fresh identifier. Singular form of
generate-temporaries. If
name-base is supplied, it
is used as the basis for the identifier’s name.
Generates a list of n fresh identifiers.
Parameter for tracking disappeared uses. Tracking is “enabled” when
the parameter has a non-false value. This is done automatically by
forms like
with-disappeared-uses.
Evaluates the
stx-expr, catching identifiers looked up using
syntax-local-value/catch. Adds the caught identifiers to the
'disappeared-uses syntax property of the resulting syntax
object.
Evaluates the
body-expr, catching identifiers looked up using
syntax-local-value/catch. Returns two values: the result of
body-expr and the list of caught identifiers.
Looks up
id in the syntactic environment (as
syntax-local-value). If the lookup succeeds and returns a
value satisfying the predicate, the value is returned and
id
is recorded (“caught”) as a disappeared use. If the lookup fails or
if the value does not satisfy the predicate,
#f is returned
and the identifier is not recorded as a disappeared use.
If not used within the extent of a with-disappeared-uses form
or similar, has no effect.
Add ids to the current disappeared uses.
If not used within the extent of a with-disappeared-uses form
or similar, has no effect.
Like
format, but produces a symbol. The format string must
use only
~a placeholders. Identifiers in the argument list
are automatically converted to symbols.
Like
format-symbol, but converts the symbol into an
identifier using
lctx for the lexical context,
src
for the source location,
props for the properties, and
cert for the inactive certificates. (See
datum->syntax.)
The format string must use only ~a placeholders. Identifiers
in the argument list are automatically converted to symbols.
Examples: |
|
> (make-pred pair) |
#<procedure:pair?> |
> (make-pred none-such) |
reference to undefined identifier: none-such? |
|
> (better-make-pred none-such) |
reference to undefined identifier: none-such? |
(Scribble doesn’t show it, but the DrRacket pinpoints the location of
the second error but not of the first.)
Applies the renamings of intdef-ctx to stx.
Evaluates stx as an expression in the current transformer
environment (that is, at phase level 1), optionally extended with
intdef-ctx.
Examples: |
|
> (show-me (+ 2 5)) |
at compile time produces 7 | at run time produes 7 |
|
> (define-for-syntax fruit 'apple) |
> (define fruit 'pear) |
> (show-me fruit) |
at compile time produces apple | at run time produes pear |
|
The subsequent bindings were added by Sam Tobin-Hochstadt.
Similar to
with-syntax, but the pattern variables are bound in the remaining
stx-exprs as well as the
bodys, and the
patterns need not
bind distinct pattern variables; later bindings shadow earlier bindings.
Example: |
|
#<syntax:22:0 ((val1) (val2))> |