I've seen that and think it's awesome. This would be used for Node.js.

I whipped this up to show what a Clojure version might look like.  
Basically each body form after the first is inserted where (cb) is found in 
the previous form.

; Definition
(defmacro defseq
  [fn-name params & body])

; Example usage
(defseq request-handler [req resp]
  ((. resp (set-header "Content-Type" "text/html"))
   (exists "some-file.txt" (cb)))

  (fn [exists]
    (if exists
      (read-file filename "utf8" (cb))
      (. resp (end "File Not Found"))))

  (fn [err data]
    (if err
      (. resp (end "Internal Server Error"))
      (. resp (end data)))))

On Wednesday, February 6, 2013 2:13:33 PM UTC-5, Max Penet wrote:
>
> Hi, 
>
> jayq includes something similar (nicer imho). It takes the form of a let 
> like construct 
>
> (let-deferred
>     [a (jq/ajax "http://localhost:8000/1.json";)
>      b (jq/ajax "http://localhost:8000/2.json";)]  (do-something-with-result 
> (merge a b foo)))
>
> It also supports :let and :when intermediary steps.
>
> more examples can be found here: 
> https://github.com/ibdknox/jayq#jayqmacros-source
>
> and the macro: 
> https://github.com/ibdknox/jayq/blob/master/src/jayq/macros.clj#L15
> https://github.com/ibdknox/jayq/blob/master/src/jayq/core.cljs#L516
>
>
> Max
>
> On Wednesday, February 6, 2013 7:45:36 PM UTC+1, da...@dsargeant.comwrote:
>>
>> I'm not to clojure/clojurescript and was wondering if anyone has taken a 
>> crack at writing a macro that transforms callbacks into a sequence.  There 
>> is an awesome implementationion in LispyScript show here: 
>> https://gist.github.com/santoshrajan/3715526.  Thanks for help.
>>
>> David
>>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to