Next: Iteration Forms, Previous: Basic Concepts, Up: For [Contents][Index]
Two definers are available for defining sequence constructors and special-clause operators. This chapter specifies them.
This definer defines the sequence constructor name as a generator
with arglist as the argument list, an optional docstring as
the documentation string, and optional bodys as the body. When no
body is present and arglist does not contain a &rest
argument (see (elisp)Argument List), the default body is used.
The default body consists of a sole expression as follows where
value is a generated identifier and args is arglist
with a potential &optional
keyword removed:
(for-iter ((value (name . args)) value))
Additional properties can be associated with the sequence constructor with optional subforms where a subform is one of the following types:
(declare [declaration…])
(:alias [alias…])
(:type [type…])
(:expander (arg) body…)
or
(:expander-case [case…])
It is an error for a type to appear more than once. The form of
declare
subforms is the same as normal declare
forms
(see (elisp)Declare Form). An alias is an identifier as an
alias of name available when used in iteration clauses. For each
type, a primary method for for-generator
is defined as
follows where datum is a generated identifier:
(cl-defmethod for-generator ((datum type)) (name datum))
When an :expander
subform is present, an expander with
arg as the sole argument and bodys as the body is defined
and available when used in iteration clauses. The expander receives the
iteration clause as the argument and produces an expanded iteration
clause. An :expander-case
subform is equivalent to an
:expander
subform with (pcase-exhaustive arg
[case…])
as the sole expression in body.
Note that the subforms are processed before the generator is defined. Therefore, the aliases and expander are available in the body of generator.
This definer defines the special-clause operator name as an
expander with an optional docstring as the documentation string.
It is an error for name to be a non-keyword. When a special
clause (name . subforms)
is encountered, the expander
is invoked. The expander receives two arguments where the first is the
special clause and the second is the body expanded so far as a list of
forms, and produces the further expanded body as a list of forms.
arglist and subforms are expanded as follows:
(special-clause body)
is the argument list of
expander where special-clause is a generated identifier, and
(pcase-exhaustive special-clause
[subform…])
is the sole expression in the body
of expander.
It is an error for arglist to be in any other form.
Next: Iteration Forms, Previous: Basic Concepts, Up: For [Contents][Index]