Hi,

recently I got interested core.async (also thanks to great blog post such 
as the ones by David Nolen) and wanted to understand better how it compares 
to other reactive libraries, in particular coming from the research on 
Functional Reactive Programming (FRP).

Compared to FRP, core.async appears to be build around side-effects on 
channels which breaks referential transparency. What I mean here, is that 
channels are somewhat like reference types and connect a (time varying) 
value to an identity.

As an example consider a map-like channel transformer (as found in many 
posts explaining core.async) (map-ch f in out) which takes values x from 
the input channel in and writes (f x) to the output channel out. 

(defn map-ch 
  ([f in]
     (map-ch f in (chan)))
  ([f in out]
    (go (loop []
             (if-let [x (<! in)]
                (do (>! out (f x))
                     (recur))
                (close! out))))
    out))

Now, the following two snippets behave rather differently:

(let [out-1 (map-ch inc (<some function creating a channel and writing data 
to it>))
      out-2 (map-ch dec (<some function creating a channel and writing data 
to it>))]
  (go (loop []
          (when-let [x (<! out-1)]
              (println "receiving " x)
              (recur)))))

(let [in     (<some function creating a channel and writing data to it>)
      out-1 (map-ch inc in)
      out-2 (map-ch dec in)]
  (go (loop []
          (when-let [x (<! out-1)]
              (println "receiving " x)
              (recur)))))

Whereas the first example receives all incremented values, the second one 
receives potentially less since both consumers read from the very same 
input channel! This also means that one can break working code, by 
(accidently) attaching an additional consumer ... note that in Rx I can 
subscribe as many times as I want to an observable without any effect on 
the rest of the data flow.

Maybe I'm misunderstanding CSP and how it allows to compose and synchronize 
processes, but somehow I feel that channels complect the idea of state 
varying values and identity. Regarding that referential transparency, which 
is required for equational reasoning, is one of the best properties of 
purely functional programs, breaking  it seems to be at least problematic.

Any thoughts?

   Nils

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to