Liking cljdoc? Tell your friends :D

emmy.pattern.syntax

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]].
raw docstring

binding?clj/s

(binding? pattern)

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> ...).
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> ...)`.
sourceraw docstring

compile-patternclj/s

(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)
  • 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.)

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.)
sourceraw docstring

restricted?clj/s

(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.
sourceraw docstring

restrictionclj/s

(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`.
sourceraw docstring

reverse-segment-nameclj/s

(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`.
sourceraw docstring

reverse-segment?clj/s

(reverse-segment? pattern)

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> ...).
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> ...)`.
sourceraw docstring

segment?clj/s

(segment? pattern)

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> ...).
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> ...)`.
sourceraw docstring

splice-reduceclj/s

(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]]
```
sourceraw docstring

unquote-splice?clj/s

(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.
sourceraw docstring

unquote?clj/s

(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.
sourceraw docstring

unquoted-formclj/s

(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.
sourceraw docstring

variable-nameclj/s

(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.
sourceraw docstring

wildcard?clj/s

(wildcard? pattern)

Returns true if pattern matches the wildcard character _, false otherwise.

Returns true if `pattern` matches the wildcard character `_`, false otherwise.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close