Nested partials in Clojure -
how data structure evaluated nested partial
s in following:((partial (partial - 3)6)9)
. inner partial
yields -3, have ((partial -3)9)
. how why partial makes (-3 -
9)? subtraction instruction from?
i helps manner of reading , evaluating of data representation clojure.
the claim ((partial - 3) 6)
called during course of evaluating expression incorrect, , @ core of misunderstanding.
to make simpler, let's break down:
((partial (partial - 3) 6) 9)
...instead, rewriting as:
(let [p1 (partial - 3)] ((partial p1 6) 9)
now, (partial p1 6)
return? function calls p1
, first argument being 6
, , subsequent arguments appended. thus, again write more verbosely as:
(let [p1 (partial - 3) p2 (partial p1 6)] (p2 9)
thus, (p2 9)
calls (p1 6 9)
, calls (- 3 6 9)
. (- 3 6)
never invoked anywhere in execution process, initial function call of -
never consumed until final invocation arguments present.
(the actual implementation may optimize middle call away, folding p1's arguments p2, there's no need incorporate such optimizations conceptual model; behavior equivalent above).
Comments
Post a Comment