The syntax namespace defines the default syntax for patterns corresponding to
the matcher combinators defined in emmy.pattern.match
.
The syntax namespace defines the default syntax for patterns corresponding to the matcher combinators defined in [[emmy.pattern.match]].
(binding? pattern)
Returns true if pattern
is a binding variable reference, false otherwise.
A binding variable is either:
?
character(? <binding> ...)
.Returns true if `pattern` is a binding variable reference, false otherwise. A binding variable is either: - A symbol starting with a single `?` character - A sequence of the form `(? <binding> ...)`.
(compile-pattern pattern)
Given a pattern with unquoted binding forms and, potentially, ~
and ~@
entries, returns a pattern appropriately quoted such that it can be evaluated
by the Clojure reader.
Changes:
(? x) => (list '? 'x)
~x
is left UNquoted, even in the symbol spot of (? ~sym ...)
~@[1 2 3]
is spliced in directly, EVEN in the symbol spot
of (? ~@sym ...)
These rules proceed recursively down into map, vector and sequential data structures. (Recursion only pushes down into values for map-shaped patterns.)
Given a pattern with unquoted binding forms and, potentially, `~` and `~@` entries, returns a pattern appropriately quoted such that it can be evaluated by the Clojure reader. Changes: - `(? x) => (list '? 'x)` - any bare symbol is quoted - Any form unquoted like `~x` is left UNquoted, even in the symbol spot of `(? ~sym ...)` - Any form marked `~@[1 2 3]` is spliced in directly, EVEN in the symbol spot of `(? ~@sym ...)` These rules proceed recursively down into map, vector and sequential data structures. (Recursion only pushes down into values for map-shaped patterns.)
(restricted? pattern)
Returns true if pattern
is a binding pattern with restriction predicates,
false otherwise.
Returns true if `pattern` is a binding pattern with restriction predicates, false otherwise.
(restriction pattern)
If pattern
is a variable binding form in a pattern with restriction predicates,
returns a predicate that only returns true if all of the predicates pass for
its input, false otherwise.
If pattern
has no restrictions or is some other input type, returns a
predicate that will always return true
.
If `pattern` is a variable binding form in a pattern with restriction predicates, returns a predicate that only returns true if all of the predicates pass for its input, false otherwise. If `pattern` has no restrictions or is some other input type, returns a predicate that will always return `true`.
(reverse-segment-name pattern)
Given a REVERSE-segment name, either extracts the symbol from a pattern
like (:$$ x)
, or transforms symbols like $$x
into ??x
.
Given a REVERSE-segment name, either extracts the symbol from a pattern like `(:$$ x)`, or transforms symbols like `$$x` into `??x`.
(reverse-segment? pattern)
Returns true if pattern
is a reversed-segment variable reference, false
otherwise.
A reverse-segment binding variable is either:
$$
(:$$ <binding> ...)
.Returns true if `pattern` is a reversed-segment variable reference, false otherwise. A reverse-segment binding variable is either: - A symbol starting with `$$` - A sequence of the form `(:$$ <binding> ...)`.
(segment? pattern)
Returns true if pattern
is a segment variable reference, false otherwise.
A segment binding variable is either:
??
(?? <binding> ...)
.Returns true if `pattern` is a segment variable reference, false otherwise. A segment binding variable is either: - A symbol starting with `??` - A sequence of the form `(?? <binding> ...)`.
(splice-reduce splice? f xs)
Helper function for reducing over a sequence that might contain forms that need
to be spliced into the resulting sequence. This is a sort of helper for a
guarded mapcat
.
Takes a sequence xs
and mapping function f
and returns a sequence of
sequences that, if concatenated together, would be identical to
(map f xs)
Where any x
such that (splice? x)
returns true would have its sequential
value (f x)
spliced into the result.
For example:
(let [f (fn [x] (if (odd? x) [x x x] x))]
(splice-reduce odd? f (range 5)))
;;=> [[0] [1 1 1] [2] [3 3 3] [4]]
Helper function for reducing over a sequence that might contain forms that need to be spliced into the resulting sequence. This is a sort of helper for a guarded `mapcat`. Takes a sequence `xs` and mapping function `f` and returns a sequence of sequences that, if concatenated together, would be identical to ```clojure (map f xs) ``` Where any `x` such that `(splice? x)` returns true would have its sequential value `(f x)` spliced into the result. For example: ```clojure (let [f (fn [x] (if (odd? x) [x x x] x))] (splice-reduce odd? f (range 5))) ;;=> [[0] [1 1 1] [2] [3 3 3] [4]] ```
(unquote-splice? pattern)
Returns true if pattern
is a sequence form that should be spliced directly
into the returned pattern, false otherwise.
Returns true if `pattern` is a sequence form that should be spliced directly into the returned pattern, false otherwise.
(unquote? pattern)
Returns true if pattern
is a form that should be included with no quoting
into the returned pattern, false otherwise.
Returns true if `pattern` is a form that should be included with no quoting into the returned pattern, false otherwise.
(unquoted-form pattern)
Given a pattern
that responds true
to unquote?
or unquote-splice?
,
returns the form from that pattern.
Given a `pattern` that responds `true` to [[unquote?]] or [[unquote-splice?]], returns the form from that pattern.
(variable-name pattern)
Given a variable or segment binding form, returns the binding variable.
NOTE that variable-name
will not guard against incorrect inputs.
Given a variable or segment binding form, returns the binding variable. NOTE that [[variable-name]] will not guard against incorrect inputs.
(wildcard? pattern)
Returns true if pattern
matches the wildcard character _
, false otherwise.
Returns true if `pattern` matches the wildcard character `_`, false otherwise.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close