API for the expr module of formform.
expression
→ interpret the representation as an indicator of a value
variable
→ the interpretation of the expression symbol is undetermined
form expression {FORM}
→ expression of form
→ invert the value of the relation
symbolic expression
→ expression symbol or operator
expression symbol
→ interpret the symbol as a specific expression
operator
→ interpret the structure by its symbol as an expression pattern
arrangement {:-}
→ operator to construct relations
unclear FORM {:uncl}
→ operator to construct unclear FORMs
seq-reentry FORM {:seq-re}
→ operator to construct self-equivalent re-entry FORMs
memory FORM {:mem}
→ operator to construct memory FORMs
formDNA {:fdna}
→ operator to construct calc/formDNA expressions
API for the `expr` module of `formform`.
## Concepts
### Basic Expressions
**expression**
→ interpret the _representation_ as an indicator of a _value_
* _representation_ → _form_ {syntax} and intentionality {semantics}
* _form_ → relate structure and code
* _value_ → _calc/value_
* _value_ → _calc/constant_ {determined} or _formDNA_ {contingent}
**variable**
→ the interpretation of the _expression symbol_ is undetermined
**form expression** {FORM}
→ _expression_ of _form_
→ invert the _value_ of the _relation_
* _relation_ → relate the _values_ of the content of the _expression_
### Symbolic Expressions
**symbolic expression**
→ _expression symbol_ or _operator_
**expression symbol**
→ interpret the symbol as a specific _expression_
**operator**
→ interpret the structure by its symbol as an _expression_ pattern
#### Types
**arrangement** {`:-`}
→ _operator_ to construct _relations_
**unclear FORM** {`:uncl`}
→ _operator_ to construct unclear _FORMs_
**seq-reentry FORM** {`:seq-re`}
→ _operator_ to construct self-equivalent re-entry _FORMs_
**memory FORM** {`:mem`}
→ _operator_ to construct memory _FORMs_
* _rem pair_ → observe and remember equality between the two expressions
**formDNA** {`:fdna`}
→ _operator_ to construct _calc/formDNA_ _expressions_
Obsolete → use nested-l>> or nested-r>> instead!
Obsolete → use [[nested-l>>]] or [[nested-r>>]] instead!
(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 (use interpret) to access the interpretation functionmake-op (use make) → constructor (either uses the provided args or a custom constructor function via the option :constructor)simplify-op (use simplify) → 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` (use [[interpret]]) to access the interpretation function * `make-op` (use [[make]]) → constructor (either uses the provided `args` or a custom constructor function via the option `:constructor`) * `simplify-op` (use [[simplify]]) → 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:
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` (use [[interpret]]) → to access the interpretation function * `simplify-sym` (use [[simplify]]) → 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?.
WARNING: Procedure and assumptions are being reassessed. Use with caution!
find-varscalc/equiv-dna?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?]]. WARNING: Procedure and assumptions are being reassessed. Use with caution! * 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?.
WARNING: Procedure and assumptions are being reassessed. Use with caution!
calc/equal-dna?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?]]. WARNING: Procedure and assumptions are being reassessed. Use with caution! * 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 expr with an optional env and returns an expression: either a constant or the simplified input expression, if it could not be determined to a value.
env must be a map from variables to expressionsEvaluates a FORM `expr` with an optional `env` and returns an expression: either a constant or the simplified input expression, if it could not be determined to a value. * `env` must be a map from variables to expressions
(eval->expr-all expr)(eval->expr-all expr env)(eval->expr-all expr env opts)Like eval->expr, but evaluates all possible interpretations of any occurring variable in the expr. Returns an expression: either a constant, a formDNA expression (which collects all interpretation results) or the simplified input expression, if it could not be determined to a value in any of its interpretations.
env must be a map from variables to expressionsAn opts map can be provided with the following keys:
:varorder → sets the variable interpretation order for the resulting formDNA:pre-simplify? → (default: true) simplifies the expression before interpretation, which might reduce terms and therefore evaluation time:reduce-dna? → (default: true) if result is a formDNA expression which can be reduced to fewer terms, reduces it to further simplify the output:allow-hole-results? → (default: false) sets a “value hole” (:_) in place of an uninterpretable result:allow-hole-exprs? → (default: false) allows “value holes” (:_) in the input expression (each instance will be treated like a different variable)Like [[eval->expr]], but evaluates all possible interpretations of any occurring variable in the `expr`. Returns an expression: either a constant, a formDNA expression (which collects all interpretation results) or the simplified input expression, if it could not be determined to a value in any of its interpretations. * `env` must be a map from variables to expressions An `opts` map can be provided with the following keys: * `:varorder` → sets the variable interpretation order for the resulting formDNA * `:pre-simplify?` → (default: `true`) simplifies the expression before interpretation, which might reduce terms and therefore evaluation time * `:reduce-dna?` → (default: `true`) if result is a formDNA expression which can be reduced to fewer terms, reduces it to further simplify the output * `:allow-hole-results?` → (default: `false`) sets a “value hole” (`:_`) in place of an uninterpretable result * `:allow-hole-exprs?` → (default: `false`) allows “value holes” (`:_`) in the input expression (each instance will be treated like a different variable)
(eval->val expr)(eval->val expr env)Evaluates a FORM expr with an optional env and returns a value: either a constant or a “value hole” :_ (in case a value cannot be determined, which usually happens when variables remain uninterpreted).
env must be a map from variables to expressionsEvaluates a FORM `expr` with an optional `env` and returns a value: either a constant or a “value hole” `:_` (in case a value cannot be determined, which usually happens when variables remain uninterpreted). * `env` must be a map from variables to expressions
(eval->val-all expr)(eval->val-all expr env)(eval->val-all expr env opts)Like eval->val, but evaluates all possible interpretations of any occurring variable in the expr. Returns a complex value called formDNA, which collects all interpretation results.
env must be a map from variables to expressionsNote: interpretation results might (in very rare cases) include “value holes” :_, if a value cannot be determined. This applies to unregistered symbols (like :pie) or uninterpretable results from custom, user-defined operators. To avoid holes, wrap them in unclear FORMs, e.g. (make :uncl :pie).
An opts map can be provided with the following keys:
:varorder → sets the variable interpretation order for the resulting formDNA:pre-simplify? → (default: false) simplifies the expression before interpretation, which might reduce terms and therefore evaluation time:reduce-dna? → (default: false) if result is a formDNA expression which can be reduced to fewer terms, reduces it to further simplify the output:allow-hole-exprs? → (default: false) allows “value holes” (:_) in the input expression (each instance will be treated like a different variable)Like [[eval->val]], but evaluates all possible interpretations of any occurring variable in the `expr`. Returns a complex value called formDNA, which collects all interpretation results. * `env` must be a map from variables to expressions Note: interpretation results might (in very rare cases) include “value holes” `:_`, if a value cannot be determined. This applies to unregistered symbols (like `:pie`) or uninterpretable results from custom, user-defined operators. To avoid holes, wrap them in unclear FORMs, e.g. `(make :uncl :pie)`. An `opts` map can be provided with the following keys: * `:varorder` → sets the variable interpretation order for the resulting formDNA * `:pre-simplify?` → (default: `false`) simplifies the expression before interpretation, which might reduce terms and therefore evaluation time * `:reduce-dna?` → (default: `false`) if result is a formDNA expression which can be reduced to fewer terms, reduces it to further simplify the output * `:allow-hole-exprs?` → (default: `false`) allows “value holes” (`:_`) in the input expression (each instance will be treated like a different variable)
(eval-all expr)(eval-all expr env)(eval-all expr env opts)Like evaluate, but evaluates all possible interpretations of any occurring variable in the expr, with an optional env.
env must be a map from variables to expressionsReturns a map with the following entries:
:results → vector of [<interpretation> <result>] tuples (with result like in evaluate), think of it as a kind of value table:varorder → the reading order of variable interpretationsAn opts map can be provided with the following keys:
:varorder → sets the variable interpretation order for the results:rich-results? → each results value will be a map as if returned by evaluate:pre-simplify? → (default: false) simplifies the expression before interpretation, which might reduce terms and therefore evaluation time:allow-hole-results? → (default: false) sets a “value hole” (:_) in place of nil for an uninterpretable result:allow-hole-exprs? → (default: false) allows “value holes” (:_) in the input expression (each instance will be treated like a different variable)Like [[evaluate]], but evaluates all possible interpretations of any occurring variable in the `expr`, with an optional `env`. * `env` must be a map from variables to expressions Returns a map with the following entries: * `:results` → vector of `[<interpretation> <result>]` tuples (with `result` like in `evaluate`), think of it as a kind of value table * `:varorder` → the reading order of variable interpretations An `opts` map can be provided with the following keys: * `:varorder` → sets the variable interpretation order for the results * `:rich-results?` → each results value will be a map as if returned by [[evaluate]] * `:pre-simplify?` → (default: `false`) simplifies the expression before interpretation, which might reduce terms and therefore evaluation time * `:allow-hole-results?` → (default: `false`) sets a “value hole” (`:_`) in place of `nil` for an uninterpretable result * `:allow-hole-exprs?` → (default: `false`) allows “value holes” (`:_`) in the input expression (each instance will be treated like a different variable)
(eval-tsds->val-all & selection)Convenience function that takes a 6-digit binary selection (as a vector) for a triple-selective decision system (TsDS) and returns the formDNA for the (as by eval->val-all) evaluated expression.
Note: contrary to eval->val-all, the resulting formDNA does not get reduced.
Convenience function that takes a 6-digit binary `selection` (as a vector) for a triple-selective decision system (TsDS) and returns the formDNA for the (as by [[eval->val-all]]) evaluated expression. Note: contrary to [[eval->val-all]], the resulting formDNA does not get reduced.
(evaluate expr)(evaluate expr env)Evaluates a FORM expr with an optional env and returns a map with a :result entry that is either a constant or nil, if it could not be determined to a value. It also contains a :simplified entry with the simplified expression.
env must be a map from variables to expressionsEvaluates a FORM `expr` with an optional `env` and returns a map with a `:result` entry that is either a constant or `nil`, if it could not be determined to a value. It also contains a `:simplified` entry with the simplified expression. * `env` must be a map from variables to expressions
(expr->const expr)Returns the constant value/expression that corresponds to its simplest (as per simplify) input expr (including itself):
nil → :n
[] → :m
[:seq-re :<r nil nil] → :u
[[:seq-re :<r nil nil]] → :i
[:u] → :i
Returns the constant value/expression that corresponds to its simplest (as per [[simplify]]) input `expr` (including itself): ``` nil → :n [] → :m [:seq-re :<r nil nil] → :u [[:seq-re :<r nil nil]] → :i [:u] → :i ```
(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:
{:ordered true} to return variables in: type order → alphanumeric order{:vars #{…}} can be given a set of specific variables to findFinds 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 args.
Constructor for FORM expressions `[ … ]`. Calls [[make]] on `args`.
(form-marked & exprs)Returns a FORM with each exprs argument marked, e.g. ((a) (b) …).
(make x y …)Returns a FORM with each `exprs` argument marked, e.g. `((a) (b) …)`. * group expressions with arrangements: `(make x y …)`
(form-nested-l & exprs)Nests exprs leftwards in a FORM, e.g. ((((…) y) z).
nil for empty expressions(make x y …) to add multiple exprs. to the same levelNests `exprs` leftwards in a FORM, e.g. `((((…) y) z)`. * use `nil` for empty expressions * use an arrangement `(make x y …)` to add multiple exprs. to the same level
(form-nested-r & exprs)Nests exprs rightwards in a FORM, e.g. (a (b (…))).
nil for empty expressions(make x y …) to add multiple exprs. to the same levelNests `exprs` rightwards in a FORM, e.g. `(a (b (…)))`. * use `nil` for empty expressions * use an arrangement `(make x y …)` to add multiple exprs. to the same level
(formDNA-perspectives fdna)Takes a formDNA expression and returns its formDNA perspective group.
Takes a formDNA expression and returns its formDNA perspective group.
(gen-vars n)Generates a number of variables with random names.
Generates a number of variables with random names.
(interpret expr)(interpret expr env)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* expr env)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 expr env)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* expr env)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
(make-marked & exprs)Returns an arrangement with each exprs argument marked, e.g. (a) (b) ….
(make x y …)Returns an arrangement with each `exprs` argument marked, e.g. `(a) (b) …`. * group expressions with arrangements: `(make x y …)`
(make-nested-l & exprs)Nests exprs leftwards in an arrangement, e.g. ((…) y) z.
nil for empty expressions(make x y …) to add multiple exprs. to the same levelNests `exprs` leftwards in an arrangement, e.g. `((…) y) z`. * use `nil` for empty expressions * use an arrangement `(make x y …)` to add multiple exprs. to the same level
(make-nested-r & exprs)Nests exprs rightwards in an arrangement, e.g. a (b (…)).
nil for empty expressions(make x y …) to add multiple exprs. to the same levelNests `exprs` rightwards in an arrangement, e.g. `a (b (…))`. * use `nil` for empty expressions * use an arrangement `(make x y …)` to add multiple exprs. to the same level
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)Obsolete → use make-marked or form-marked instead.
Obsolete → use [[make-marked]] or [[form-marked]] instead.
(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)Obsolete → use make-nested-l/make-nested-r or form-nested-l/form-nested-r instead.
Obsolete → use [[make-nested-l]]/[[make-nested-r]] or [[form-nested-l]]/[[form-nested-r]] instead.
Gets 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.
(permute-vars varorder)Generates all permutations of a variable order (a sequence of variables).
Generates all permutations of a variable order (a sequence of variables).
(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)(simplify x env opts)Simplifies a FORM recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic.
envx as isAn opts map can be provided with the following keys:
:allow-hole-exprs? → (default: false) allows “value holes” (:_) in the input expression (each instance will be treated like a different variable)Simplifies a FORM recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic. * if no simplification applies, tries to retrieve the value from given `env` * if retrieval was unsuccessful, returns `x` as is An `opts` map can be provided with the following keys: * `:allow-hole-exprs?` → (default: `false`) allows “value holes” (`:_`) in the input expression (each instance will be treated like a different variable)
(simplify-expr-chain chain env)(simplify-expr-chain opts chain env)Obsolete → use simplify-nested-l or simplify-nested-r instead!
Obsolete → use [[simplify-nested-l]] or [[simplify-nested-r]] instead!
(simplify-in ctx)(simplify-in ctx env)(simplify-in ctx env opts)Simplifies a context/sequence of FORMs recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic.
An opts map can be provided with the following keys:
:allow-hole-exprs? → (default: false) allows “value holes” (:_) in the input expression (each instance will be treated like a different variable)Simplifies a context/sequence of FORMs recursively until it cannot be further simplified. All deductions are justified by the axioms of FORM logic. An `opts` map can be provided with the following keys: * `:allow-hole-exprs?` → (default: `false`) allows “value holes” (`:_`) in the input expression (each instance will be treated like a different variable)
(simplify-nested-l nesting-chain)(simplify-nested-l nesting-chain env)(simplify-nested-l nesting-chain env opts)Reduces a leftward nesting-chain, a sequence of expressions ( … x y z ) whose interpretation is ( [[[…] x] y] z ), to a simplified nesting chain, possibly spliced or shortened via inference.
env that gets applied to the nested expansionAn opts map can be provided with the following keys:
:allow-hole-exprs? → (default: false) allows “value holes” (:_) in the input expression (each instance will be treated like a different variable)Reduces a leftward `nesting-chain`, a sequence of expressions `( … x y z )` whose interpretation is `( [[[…] x] y] z )`, to a simplified nesting chain, possibly spliced or shortened via inference. * takes an optional `env` that gets applied to the nested expansion An `opts` map can be provided with the following keys: * `:allow-hole-exprs?` → (default: `false`) allows “value holes” (`:_`) in the input expression (each instance will be treated like a different variable)
(simplify-nested-r nesting-chain)(simplify-nested-r nesting-chain env)(simplify-nested-r nesting-chain env opts)Reduces a rightward nesting-chain, a sequence of expressions ( a b c … ) whose interpretation is ( a [b [c […]]] ), to a simplified nesting chain, possibly spliced or shortened via inference.
env that gets applied to the nested expansionAn opts map can be provided with the following keys:
:allow-hole-exprs? → (default: false) allows “value holes” (:_) in the input expression (each instance will be treated like a different variable)Reduces a rightward `nesting-chain`, a sequence of expressions `( a b c … )` whose interpretation is `( a [b [c […]]] )`, to a simplified nesting chain, possibly spliced or shortened via inference. * takes an optional `env` that gets applied to the nested expansion An `opts` map can be provided with the following keys: * `:allow-hole-exprs?` → (default: `false`) allows “value holes” (`:_`) in the input expression (each instance will be treated like a different variable)
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 |