Liking cljdoc? Tell your friends :D

pattern.match.core


*disable-modes*clj


add-lengthsclj

(add-lengths)
(add-lengths a b)

all-namesclj

(all-names match-procedure)

all-valuesclj

(all-values match-procedure)

A success continuation that returns a list of values in the order the vars are defined within the pattern.

A success continuation that returns a list of values in the order the vars
are defined within the pattern.
raw docstring

and-lengthsclj

(and-lengths)
(and-lengths a b)

build-child-matchersclj

(build-child-matchers pattern comp-env)

Builds in reverse so that sequence matchers know how many elements to reserve after them, and their minimum required match size.

Matchers are returned in the original order.

Builds in reverse so that sequence matchers know how many elements to reserve
after them, and their minimum required match size.

Matchers are returned in the original order.
raw docstring

compile-patternclj

(compile-pattern pattern)
(compile-pattern pattern comp-env)

Compiles a pattern, returning a function that can be used in two different ways.

Arity 1 is the user-friendly version. Use it to match against a piece of data, returning either nil or a result map of name -> value. For example, this pattern will match an unordered multiply expression:

(let [find-unordered (compile-pattern '(* ?b (? a < ?b)))]
  (find-unordered '(* 1 2))  ;; => nil
  (find-unordered '(* 2 1))) ;; => {'b 2, 'a 1}

Experimental: Patterns may be altered and recompiled via a special call to the arity-1 matcher:

(let [p (compile-pattern '(+ 1 2 ?x))]
  (p ^::recompile (fn [orig-matcher compile pattern comp-env]
                    (compile (reverse pattern) comp-env)))
  (p '(9 2 1 +))) ;; => {x 9}

The recompile function takes 4 arguments and must have ::recompile in its metadata. This is to support progressive construction of rules. It does not facilitate rule reuse because the recompiled rules are mutated in place with the new matcher.

Compiles a pattern, returning a function that can be used in two different ways.

Arity 1 is the user-friendly version. Use it to match against a piece of data, returning
either nil or a result map of name -> value. For example, this pattern will match
an unordered multiply expression:

    (let [find-unordered (compile-pattern '(* ?b (? a < ?b)))]
      (find-unordered '(* 1 2))  ;; => nil
      (find-unordered '(* 2 1))) ;; => {'b 2, 'a 1}

Experimental: Patterns may be altered and recompiled via a special call to the
arity-1 matcher:

    (let [p (compile-pattern '(+ 1 2 ?x))]
      (p ^::recompile (fn [orig-matcher compile pattern comp-env]
                        (compile (reverse pattern) comp-env)))
      (p '(9 2 1 +))) ;; => {x 9}

The recompile function takes 4 arguments and must have ::recompile in its metadata. This is
to support progressive construction of rules. It does not facilitate rule reuse because the
recompiled rules are mutated in place with the new matcher.
raw docstring

compile-pattern*cljmultimethod

The multimethod that patterns are registered to. This function is used within pattern combinators to instantiate child patterns.

The multimethod that patterns are registered to. This function is used within pattern combinators
to instantiate child patterns.
raw docstring

compiled*-matcher?clj

(compiled*-matcher? m)

Returns true if the matcher was compiled with (compile-pattern*)

Returns true if the matcher was compiled with (compile-pattern*)
raw docstring

compiled-matcher?clj

(compiled-matcher? m)

Returns true if the matcher was compiled with (compile-pattern)

Returns true if the matcher was compiled with (compile-pattern)
raw docstring

enable-restart-pattern?clj


extend-dictclj

(extend-dict name value type abbr dict env)

lenclj

(len n)

Create a fixed-length Length object with the given min length.

Create a fixed-length Length object with the given min length.
raw docstring

lookupclj

(lookup name dict env)

match?clj

(match? pattern)
(match? pattern datum)

Like matcher but simply returns true if matched successfully.

Like [[matcher]] but simply returns true if matched successfully.
raw docstring

matcherclj

(matcher pattern)
(matcher pattern datum)

Compiles (and optionally executes) a matcher pattern.

The result is either nil if no match is made or a list of matches for each variable in the pattern in the order they are defined.

(let [find-unordered (matcher '(* ?b (? a < ?b)))] (find-unordered '(* 1 2)) ;; => nil (find-unordered '(* 2 1))) ;; => '(2 1)

This style is useful for short or simple patterns but it becomes more challenging to maintain matcher ordering between the pattern and the result as the pattern complexity increases. To instead receive a dictionary of matches, use compile-pattern instead, which returns a function that, when called with just 1 argument returns either a dictionary of matches or nil.

The compilation and execution process for this function and compile-pattern is identical.

Compiles (and optionally executes) a matcher pattern.

The result is either nil if no match is made or a list of matches for each
variable in the pattern in the order they are defined.

(let [find-unordered (matcher '(* ?b (? a < ?b)))]
  (find-unordered '(* 1 2))  ;; => nil
  (find-unordered '(* 2 1))) ;; => '(2 1)

This style is useful for short or simple patterns but it becomes more
challenging to maintain matcher ordering between the pattern and the result as
the pattern complexity increases. To instead receive a dictionary of matches,
use [[compile-pattern]] instead, which returns a function that, when called
with just 1 argument returns either a dictionary of matches or nil.

The compilation and execution process for this function and
[[compile-pattern]] is identical.
raw docstring

matcher-aliasclj


matcher-form-partsclj

(matcher-form-parts s)

If a matcher form is a symbol, return the result of matching it against a regex to extract the matcher-type parts and matcher-mode.

If a matcher form is a symbol, return the result of matching it against a
regex to extract the matcher-type parts and matcher-mode.
raw docstring

matcher-form?clj

(matcher-form? x)

Returns the matcher-type symbol for a given form if it matches a registered matcher type.

Returns the matcher-type symbol for a given form if it matches a registered
matcher type.
raw docstring

matcher-modeclj

(matcher-mode _)

Return the mode portion of the matcher, which is a string of any non-alphanumeric characters (except :) immediately after the ? characters in the matcher symbol. Examples:

?x            -> nil
?<>x          -> "<>"
??<>x         -> "<>"
(??>>> name)  -> ">>>"
Return the mode portion of the matcher, which is a string of any
non-alphanumeric characters (except :) immediately after the ? characters
in the matcher symbol. Examples:

    ?x            -> nil
    ?<>x          -> "<>"
    ??<>x         -> "<>"
    (??>>> name)  -> ">>>"
raw docstring

matcher-mode?clj

(matcher-mode? var mode)

matcher-prefixclj

(matcher-prefix _)

Return the prefix portion of the matcher which is not included in the name.

The prefix is the part of the name after the matcher-mode and before the first : character, or in a list-style matcher, it's the characters before the first : in the name.

Examples:

?x -> nil ?:x -> nil ?t:x -> "t" ?>>some-info:name -> "some-info" (? name) -> nil (? info:name) -> "info"

Return the prefix portion of the matcher which is not included in the name.

The prefix is the part of the name after the [[matcher-mode]] and before the
first `:` character, or in a list-style matcher, it's the characters before the
first `:` in the name.

Examples:

  ?x                -> nil
  ?:x               -> nil
  ?t:x              -> "t"
  ?>>some-info:name -> "some-info"
  (? name)          -> nil
  (? info:name)     -> "info"
raw docstring

matcher-typeclj

(matcher-type var)

Return the type indicator symbol for the variable if it is a matcher.

Return the type indicator symbol for the variable if it is a matcher.
raw docstring

matcher-type-for-dispatchclj

(matcher-type-for-dispatch pattern)
(matcher-type-for-dispatch pattern comp-env)

The same as matcher-type, but with aliases resolved.

The same as matcher-type, but with aliases resolved.
raw docstring

matcher-type?clj


merge-metaclj

(merge-meta map-or-maps & more)

merge-meta-keycljmultimethod


named-matcher-type?clj


named-matcher?clj

(named-matcher? x)

Returns truthy if the var is a list-style matcher type registered as named, and it has a name.

Returns truthy if the var is a list-style matcher type registered as named,
and it has a name.
raw docstring

new-envclj

(new-env succeed)

next-scopeclj

(next-scope f make-new-scope)

This mechanism supports scoping within the match dictionary for ?:fresh variables.

This mechanism supports scoping within the match dictionary for ?:fresh variables.
raw docstring

on-failureclj

(on-failure type pattern dictionary env match-length data value & more-restarts)

This is called when a pattern fails, but typically just returns nil. If a variable is marked as restartable then this provides the signalling and continuation mechanisms via the pure-conditioning library.

This is called when a pattern fails, but typically just returns nil. If a
variable is marked as restartable then this provides the signalling and
continuation mechanisms via the pure-conditioning library.
raw docstring

pattern-namesclj

(pattern-names pattern)

Return a list of all of the variable names defined in the pattern in the order the values will be returned when using matcher.

(let [find-unordered (matcher '(* ?b (? a < ?b)))]
    (pattern-names find-unordered)) ;; => (b a)

This may be either passed a pattern directly or a pattern compiled either by compile-pattern or matcher

Return a list of all of the variable names defined in the pattern in the
order the values will be returned when using [[matcher]].

    (let [find-unordered (matcher '(* ?b (? a < ?b)))]
        (pattern-names find-unordered)) ;; => (b a)

This may be either passed a pattern directly or a pattern compiled either by
[[compile-pattern]] or [[matcher]]
raw docstring

re-prefix-nameclj


register-matcherclj

(register-matcher matcher-type matcher-impl)
(register-matcher matcher-type
                  matcher-impl
                  {:keys [aliases named? restriction-position]})

Register a matcher combinator type with its compiler function.

  • matcher-type is a symbol used in a pattern to indicate the registered pattern type.

  • matcher-impl is a pattern compiler function that takes [pattern comp-env] and returns a (fn [data dictionary env]) with appropriate metadata indicating all var-names it or any of its child patterns contains together with their modes and prefixes, and the pattern length, which indicates minimum length and whether the pattern is variable length.

Optionally, you may specify:

  • aliases: additional matcher-type symbols

  • named?: true if the pattern is named within the pattern and an appropriate implementation of var-name exists

  • restriction-position: the position in the list where a restriction function may optionally be included. ie 2 in the case of (? x restr?)

Register a matcher combinator type with its compiler function.

- matcher-type is a symbol used in a pattern to indicate the registered pattern type.

- matcher-impl is a pattern compiler function that takes [pattern comp-env] and returns a
(fn [data dictionary env]) with appropriate metadata indicating all var-names it or any of
its child patterns contains together with their modes and prefixes, and the
pattern length, which indicates minimum length and whether the pattern is
variable length.

Optionally, you may specify:

- aliases: additional matcher-type symbols

- named?: true if the pattern is named within the pattern and an appropriate
implementation of var-name exists

- restriction-position: the position in the list where a restriction function
may optionally be included. ie 2 in the case of (? x restr?)
raw docstring

resolve-fnclj

(resolve-fn form fail)

Attempts to return a function for the given form:

symbol?   -> resolve the symbol in the global scope
(apply x) -> recursively resolve x and return (partial apply x)
ifn?      -> return the value literally. Works for function, keyword, map, set, etc.

If the result is not resolved to ifn? then call (fail)

Attempts to return a function for the given form:

    symbol?   -> resolve the symbol in the global scope
    (apply x) -> recursively resolve x and return (partial apply x)
    ifn?      -> return the value literally. Works for function, keyword, map, set, etc.

If the result is not resolved to `ifn?` then call `(fail)`
raw docstring

resolver-eval-whitelistclj

If the first symbol in the form in a matcher predicate can be resolved to a var in this list, then that form will be eval'd.

For example: (? x (every-pred float? pos?)) will eval the predicate by default because #'every-pred is in this list by default.

A special case is 'fn* which can't be resolved but may be eval'd, so it is present as a symbol here.

If the first symbol in the form in a matcher predicate can be resolved to a
var in this list, then that form will be eval'd.

For example: (? x (every-pred float? pos?)) will eval the predicate by default
because #'every-pred is in this list by default.

A special case is 'fn* which can't be resolved but may be eval'd, so it is
present as a symbol here.
raw docstring

restartable?clj

(restartable? pattern)

restriction-positionclj


run-matcherclj

(run-matcher match-procedure datum succeed)

Run the given matcher on the given datum, calling succeed with the match dictionary if the matcher pattern.

The dictionary is structured var-name -> {:name var-name :value matched-value :type matcher-type}

Run the given matcher on the given datum, calling succeed with the match
dictionary if the matcher pattern.

The dictionary is structured var-name -> {:name var-name
                                          :value matched-value
                                          :type matcher-type}
raw docstring

sequence-extend-dictclj

(sequence-extend-dict name value type abbr dict env)

Special version of extend-dict installed in the env when processing a sequence.

Special version of extend-dict installed in the env when processing a sequence.
raw docstring

sequence-lookupclj

(sequence-lookup name dict env)

Special version of lookup installed in the env when processing a sequence.

Special version of lookup installed in the env when processing a sequence.
raw docstring

simple-named-var?clj

(simple-named-var? x)

Returns a truthy value if x is a symbol starting with some number of ?'s followed by some other character, indicating a non-list variable.

Returns a truthy value if x is a symbol starting with some number of ?'s
followed by some other character, indicating a non-list variable.
raw docstring

simple-ref?clj

(simple-ref? x)

Returns a truthy value if x is a symbol starting with $, indicating a ref insertion.

Returns a truthy value if x is a symbol starting with $, indicating a ref insertion.
raw docstring

symbol-dictclj

(symbol-dict match-procedure)

A success continuation that creates a simple dictionary of 'name -> value from the full match dictionary.

A success continuation that creates a simple dictionary of 'name -> value from
the full match dictionary.
raw docstring

unregister-matcherclj

(unregister-matcher matcher-type)

value-dictclj

(value-dict match-procedure)

A success continuation that creates a simple dictionary of :name -> value from the full match dictionary.

Converts symbol names to keywords.

A success continuation that creates a simple dictionary of :name -> value from
the full match dictionary.

Converts symbol names to keywords.
raw docstring

var-keyclj

(var-key name env)

var-lenclj

(var-len n)

Create a variable-length Length object with the given min length.

Create a variable-length Length object with the given min length.
raw docstring

var-nameclj

(var-name var)

var-restrictionclj

(var-restriction var comp-env)

Returns a function that takes a potential match value and returns true if the value is valid for the var

Returns a function that takes a potential match value and returns true if the
value is valid for the var
raw docstring

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

× close