Liking cljdoc? Tell your friends :D

meander.epsilon


$clj

($ pattern)
($ context-pattern pattern)

Pattern matching and substitution operator.

When used as a pattern matching operator will attempt match pattern against some value that is a subtree of the target of pattern matching. Optionally, context-pattern (should be a variable pattern) can be passed and will be applied against a function. This function accepts one argument and when invoked with some value x will return the original, root target updated with the x installed at the place where pattern matched successfully.

(match [:A 2]
  ($ (pred number? ?x))
  ?x)
;; => 2

(match [:A 2]
  ($ ?context (pred number? ?x))
  (?context 3))
;; => [:A 3]
Pattern matching and substitution operator.

When used as a pattern matching operator will attempt match
`pattern` against some value that is a subtree of the target of
pattern matching. Optionally, `context-pattern` (should be a
variable pattern) can be passed and will be applied against a
function. This function accepts one argument and when invoked with
some value `x` will return the original, root target updated with
the `x` installed at the place where `pattern` matched successfully.


    (match [:A 2]
      ($ (pred number? ?x))
      ?x)
    ;; => 2

    (match [:A 2]
      ($ ?context (pred number? ?x))
      (?context 3))
    ;; => [:A 3]
sourceraw docstring

$*clj

($* context pattern)
($* context pattern & patterns)
source

andclj

(and pattern & patterns)

Pattern matching operator which matches when pattern and, optionally, all of patterns match.

Pattern matching operator which matches when `pattern` and,
optionally, all of `patterns` match.
sourceraw docstring

appclj

(app f pattern)
(app f pattern & patterns)

Pattern matching operator which applies pattern matching the result applying f to the current value being matched.

Pattern matching operator which applies pattern matching the result
applying `f` to the current value being matched.
sourceraw docstring

(breadth-first-search x & clauses)

Like search but traverses the search space in breadth first order.

Like `search` but traverses the search space in breadth first
order.
sourceraw docstring

cataclj

(cata pattern)

Pattern matching operator which causes pattern matching to recurse on the target of pattern matching. The result is then pattern matched with pattern.

(match [1 2 3]
  [(cata ?x) (cata ?y) (cata ?z)]
  [?x ?y ?z]

  3
  :three

  2
  :two

  1
  :one)
;; =>
[:one :two :three]
Pattern matching operator which causes pattern matching to recurse
on the target of pattern matching. The result is then pattern
matched with `pattern`.

    (match [1 2 3]
      [(cata ?x) (cata ?y) (cata ?z)]
      [?x ?y ?z]

      3
      :three

      2
      :two

      1
      :one)
    ;; =>
    [:one :two :three]
sourceraw docstring

defsyntaxclj/smacro

(defsyntax name doc-string? attr-map? [params*] prepost-map? body)
(defsyntax name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?)
source

findclj/smacro

(find x match-pattern result & more-pattern-result-pairs)

Given some data x, returns a single result that satisfies match-clause which is the first solution explored in depth-first order.

Like search but returns only the first successful match.

Given some data `x`, returns a single `result` that satisfies `match-clause`
which is the first solution explored in depth-first order.

Like `search` but returns only the first successful match.
sourceraw docstring

gatherclj

(gather pattern)
(gather pattern count-pattern)

Pattern matching operator that works in a similar manner to clojure.core/filter.

gather allows you to match a pattern over a seqable, ignoring any values that don't match.

(match [1 2 3 4]
  (gather (m/pred even? !xs))
  !xs)
  ;; =>
  [2 4]

gather also offers a two arity version that can be supplied a logic variable, memory variable, _ pattern, number, or an ellipsis that allows control over the repeat behavior of gather.

(match [:a :b :a :a :c]
  (gather :a ?count)
  ?count)
  ;; =>
  3

(match [:a :b :a :a :c]
  (gather :a ..4)
   true

   _
   false)
   ;; =>
   false
Pattern matching operator that works in a similar manner to
 clojure.core/filter.

`gather` allows you to match a pattern over a seqable, ignoring any
values that don't match.


    (match [1 2 3 4]
      (gather (m/pred even? !xs))
      !xs)
      ;; =>
      [2 4]

`gather` also offers a two arity version that can be supplied a
logic variable, memory variable, _ pattern, number, or an ellipsis
that allows control over the repeat behavior of gather.

    (match [:a :b :a :a :c]
      (gather :a ?count)
      ?count)
      ;; =>
      3

    (match [:a :b :a :a :c]
      (gather :a ..4)
       true

       _
       false)
       ;; =>
       false
sourceraw docstring

guardclj

(guard pred-expr)

Pattern matching operator which succeeds whenever pred-expr returns a truthy result. pred-expr is evaluated by Clojure.

