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

$*clj

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

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.
raw 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.
raw 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.
raw 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]
raw 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?)

findclj/smacro

(find x & clauses)

Like search but returns only the first successful match.

Syntax:

(find x
  pattern_1 expr_1
  ,,,
  pattern_n expr_n)

Optionally, type checks and/or bounds checks can be omitted from compiled code by annotating the find macro form with meta data.

;; Disable runtime type checking. ^::no-type-check (find ,,,)

;; Disable runtime bounds checking of sequences. ^::no-bounds-check (find ,,,)

;; Disable both runtime type checking and bounds checking. ^::unsafe (find ,,,)

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

Syntax:

    (find x
      pattern_1 expr_1
      ,,,
      pattern_n expr_n)

Optionally, type checks and/or bounds checks can be omitted from
compiled code by annotating the `find` macro form with meta data.

  ;; Disable runtime type checking.
  ^::no-type-check (find ,,,)

  ;; Disable runtime bounds checking of sequences.
  ^::no-bounds-check (find ,,,)

  ;; Disable both runtime type checking and bounds checking.
  ^::unsafe (find ,,,)
raw 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
raw 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.
raw 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.
raw docstring

letclj

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

map-ofclj

(map-of k-pattern v-pattern)

Pattern matching and substitution operator.

When used as a pattern matching operator, matches a map where all the entries have keys which match k-pattern and all the values match v-pattern.

When used as a pattern substitution operator, constructs a map where all entries are constructed with keys with k-pattern and values with v-pattern.

Pattern matching and substitution operator.

When used as a pattern matching operator, matches a map where all
the entries have keys which match `k-pattern` and all the values
match `v-pattern`.

When used as a pattern substitution operator, constructs a map where
all entries are constructed with keys with `k-pattern` and
values with `v-pattern`.
raw docstring

matchclj/smacro

(match x pattern expr)
(match x pattern expr & more-clauses)

Basic pattern matching macro.

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.

Optionally, type checks and/or bounds checks can be omitted from compiled code by annotating the match macro form with meta data.

;; Disable runtime type checking. ^::no-type-check (match ,,,)

;; Disable runtime bounds checking of sequences. ^::no-bounds-check (match ,,,)

;; Disable both runtime type checking and bounds checking. ^::unsafe (match ,,,)

Note: This operator restricts ambiguous patterns i.e. patterns which have more than one possible match. 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.

Basic pattern matching macro.

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.

Optionally, type checks and/or bounds checks can be omitted from
compiled code by annotating the `match` macro form with meta data.

  ;; Disable runtime type checking.
  ^::no-type-check (match ,,,)

  ;; Disable runtime bounds checking of sequences.
  ^::no-bounds-check (match ,,,)

  ;; Disable both runtime type checking and bounds checking.
  ^::unsafe (match ,,,)

Note: This operator restricts ambiguous patterns i.e. patterns which
have more than one possible match. 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`.
raw docstring

match-syntax?clj

(match-syntax? env)

notclj

(not pattern)

Pattern matching operator which matches when pattern does not match.

Pattern matching operator which matches when `pattern` does not
match.
raw 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.
raw 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.
raw 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)
raw 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"]
raw 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))
raw docstring

rewritesclj/smacro

(rewrites x & clauses)

Like rewrite but is sugar for

(search x p_1 (subst p_2) ,,, p_n-1 (subst p_n))

Like `rewrite` but is sugar for

(search x
  p_1 (subst p_2)
  ,,,
  p_n-1 (subst p_n))
raw docstring

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

(search x & clauses)

Like match but allows for ambiguous patterns and returns a lazy sequence of all expression values in depth-first order.

Syntax:

(search x
  pattern_1 expr_1
  ,,,
  pattern_n expr_n)

Optionally, type checks and/or bounds checks can be omitted from compiled code by annotating the search macro form with meta data.

;; Disable runtime type checking. ^::no-type-check (search ,,,)

;; Disable runtime bounds checking of sequences. ^::no-bounds-check (search ,,,)

;; Disable both runtime type checking and bounds checking. ^::unsafe (search ,,,)

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 []})

Example:

(search {:foo 1, :bar 2, :baz 1, :quux 2}
  {?k 1}
  [?k :one]

  {?k 2}
  [?k :two])
;; =>
([:foo :one]
 [:baz :one]
 [:quux :two]
 [:bar :two])

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

(first (search x ,,,))

can be significantly slower than

(find x ,,,)
Like `match` but allows for ambiguous patterns and returns a lazy
sequence of all expression values in depth-first order.

Syntax:

    (search x
      pattern_1 expr_1
      ,,,
      pattern_n expr_n)

Optionally, type checks and/or bounds checks can be omitted from
compiled code by annotating the `search` macro form with meta data.

  ;; Disable runtime type checking.
  ^::no-type-check (search ,,,)

  ;; Disable runtime bounds checking of sequences.
  ^::no-bounds-check (search ,,,)

  ;; Disable both runtime type checking and bounds checking.
  ^::unsafe (search ,,,)

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 []})

Example:

    (search {:foo 1, :bar 2, :baz 1, :quux 2}
      {?k 1}
      [?k :one]
    
      {?k 2}
      [?k :two])
    ;; =>
    ([:foo :one]
     [:baz :one]
     [:quux :two]
     [:bar :two])

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

    (first (search x ,,,))

can be significantly slower than

    (find x ,,,)
raw 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`.
raw 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`.
raw docstring

set-ofclj

(set-of k-pattern)

Pattern matching and substitution operator.

When used as a pattern matching operator matches a set where all the entries have keys which match k-pattern.

When used as a pattern substitution operator constructs a set where all keys are constructed with k-pattern.

Pattern matching and substitution operator.

When used as a pattern matching operator matches a set where all
the entries have keys which match `k-pattern`.

When used as a pattern substitution operator constructs a set where
all keys are constructed with `k-pattern`.
raw 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.
raw docstring

submap-ofclj

(submap-of k-pattern v-pattern)

Pattern matching and substitution operator.

When used as a pattern matching operator matches a map where some or none of the entries have keys that match k-pattern and values which match v-pattern.

When used as a pattern substitution operator constructs a map where all entries are constructed with keys with k-pattern and values with v-pattern.

Pattern matching and substitution operator.

When used as a pattern matching operator matches a map where some
or none of the entries have keys that match `k-pattern` and values
which match `v-pattern`.

When used as a pattern substitution operator constructs a map where
all entries are constructed with keys with `k-pattern` and
values with `v-pattern`.
raw docstring

subset-ofclj

(subset-of k-pattern)

Pattern matching and substitution operator.

When used as a pattern matching operator matches a set where some or none of the entries have keys which match k-pattern.

When used as a pattern substitution operator constructs a set where all keys are constructed with k-pattern.

Pattern matching and substitution operator.

When used as a pattern matching operator matches a set where
some or none of the entries have keys which match `k-pattern`.

When used as a pattern substitution operator constructs a set where
all keys are constructed with `k-pattern`.
raw 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.
raw docstring

subst-syntax?clj

(subst-syntax? env)

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

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

× close