6.3.90.900
7.7 mischief/visitor: Compositional, Higher-Order Value Traversals
(require mischief/visitor) | package: mischief-dev |
Invokes visitor on target, passing on the given
arg-or-keyword-args.
Recognizes visitors.
procedure
(visitor-combine visitor ...) → visitor?
visitor : visitor?
Constructs a compound visitor that tries the given visitors from left
to right to find one that can process any given value.
Constructs a visitor that always calls handler with the target value
and any additional arguments.
procedure
(make-leaf-visitor predicate handler) → visitor?
predicate : (-> any/c boolean?) handler : (-> any/c any/c ... any/c)
Constructs a visitor that handles target values that satisfy
predicate. These target values are passed to handler along
with any additional arguments that were passed to the visitor.
procedure
(make-visitor predicate handler) → visitor?
predicate : (-> any/c boolean?) handler : (-> (-> any/c any/c ... any/c) any/c any/c ... any/c)
Constructs a visitor that handles target values that satisfy
predicate. The handler is called with a recursive handler procedure,
the target value, and any additional arguments that were passed to the visitor.
procedure
(make-wrapper-visitor handler) → visitor?
handler :
(-> (-> any/c any/c ... any/c) (-> any/c any/c ... any/c) any/c any/c ... any/c)
Constructs a visitor that processes all target values, given two recursive
handler procedures. The first resumes the search for a relevant visitor after
the current one within a compound visitor, and is usually used for the given
value when the current visitor is not relevant. The second uses the whole
visitor in use, and is intended for recursive handling of sub-parts.
procedure
(make-uniform-default-visitor handler) → visitor?
handler : (-> any/c any/c)
procedure
(make-uniform-leaf-visitor predicate handler) → visitor? predicate : (-> any/c boolean?) handler : (-> any/c any/c)
procedure
(make-uniform-visitor predicate handler) → visitor?
predicate : (-> any/c boolean?) handler : (-> (-> any/c any/c) any/c)
procedure
(make-uniform-wrapper-visitor handler) → visitor?
handler : (-> (-> any/c any/c) (-> any/c any/c) any/c any/c)
Variants of make-default-visitor, make-leaf-visitor,
make-visitor, and make-wrapper-visitor that ignore any
additional arguments, and automatically pass them on unchange to all recursive
visitor calls.
value
A visitor that reconstructs its target value.
value
value
A visitor that expects two additional arguments: a unary map function to
transform individual elements of the target value, and a variable-arity
reduce function to combine results.
procedure
(make-map-visitor predicate constructor accessor ...) → visitor? predicate : (-> any/c boolean?) constructor : (-> any/c ... predicate) accessor : (-> predicate any/c)
Creates a visitor that handles values satisfying predicate by
extracting their fields with the given accessors, recursively visiting
each, then reassembling the result using the constructor.
procedure
(make-for-each-visitor predicate accessor ...) → visitor? predicate : (-> any/c boolean?) accessor : (-> predicate/c any/c)
Creates a visitor that handles values satisfying predicate by
extracting their fields with the given accessors and recursively
visiting each. Always returns (void).
procedure
(make-map/reduce-visitor predicate accessor ...) → visitor? predicate : (-> any/c boolean?) accessor : (-> predicate/c any/c)
Creates a visitor that handles values satisfying predicate by
extracting their fields with the given accessors, recursively visiting
each, then reassembling the result using the visitor’s reduce function.
procedure
(make-memoizing-visitor [memo]) → visitor?
memo : memo-table? = (make-memo-table)
Creates a visitor that memoizes the results of passing each target value to
subsequent visitors.