Pattern matching operator which succeeds whenever `pred-expr`
returns a truthy result. `pred-expr` is evaluated by Clojure.
sourceraw docstring

keywordclj

(keyword name)
(keyword namespace name)
(keyword namespace name & rest)

Pattern matching and substitution operator.

When used as a pattern matching operator it will match a keyword with name and, optionally, namespace.

(match :foo/bar
  (keyword ?name)
  ?name)
;; => "bar"

(match :foo/bar
  (keyword ?namespace ?name)
  [?namespace ?name])
;; => ["foo" "bar"]

Additionally, the keyword itself can be pattern matched against the :as keyword argument.

(match :foo/bar
  (keyword _ _ :as ?keyword)
  ?keyword)
;; => :foo/bar

When used as a substutition operator it will create a keyword with name and, optionally, namespace e.g. it behaves the same as clojure.core/keyword in the context of normal substitution behavior.

(subst (keyword "foo" "bar"))
;; => :foo/bar

;; clojure.core/let
(let [!namespaces ["foo" "foo"]
      !names ["bar" "baz"]]
  (subst [(keyword !namespaces !names) ...]))
;; => [:foo/bar :foo/baz]

For substitution the :as keyword argument is ignored.

Pattern matching and substitution operator.

When used as a pattern matching operator it will match a keyword
with `name` and, optionally, `namespace`.

    (match :foo/bar
      (keyword ?name)
      ?name)
    ;; => "bar"

    (match :foo/bar
      (keyword ?namespace ?name)
      [?namespace ?name])
    ;; => ["foo" "bar"]

Additionally, the keyword itself can be pattern matched against
the `:as` keyword argument.

    (match :foo/bar
      (keyword _ _ :as ?keyword)
      ?keyword)
    ;; => :foo/bar

When used as a substutition operator it will create a keyword with
`name` and, optionally, `namespace` e.g. it behaves the same as
`clojure.core/keyword` in the context of normal substitution
behavior.

    (subst (keyword "foo" "bar"))
    ;; => :foo/bar

    ;; clojure.core/let
    (let [!namespaces ["foo" "foo"]
          !names ["bar" "baz"]]
      (subst [(keyword !namespaces !names) ...]))
    ;; => [:foo/bar :foo/baz]

For substitution the `:as` keyword argument is ignored.
sourceraw docstring

letclj

(let binding-patterns)
(let binding-patterns target-pattern)
source

matchclj/smacro

(match x match-pattern result & more-pattern-result-pairs)

Given some data x, return the corresponding result if it matches match-pattern. Logic variables may exist in both the match-pattern and result, enabling the reshaping of data. match is the fundamental pattern matching operator.

Syntax

(match x
  pattern_1 expr_1
  ,,,
  pattern_n expr_n)

Attempts to pattern match x against one of patterns pattern_1 through pattern_n. If some pattern pattern_i matches successfully, expr_i will be executed. If none of the patterns match successfully an error will be thrown indicating the pattern match failed.

This operator restricts patterns which may have several possible solutions. For example, the pattern

#{?x ?y}

matches any set with at least two elements. However, with consideration to the property that Clojure sets are unordered, there are many possible ways we could bind values for ?x and ?y. Because there is no obvious way to know which solution to pick, patterns which have this property are illegal in the context of this operator. For operators which relax this restriction, see find and search.

Given some data `x`, return the corresponding `result` if it matches `match-pattern`.
Logic variables may exist in both the `match-pattern` and `result`,
enabling the reshaping of data.
`match` is the fundamental pattern matching operator.

Syntax

    (match x
      pattern_1 expr_1
      ,,,
      pattern_n expr_n)

Attempts to pattern match `x` against one of patterns `pattern_1`
through `pattern_n`. If some pattern `pattern_i` matches
successfully, `expr_i` will be executed. If none of the patterns
match successfully an error will be thrown indicating the pattern
match failed.

This operator restricts patterns which may have several possible
solutions. For example, the pattern

    #{?x ?y}

matches any set with at least two elements. However, with
consideration to the property that Clojure sets are unordered, there
are many possible ways we could bind values for `?x` and
`?y`. Because there is no obvious way to know which solution to
pick, patterns which have this property are illegal in the context
of this operator.
For operators which relax this restriction, see `find` and `search`.
sourceraw docstring

match-syntax?clj

(match-syntax? env)
source

notclj

(not pattern)

Pattern matching operator which matches when pattern does not match.

Pattern matching operator which matches when `pattern` does not
match.
sourceraw docstring

numberclj

(number)
(number pattern)

Pattern matching operator which matches a number?. Optionally pattern may be passed to further pattern match on the value.

Pattern matching operator which matches a `number?`. Optionally
`pattern` may be passed to further pattern match on the value.
sourceraw docstring

