This namespace implements subexpression extraction and "elimination", the process we use to avoid redundant computation inside of a simplified function body.
This namespace implements subexpression extraction and "elimination", the process we use to avoid redundant computation inside of a simplified function body.
(extract-common-subexpressions expr continue)
(extract-common-subexpressions expr
continue
{:keys [gensym-fn deterministic?]
:or {gensym-fn
(a/monotonic-symbol-generator 8 "_")}})
Considers an S-expression from the point of view of optimizing its evaluation by isolating common subexpressions into auxiliary variables.
Accepts:
expr
continue
of two arguments:
[aux variable, subexpression]
used to reconstitute the
value.Calls the continuation at completion and returns the continuation's value.
:gensym-fn
: side-effecting function that returns a new, unique
variable name prefixed by its argument on each invocation.
monotonic-symbol-generator
by default.
NOTE that the symbols should appear in sorted order! Otherwise we can't
guarantee that the binding sequence passed to continue
won't contain entries
that reference previous entries.
:deterministic?
: if true, the function will assign aux variables by sorting
the string representations of each term before assignment. Otherwise, the
nondeterministic order of hash maps inside this function won't guarantee a
consistent variable naming convention in the returned function. For tests, set
:deterministic? true
.
Considers an S-expression from the point of view of optimizing its evaluation by isolating common subexpressions into auxiliary variables. Accepts: - A symbolic expression `expr` - a continuation fn `continue` of two arguments: - a new equivalent expression with possibly some subexpressions replaced by new variables (delivered by the supplied generator, see below) - a seq of pairs of `[aux variable, subexpression]` used to reconstitute the value. Calls the continuation at completion and returns the continuation's value. ### Optional Arguments `:gensym-fn`: side-effecting function that returns a new, unique variable name prefixed by its argument on each invocation. `monotonic-symbol-generator` by default. NOTE that the symbols should appear in sorted order! Otherwise we can't guarantee that the binding sequence passed to `continue` won't contain entries that reference previous entries. `:deterministic?`: if true, the function will assign aux variables by sorting the string representations of each term before assignment. Otherwise, the nondeterministic order of hash maps inside this function won't guarantee a consistent variable naming convention in the returned function. For tests, set `:deterministic? true`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close