Nested particles in Clojure
As the data structure is evaluated using a nested partial
as follows: ((partial (partial - 3)6)9)
. The inner partial
gives -3, then we have ((partial -3)9)
. But how then does the partial (-3 -
9) happen ? Where does he get the subtract instruction from?
I would like some of them to help in reading and evaluating this data view with Clojure.
source to share
The assertion that ((partial - 3) 6)
is invoked during the evaluation of this expression is incorrect, and this is at the root of the misunderstanding.
To make it easier, let's break down:
((partial (partial - 3) 6) 9)
... instead rewriting it as:
(let [p1 (partial - 3)]
((partial p1 6) 9)
Now what (partial p1 6)
does it return ? The calling function, p1
with its first argument 6
and any subsequent arguments. So we could write it again in more detail:
(let [p1 (partial - 3)
p2 (partial p1 6)]
(p2 9)
Thus, the (p2 9)
calling (p1 6 9)
, which is calling (- 3 6 9)
. (- 3 6)
is never called anywhere during execution, so the initial function call is -
never consumed until the final call with all arguments.
(The actual implementation can optimize the middle call by adding the arguments p1 to p2, but there is no need to include such optimizations in the conceptual model, the behavior is equivalent to the above).
source to share