orclj

(or pattern & patterns)

Pattern matching operator which matches when either pattern or, opitionally, one of patterns match.

Pattern matching operator which matches when either `pattern` or,
opitionally, one of `patterns` match.
sourceraw docstring

predclj

(pred p)
(pred p pattern)
(pred p pattern & patterns)

Pattern matching operator which successfully matches whenever the target of pattern matching applied to expr returns a truthy value.

(match 1
  (pred odd?)
  :okay)
;; => :okay

Optionally, additional patterns patterns may be passed in which case they will be treated as an and pattern against the target of pattern matching.

(match 1
  (pred odd? ?x)
  :okay)

is the same as

(match 1
  (and (pred odd?) ?x)
  :okay)
Pattern matching operator which successfully matches whenever the
target of pattern matching applied to `expr` returns a truthy
value.

    (match 1
      (pred odd?)
      :okay)
    ;; => :okay

Optionally, additional patterns `patterns` may be passed in which
case they will be treated as an `and` pattern against the target of
pattern matching.

    (match 1
      (pred odd? ?x)
      :okay)

is the same as

    (match 1
      (and (pred odd?) ?x)
      :okay)
sourceraw docstring

reclj

(re regex-pattern)
(re regex-pattern capture-pattern)

Pattern matching operator which matches strings which match the regular expression regex-pattern with re-matches. Optionally, a second argument capture-pattern can be passed which will be matched against the result of the underlying re-matches call.

