Node:Pattern language, Previous:Binding constructs for syntactic keywords, Up:Macros
A <transformer spec> has the following form:
syntax-rules <literals> <syntax rule> ... |
Syntax:
<Literals> is a list of identifiers and each <syntax rule>
should be of the form
(<pattern> <template>) The <pattern> in a <syntax rule> is a list <pattern> that begins with the keyword for the macro. A <pattern> is either an identifier, a constant, or one of the
following
(<pattern> ...) (<pattern> <pattern> ... . <pattern>) (<pattern> ... <pattern> <ellipsis>) #(<pattern> ...) #(<pattern> ... <pattern> <ellipsis>) and a template is either an identifier, a constant, or one of the following
(<element> ...) (<element> <element> ... . <template>) #(<element> ...) where an <element> is a <template> optionally
followed by an <ellipsis> and
an <ellipsis> is the identifier " Semantics: An instance of An identifier that appears in the pattern of a <syntax rule> is
a pattern variable, unless it is the keyword that begins the pattern,
is listed in <literals>, or is the identifier " The keyword at the beginning of the pattern in a <syntax rule> is not involved in the matching and is not considered a pattern variable or literal identifier. Rationale: The scope of the keyword is determined by the expression or syntax definition that binds it to the associated macro transformer. If the keyword were a pattern variable or literal identifier, then the template that follows the pattern would be within its scope regardless of whether the keyword were bound by Identifiers that appear in <literals> are interpreted as literal identifiers to be matched against corresponding subforms of the input. A subform in the input matches a literal identifier if and only if it is an identifier and either both its occurrence in the macro expression and its occurrence in the macro definition have the same lexical binding, or the two identifiers are equal and both have no lexical binding. A subpattern followed by More formally, an input form F matches a pattern P if and only if:
It is an error to use a macro keyword, within the scope of its binding, in an expression that does not match any of the patterns. When a macro use is transcribed according to the template of the
matching <syntax rule>, pattern variables that occur in the
template are replaced by the subforms they match in the input.
Pattern variables that occur in subpatterns followed by one or more
instances of the identifier
Identifiers that appear in the template but are not pattern variables
or the identifier
As an example, if (let ((=> #f)) (cond (#t => 'ok))) ==> ok The macro transformer for (let ((=> #f)) (if #t (begin => 'ok))) instead of
(let ((=> #f)) (let ((temp #t)) (if temp ('ok temp)))) which would result in an invalid procedure call. |