(add-lengths)
(add-lengths a b)
(all-names match-procedure)
(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.
(and-lengths)
(and-lengths a b)
(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.
(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.
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.
(compiled*-matcher? m)
Returns true if the matcher was compiled with (compile-pattern*)
Returns true if the matcher was compiled with (compile-pattern*)
(compiled-matcher? m)
Returns true if the matcher was compiled with (compile-pattern)
Returns true if the matcher was compiled with (compile-pattern)
(extend-dict name value type abbr dict env)
(len n)
Create a fixed-length Length object with the given min length.
Create a fixed-length Length object with the given min length.
(lookup name dict env)
(match? pattern)
(match? pattern datum)
Like matcher
but simply returns true if matched successfully.
Like [[matcher]] but simply returns true if matched successfully.
(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.
(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.
(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.
(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) -> ">>>"
(matcher-mode? var mode)
(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"
(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.
(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.
(merge-meta map-or-maps & more)
(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.
(new-env succeed)
(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.
(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.
(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]]
(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?)
(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)`
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.
(restartable? pattern)
(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}
(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.
(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.
(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.
(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.
(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.
(unregister-matcher matcher-type)
(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.
(var-key name env)
(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.
(var-name var)
(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
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close