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.

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

gatherclj

(gather pattern)
(gather pattern count-pattern)

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)

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"]

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]
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"]

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

letclj

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

matchclj/smacro

(match x & clauses)

Traditional 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.

Traditional 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`.
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 & clauses)

Syntactic sugar for

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

Syntactic sugar for

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

rewritesclj/smacro

(rewrites x & clauses)

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 patterns which may match x in more than one way. Returns a lazy sequence of expression values in depth-first order.

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 ,,,)
Like `match` but allows for patterns which may match `x` in more
than one way. Returns a lazy sequence of expression values in
depth-first order.

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 ,,,)
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

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

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)

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"]

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]
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"]

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