Liking cljdoc? Tell your friends :D

Patterns

Patterns consist of literals and/or wildcards.

They are matched recursively: [$] matches [[1]] twice; once on [[1]] and once on [1].

Literals

literals are matched, well, literally. Like in a regular expression, they match their own representation.

Wildcards

$

$ matches any expression.

Examples:

  • $ matches literal like 42 but also more complex expressions like (do (println "foo") (update my-map :foo inc)).
  • [$] matches vectors of one single element.

$&

$& matches any number of expressions, including zero.

There can be only one $& per sequence of expressions (contiguous $&s are equivalent to one $&).

$type

$type is an equivalent to $ with a constraint on the literal type. It matches any expression with the given type. See the table below for a description of the available types:

PatternDescriptionExample expressions
$backticka backtick-ed expression`foo
$charactera character\space, \a
$conditional-splicinga reader splicing conditional#?@(:cljs nil)
$conditionala reader conditional#?(:cljs nil)
$derefa dereferenced expression using @@foo
$fnan anonymous function#(do %)
$keyworda keyword:foo
$lista list(f 2 3)
$macro-keyworda keyword defined with ::::foo
$mapa map{}
$metadataa metadata-tagged expression^:private my-sym
$numbera number (int or float)42, 3.14
$quotea quoted expression'foo
$regexa regular expression#"foo"
$seta set#{}
$stringa string"foo"
$symbola symbolfoo, foo/bar, clojure.string/trim
$symbolica special symbol such as ##NaN or ##Inf##Inf
$unquote-splicinga splice-unquoted expression~@foo
$unquotean unquoted expression~foo
$var-quote #'foo
$vectora vector[]

This list is based on Parcera’s grammar, except that underscores are replaced with dashes.

Note: when matching collections you can have a better control over their content by using literals: $vector matches any vector, while [] matches empty vectors and [$ $ $] matches vectors of exactly 3 elements. These can of course be combined: [$ $number $ $regex] matches all 4-elements vectors where the second one is a number and the fourth and last one a regular expression.

Can you improve this documentation?Edit on GitHub

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

× close