Nested partials in Clojure -


how data structure evaluated nested partials 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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -