Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does parallel binding mean in Clojure

Tags:

clojure

lisp

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?

like image 207
albusshin Avatar asked Mar 21 '23 23:03

albusshin


1 Answers

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).

like image 153
noisesmith Avatar answered Mar 29 '23 16:03

noisesmith