Why does this need to be a macro?  It doesn't actually manipulate code.

Just turn this:  (~f n# ~@args) into (apply f n args) in the function
implementation.


On Fri, Jul 26, 2013 at 11:49 AM, Yoshinori Kohyama <yykohy...@gmail.com>wrote:

> Hello group.
>
> I wrote a tiny macro to apply a function to values in lowest levels in a map 
> with arguments.
> Three questions:
>
>    - Does this abstraction have any existing name?
>    - Is there any existing function/macro to do similar things?
>    - Would anyone improve this implementation?
>
>
> (require '[clojure.test :refer (with-test is are run-tests)])
>
> (with-test
>   (defmacro mapf [f m & args]
>     `((fn f# [n#]
>         (if (map? n#)
>             (into {} (map (fn [[k# v#]] [k# (f# v#)]) n#))
>             (~f n# ~@args)))
>       ~m))
>
>   (is (= (mapf #(* % %) {:a {:b 3 :c 4} :d 5})
>          {:a {:b 9 :c 16} :d 25}))
>   (is (= (mapf #(+ (* %1 %1) %2) {:a {:b 3 :c 4} :d 5} 1)
>          {:a {:b 10 :c 17} :d 26})))
>
> https://gist.github.com/kohyama/6089899
>
> Thank you in advance.
>
> Y.Kohyama
>
>  --
> --
> 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.
>
>
>

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