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
{:keys [gensym-fn] :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.
The special form (doto v (aset i v_i)...)
is recognized at the top level,
and the CSE process is then confined to the $v_i$ expressions.
:gensym-fn
: side-effecting function that returns a new, unique
variable name prefixed by its argument on each invocation.
monotonic-symbol-generator
by default.
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. The special form `(doto v (aset i v_i)...)` is recognized at the top level, and the CSE process is then confined to the $v_i$ expressions. ### 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.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close