Reputation: 4010
I see the binding of recur
is "parallel", however I don't get what that means.
I've tested the code below:
(defn parallelTest
"parallel binding test of recur "
[]
(loop [vectorA [1 2 3 4 5]
A (first vectorA)]
(if-not (= A nil)
(do (println vectorA) (println A)
(recur (rest vectorA) (first vectorA)))) ;Recur!
))
(parallelTest)
the output is
user=>
[1 2 3 4 5]
1
(2 3 4 5)
1
(3 4 5)
2
(4 5)
3
(5)
4
()
5
nil
so I assume the bindings are happened simultaneously instead of one by one?
Upvotes: 4
Views: 321
Reputation: 18917
Sequential binding
a = 1
b = 2
Here
1
is evaluateda
2
is evaluatedParallel binding
a,b = 1,2
Here,
1
and 2
are evaluated, either in a determined order (such as left to right) or not, depending on the language specificationsa
and b
, respectively.If the expressions (here 1
and 2
) are independant and side-effect free, it doesn't matter which binding you use, but in parallel you need to be aware of the exact evaluation order.
Now, in your case,
(rest vectorA)
(first vectorA)
are evaluated (left to right)vectorA
and A
, respectively.which is a parallel binding, as opposed to for example a let
binding in Clojure which is sequential.
Upvotes: 3
Reputation: 20194
Yes, in computer science, "in parallel" will generally mean simultaneously, as opposed to "sequentially" (in a specified order) or "concurrently" (in an arbitrary indeterminate order, which could be parallel or sequential with arbitrary sequence). Parallel binding is typically understood to mean that a result (left hand side) of one binding is not in the scope of the creation (right hand side) of another (as opposed to sequential binding, as seen in Clojure's let
statement).
Upvotes: 4