Hi,

threading doesn't need to be a macro. In fact it would be easier to test if
it's just a function.

Also, you know about as->, don't you?


On Fri, Aug 28, 2015 at 2:37 PM, Akhil Wali <green.transis...@gmail.com>
wrote:

> I've been trying to refactor the -> and ->> forms to use a common macro
> form.
> Ended up with this.
>
> (defmacro threading [a b x forms]
>   (loop [x x
>          forms forms]
>     (if forms
>       (let [form (first forms)
>             f (first form)
>             r (rest form)
>             threaded (if (seq? form)
>                        (with-meta
>                          `(~f ~`(~a ~`(list ~x ~@r))
>                               ~`(~b ~`(list ~x ~@r)))
>                          (meta form))
>                        (list form x))]
>         (recur threaded (next forms)))
>       x)))
>
> (defmacro -> [x & forms]
>   `(threading ~'first ~'second
>               ~x ~forms))
>
> (defmacro ->> [x & forms]
>   `(threading ~'second ~'first
>               ~x ~forms))
>
>
> This does work, but it's a bit of whammy.
> Anyone with suggestions for improvement?
>
> --
> 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/d/optout.
>



-- 
Kind Regards,
Atamert Ölçgen

◻◼◻
◻◻◼
◼◼◼

www.muhuk.com

-- 
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/d/optout.

Reply via email to