Promises (and dataflow programming in general) are really useful with interacting with physical devices, especially robots. Suppose you have a 200 ton press, with a safety sensor. You have the following code:
(def is-it-safe? (promise)) (defn activate-press [] (if @is-it-safe? (go!))) (defn poll-sensor [] (loop [] (if (= (read-sensor) :safe) (deliver is-it-safe :safe) (do (Thread/sleep 50) recur)))) Now, the poll-sensor fn is usually running in a daemon thread somewhere else. The call to activate-press will happen at a seemingly random time, at least as far as poll-sensor is concerned. The promise forces the press to wait unit it's safe to activate. There are all sort of other conditions where this makes sense when dealing with mechanics. This is just one. HTH, Sean On Jan 21, 6:40 am, Laurent PETIT <laurent.pe...@gmail.com> wrote: > In a nutshell, those are the building blocks for the "dataflow > programming paradigm". > > It's an easy way to make a computation done in thread A (and using a > pre-declared promise) block until thread B has delivered the promise > (given it its value). > > The book CTM covers dataflow programming > :http://www.info.ucl.ac.be/~pvr/book.html > > Now, to be honest, i still haven't read the related parts of the book, > and I'm unable to give more concrete examples yet :-) > > 2010/1/21 Baishampayan Ghose <b.gh...@ocricket.com>: > > > Hello, > > > I am trying to understand the use-cases of the new promise/deliver > > feature in Clojure. I have tried using them, and they seem to be > > pretty straight-forward to use, but unfortunately I haven't been able > > to understand its use-cases. > > > It would be great if someone pointed out some example usage of > > promise/deliver. > > > Regards, > > BG > > > -- > > Baishampayan Ghose > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > 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 post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en