API for the expr module of formform.
API for the `expr` module of `formform`.
(defoperator k args interpretation & params)Defines a new operator by its symbol (a keyword), a vector of arguments and an interpretation function. Takes additional key-value pairs for options.
Registers various methods for the operator:
interpret-op to access the interpretation functionmake-op -> constructor (either uses the provided args or a custom constructor function via the option :constructor)simplify-op -> simplifier (either defaults to the given interpretation function or uses a custom reducer via the option :reducer)valid-op? -> validator (provided by the :predicate option)op-data -> returns a key-value map of the operator argumentsop-get -> returns a specific value by a given argument-keyDefines a new operator by its symbol (a keyword), a vector of arguments and an interpretation function. Takes additional key-value pairs for options. Registers various methods for the operator: * `interpret-op` to access the interpretation function * `make-op` -> constructor (either uses the provided `args` or a custom constructor function via the option `:constructor`) * `simplify-op` -> simplifier (either defaults to the given interpretation function or uses a custom reducer via the option `:reducer`) * `valid-op?` -> validator (provided by the `:predicate` option) * `op-data` -> returns a key-value map of the operator arguments * `op-get` -> returns a specific value by a given argument-key
(defsymbol k interpretation & params)Defines a new expression symbol by its symbol (a keyword) and an interpretation function. Takes additional key-value pairs for options.
Registers various methods for the expression symbol:
interpret-sym -> to access the interpretation functionsimplify-sym -> simplifier (either defaults to the given interpretation function or uses a custom reducer via the option :reducer)Defines a new expression symbol by its symbol (a keyword) and an interpretation function. Takes additional key-value pairs for options. Registers various methods for the expression symbol: * `interpret-sym` -> to access the interpretation function * `simplify-sym` -> simplifier (either defaults to the given interpretation function or uses a custom reducer via the option `:reducer`)
(equal & exprs)Equality check for expressions. Two expressions are considered equal, if their formDNAs are equal. Compares formDNAs from evaluation results of each expression by calling calc/equal-dna.
find-varsequiv, which compares by calc/equiv-dnaEquality check for expressions. Two expressions are considered equal, if their formDNAs are equal. Compares formDNAs from evaluation results of each expression by calling `calc/equal-dna`. * ordering of variable names in formDNA matters, see `find-vars` * stricter than `equiv`, which compares by `calc/equiv-dna`
(equiv & exprs)Equivalence check for expressions. Two expressions are considered equivalent, if their formDNAs are equivalent. Compares formDNAs from evaluation results of each expression by calling calc/equiv-dna.
equal, which compares by calc/equal-dnaEquivalence check for expressions. Two expressions are considered equivalent, if their formDNAs are equivalent. Compares formDNAs from evaluation results of each expression by calling `calc/equiv-dna`. * ordering of variable names in formDNA is irrelevant * looser than `equal`, which compares by `calc/equal-dna` * can be slow on expressions with 6+ variables
(eval->expr expr)(eval->expr expr env)Evaluates a FORM expression with an optional env and returns a constant expression with attached metadata including the maximally reduced expression in :expr and the environment in :env.
env must be a map with a content/variable in expr as a keyEvaluates a FORM expression with an optional `env` and returns a constant expression with attached metadata including the maximally reduced expression in `:expr` and the environment in `:env`. * `env` must be a map with a content/variable in `expr` as a key
(eval->expr-all expr)(eval->expr-all expr env)(eval->expr-all opts expr env)Evaluates a FORM expression for all possible interpretations of any occurring variable in the expression. Returns a formDNA expression by default.
to-fdna? is false, returns a seq of results as returned by => in the order of the corresponding vspace orderingEvaluates a FORM expression for all possible interpretations of any occurring variable in the expression. Returns a formDNA expression by default. * if `to-fdna?` is false, returns a seq of results as returned by `=>` in the order of the corresponding `vspace` ordering
(eval-all expr)(eval-all expr env)(eval-all opts expr env)Evaluates a FORM expresson for all possible interpretations of any occurring variable in the expresson. Returns a map with a :results key whose value is a sequence of [<interpretation> <result>] tuples and with a :varorder key whose value is the reading order for variable results in the interpretations. This output is particularly suited for value tables.
Evaluates a FORM expresson for all possible interpretations of any occurring variable in the expresson. Returns a map with a `:results` key whose value is a sequence of `[<interpretation> <result>]` tuples and with a `:varorder` key whose value is the reading order for variable results in the interpretations. This output is particularly suited for value tables.
(evaluate expr)(evaluate expr env)Evaluates a FORM expresson with an optional env and returns either a constant or the simplified expression if it could not be determined to a value.
Evaluates a FORM expresson with an optional `env` and returns either a constant or the simplified expression if it could not be determined to a value.
(expr->const expr)Given an expression, returns the corresponding constant value.
Given an expression, returns the corresponding constant value.
(find-subexprs expr subexprs)Finds all subexpressions in expr that match any element of the given set subexprs.
Finds all subexpressions in `expr` that match any element of the given set `subexprs`.
(find-vars expr opts)Finds all variables in an expresson or returns the expression itself if it is a variable.
Options:
Finds all variables in an expresson or returns the expression itself if it is a variable.
Options:
* {:ordered true} to return variables in: type order -> alphanumeric order
* {:vars #{…}} can be given a set of specific variables to find(form & args)Constructor for FORM expressions. Calls make on arguments.
Constructor for FORM expressions. Calls `make` on arguments.
(gen-vars n)Generates a number of variables with random names.
Generates a number of variables with random names.
(interpret expr)(interpret env expr)Interprets an expression of any kind. Returns the original expression if it cannot be interpreted.
Can be given an env map to interpret variables (as keys). This map can have an optional --defocus entry whose value is a set of items that should not be interpreted and a complementary --focus entry to only interpret the items specified in its set and nothing else.
:ops / :syms / :vars designate all operations / expression symbols / variables--focus and --defocus can cancel each other out if they contain the same item so you usually pick one or the otherInterprets an expression of any kind. Returns the original expression if it cannot be interpreted. Can be given an `env` map to interpret variables (as keys). This map can have an optional `--defocus` entry whose value is a set of items that should not be interpreted and a complementary `--focus` entry to only interpret the items specified in its set and nothing else. * the keywords `:ops` / `:syms` / `:vars` designate _all_ operations / expression symbols / variables * an operator symbol can provided to designate a specific operator * any other expression (like a variable) can be designated as itself * `--focus` and `--defocus` can cancel each other out if they contain the same item so you usually pick one or the other
(interpret* expr)(interpret* env expr)Like interpret, but repeats substitution on interpreted expressions until they cannot be interpreted any further.
Like `interpret`, but repeats substitution on interpreted expressions until they cannot be interpreted any further.
Interprets a symbolic expression with a registered operator.
Note: default to use interpret instead
Interprets a symbolic expression with a registered operator. Note: default to use `interpret` instead
Interprets a registered symbol.
Note: default to use interpret instead
Interprets a registered symbol. Note: default to use `interpret` instead
(interpret-walk expr)(interpret-walk env expr)Recursively calls interpret on given expression and all its subexpressions with a depth-first walk.
Recursively calls `interpret` on given expression and all its subexpressions with a depth-first walk.
(interpret-walk* expr)(interpret-walk* env expr)Like interpret-walk, but repeats substitution on interpreted (sub-)expressions until they cannot be interpreted any further.
Like `interpret-walk`, but repeats substitution on interpreted (sub-)expressions until they cannot be interpreted any further.
(isolator c)Given a constant, returns the corresponding FORM from the isolator class.
Given a constant, returns the corresponding FORM from the isolator class.
(make & args)Constructor for expressions of any kind. Validates its input. If the first argument (or the first after the options map) is a keyword of a registered operator, will call the constructor for that operator
Can be given an options map as first argument:
mark? (default: false) marks the whole expression, creating a FORMsplice? (default: true) dissolves all top-level arrangementsConstructor for expressions of any kind. Validates its input. If the first argument (or the first after the options map) is a keyword of a registered operator, will call the constructor for that operator Can be given an options map as first argument: * `mark?` (default: false) marks the whole expression, creating a FORM * `splice?` (default: true) dissolves all top-level arrangements
Constructs a symbolic expression given a registered operator and parameters.
Note: default to use make instead of make-op
Constructs a symbolic expression given a registered operator and parameters. Note: default to use `make` instead of `make-op`
(mark-exprs opts & exprs)Chains expressions like ((a)(b)…) or (a)(b)… if {:unmarked? true}`
[:- x y …]Chains expressions like `((a)(b)…)` or `(a)(b)…` if {:unmarked? true}`
* group expressions with arrangements: `[:- x y …]`(memory rem-pairs & exprs)Constructs a memory FORM from a given list of rem-pairs (key-value pairs, where both the key and the value is an expression) and one or more expressions which are in their scope.
Constructs a memory FORM from a given list of `rem-pair`s (key-value pairs, where both the key and the value is an expression) and one or more expressions which are in their scope.
(memory-extend mem & ext-pairs)Takes a memory FORM and extends its rem-pairs by one or more given extension pairs.
Takes a memory FORM and extends its `rem-pair`s by one or more given extension pairs.
(memory-replace mem & repl-pairs)Takes a memory FORM and replaces its rem-pairs by one or more given replacement pairs.
Takes a memory FORM and replaces its `rem-pair`s by one or more given replacement pairs.
(nest-exprs opts & exprs)Nests expressions leftwards (((…)a)b) or rightwards (a(b(…))) if {:ltr? true}
nil for empty expressions(make x y …) to add multiple exprs. to the same levelNests expressions leftwards `(((…)a)b)` or rightwards `(a(b(…)))` if `{:ltr? true}`
* use `nil` for empty expressions
* use an arrangement `(make x y …)` to add multiple exprs. to the same levelGets all parameters from a symbolic expression with a registered operator as a map.
Gets all parameters from a symbolic expression with a registered operator as a map.
Gets a specified part from a symbolic expression with a registered operator.
Gets a specified part from a symbolic expression with a registered operator.
Returns the symbol of a given operator.
Returns the symbol of a given operator.
(selector vars->consts)(selector vars->consts simplify?)Given a map variable->constant, returns a FORM from the selector class.
Given a map variable->constant, returns a FORM from the selector class.
(seq-re specs & nested-exprs)Constructs a self-equivalent re-entry FORM given the arguments:
specs: either a seq-reentry-signature or an options mapnested-exprs: zero or more expressions intended as a nested sequenceConstructs a self-equivalent re-entry FORM given the arguments: * `specs`: either a `seq-reentry-signature` or an options map * `nested-exprs`: zero or more expressions intended as a nested sequence
(seq-reentry-opts->sign opt-map)Inverse map of seq-reentry-sign->opts with default args.
Inverse map of seq-reentry-sign->opts with default args.
(seq-reentry-sign->opts sign)Maps signatures for self-equivalent re-entry FORMs to their corresponding option-maps.
Maps signatures for self-equivalent re-entry FORMs to their corresponding option-maps.
(simplify x)(simplify x env)Simplifies a FORM recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic.
x is a complex FORM, calls simplify-context on xenvx as isSimplifies a FORM recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic. * if `x` is a complex FORM, calls `simplify-context` on `x` * if no simplification applies, tries to retrieve the value from given `env` * if retrieval was unsuccessful, returns `x` as is
(simplify-expr-chain chain env)(simplify-expr-chain opts chain env)Reduces a sequence of expressions, intended to be linked in a chain, to a sequence of simplified expressions, possibly spliced or shortened via inference.
(…(…(…)))(((…)…)…), pass {:rtl? true}Reduces a sequence of expressions, intended to be linked in a `chain`, to a sequence of simplified expressions, possibly spliced or shortened via inference.
* assumes rightward-nesting, e.g. `(…(…(…)))`
* for leftward-nesting, e.g. `(((…)…)…)`, pass `{:rtl? true}`(simplify-in ctx)(simplify-in ctx env)Simplifies a context/sequence of FORMs recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic.
expr.core/simplify-content on every unique elementSimplifies a context/sequence of FORMs recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic. * for complex expressions, calls `expr.core/simplify-content` on every unique element
Simplifies a symbolic expression with a registered operator given an optional environment.
Note: default to use simplify instead
Simplifies a symbolic expression with a registered operator given an optional environment. Note: default to use `simplify` instead
Simplifies a registered symbol given an optional environment.
Note: default to use simplify instead
Simplifies a registered symbol given an optional environment. Note: default to use `simplify` instead
Validates the shape of a symbolic expression with a registered operator.
Validates the shape of a symbolic expression with a registered operator.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs | 
| ← | Move to previous article | 
| → | Move to next article | 
| Ctrl+/ | Jump to the search field |