(match "foo"
  (re #"...")
  true)
;; =>
true

(match "foo"
  (re #"(.)(.)(.)" [?0 ?1 ?2 ?3])
  [?0 ?1 ?2 ?3])
;; =>
["foo" "f" "o" "o"]
Pattern matching operator which matches strings which match the
regular expression `regex-pattern` with `re-matches`. Optionally, a
second argument `capture-pattern` can be passed which will be
matched against the result of the underlying `re-matches` call.

    (match "foo"
      (re #"...")
      true)
    ;; =>
    true

    (match "foo"
      (re #"(.)(.)(.)" [?0 ?1 ?2 ?3])
      [?0 ?1 ?2 ?3])
    ;; =>
    ["foo" "f" "o" "o"]
sourceraw docstring

rewriteclj/smacro

(rewrite x match-pattern subst-pattern & more-pattern-pairs)

Given some data x, match a match-pattern and substitute with the subst-pattern.

Syntactic sugar for

 (find x
   p_1 (subst p_2)
   ,,,
   p_n-1 (subst p_n))
Given some data x, match a `match-pattern` and substitute with the `subst-pattern`.

Syntactic sugar for

     (find x
       p_1 (subst p_2)
       ,,,
       p_n-1 (subst p_n))
sourceraw docstring

rewritesclj/smacro

(rewrites x & clauses)
source

scanclj

(scan & patterns)

Pattern matching operator which matches the seq of seqable? forms of the shape

(_ ... p1 ,,, pn . _ ...)

or vectors? of the form

[_ ... p1 ,,, pn . _ ...]

where the sequence p1 through pn is equal to patterns.

Pattern matching operator which matches the `seq` of `seqable?`
forms of the shape

    (_ ... p1 ,,, pn . _ ...)

or `vectors?` of the form

    [_ ... p1 ,,, pn . _ ...]

where the sequence `p1` through `pn` is equal to `patterns`.
sourceraw docstring

(search x match-pattern result & more-pattern-result-pairs)

Given some data x, searches for variable assignments that satisfy a match-pattern, and returns a user defined result which may use those variables. Returns a lazy sequence of expression values in depth-first order.

Like match but allows for patterns which may match x in more than one way.

Example

(search [1 2 3]
  [!xs ... !ys ...]
  {'!xs !xs, '!ys !ys})
;; =>
({!xs [], !ys [1 2 3]}
 {!xs [1], !ys [2 3]}
 {!xs [1 2], !ys [3]}
 {!xs [1 2 3], !ys []})

Note, if only the first value is needed, use find instead. The expression

(first (search x ,,,))

can be significantly slower than

(find x ,,,)
Given some data `x`, searches for variable assignments that satisfy a `match-pattern`,
and returns a user defined `result` which may use those variables.
Returns a lazy sequence of expression values in depth-first order.

Like `match` but allows for patterns which may match `x` in more
than one way.

Example

    (search [1 2 3]
      [!xs ... !ys ...]
      {'!xs !xs, '!ys !ys})
    ;; =>
    ({!xs [], !ys [1 2 3]}
     {!xs [1], !ys [2 3]}
     {!xs [1 2], !ys [3]}
     {!xs [1 2 3], !ys []})

Note, if only the first value is needed, use `find` instead. The
expression

    (first (search x ,,,))

can be significantly slower than

    (find x ,,,)
sourceraw docstring

separatedclj

(separated & patterns)

Pattern matching operator which matches the seq of seqable? forms of the shape

(_ ... p1 ,,, . _ ... pn . _ ...)

or vectors? of the form

[_ ... p1 ,,, . _ ... pn . _ ...]

where the sequence p1 through pn is equal to patterns.

Pattern matching operator which matches the `seq` of `seqable?`
forms of the shape

    (_ ... p1 ,,, . _ ... pn . _ ...)

or `vectors?` of the form

    [_ ... p1 ,,, . _ ... pn . _ ...]

where the sequence `p1` through `pn` is equal to `patterns`.
sourceraw docstring

seqableclj

(seqable & patterns)

Pattern matching operator which matches the seq of anything that is seqable? against

(p1 ,,, pn)

where the sequence p1 through pn is equal to patterns.

Pattern matching operator which matches the `seq` of anything that
is `seqable?` against

    (p1 ,,, pn)

where the sequence `p1` through `pn` is equal to `patterns`.
sourceraw docstring

someclj

(some)
(some pattern)

Pattern matching operator which matches a non nil value. Optionally, pattern may be passed to further match on the value.

Pattern matching operator which matches a non `nil`
value. Optionally, `pattern` may be passed to further match on the
value.
sourceraw docstring

substclj/smacro

(subst pattern)

Substitution operator, the inverse of pattern matching. Evaluates pattern in the Clojure environment.

Substitution operator, the inverse of pattern matching. Evaluates
`pattern` in the Clojure environment.
sourceraw docstring

subst-syntax?clj

(subst-syntax? env)
source

symbolclj

(symbol name)
(symbol namespace name)
(symbol namespace name & rest)

Pattern matching and substitution operator.

When used as a pattern matching operator it will match a symbol with name and, optionally, namespace.

(match 'foo/bar
  (symbol ?name)
  ?name)
;; => "bar"

(match :foo/bar
  (symbol ?namespace ?name)
  [?namespace ?name])
;; => ["foo" "bar"]

Additionally, the symbol itself can be pattern matched against the :as keyword argument.

(match 'foo/bar
  (symbol _ _ :as ?symbol)
  ?symbol)
;; => 'foo/bar

When used as a substutition operator it will create a symbol with name and, optionally, namespace e.g. it behaves the same as clojure.core/symbol in the context of normal substitution behavior.

(subst (symbol "foo" "bar"))
;; => 'foo/bar

;; clojure.core/let
(let [!namespaces ["foo" "foo"]
      !names ["bar" "baz"]]
  (subst [(symbol !namespaces !names) ...]))
;; => ['foo/bar 'foo/baz]

For substitution the :as keyword argument is ignored.

Pattern matching and substitution operator.

When used as a pattern matching operator it will match a symbol
with `name` and, optionally, `namespace`.

    (match 'foo/bar
      (symbol ?name)
      ?name)
    ;; => "bar"

    (match :foo/bar
      (symbol ?namespace ?name)
      [?namespace ?name])
    ;; => ["foo" "bar"]


Additionally, the symbol itself can be pattern matched against
the `:as` keyword argument.

    (match 'foo/bar
      (symbol _ _ :as ?symbol)
      ?symbol)
    ;; => 'foo/bar

When used as a substutition operator it will create a symbol with
`name` and, optionally, `namespace` e.g. it behaves the same as
`clojure.core/symbol` in the context of normal substitution
behavior.

    (subst (symbol "foo" "bar"))
    ;; => 'foo/bar

    ;; clojure.core/let
    (let [!namespaces ["foo" "foo"]
          !names ["bar" "baz"]]
      (subst [(symbol !namespaces !names) ...]))
    ;; => ['foo/bar 'foo/baz]

For substitution the `:as` keyword argument is ignored.
sourceraw docstring

withclj

(with pattern-bindings body)

Pattern matching and substitution operator.

Syntax

(with [%pattern-name pattern ...]
  target-pattern)

Allows for patterns to be referenced by %pattern-name in target-pattern.

Example

(match [[1 2] [1 2]]
  (with [%x-y [?x ?y]]
    [%x-y %x-y])
  {:x ?x, :y ?y})
;; =>
{:x 1, :y 2}
Pattern matching and substitution operator.

Syntax

    (with [%pattern-name pattern ...]
      target-pattern)

Allows for patterns to be referenced by %pattern-name in
target-pattern.

Example

    (match [[1 2] [1 2]]
      (with [%x-y [?x ?y]]
        [%x-y %x-y])
      {:x ?x, :y ?y})
    ;; =>
    {:x 1, :y 2}
sourceraw docstring

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

× close