I have manage to write something like this. But nothing more, all my
ideas are wrong, because bad knowledge about evaluation and namespace
expansion time.


(defmacro map-fnc [ & methods ]
        `(reduce (fn[ acc# m# ] (assoc acc# (str (first m#)) (list 'fn (rest
m#))  )) {} '~methods ))

(map-fnc (function1 [] "hello")
                (function2 [a] (println a)))

On Oct 5, 11:38 am, Michael Jaaka <michael.ja...@googlemail.com>
wrote:
> Hi!
>
> I wrote few apps with clojure. I have used many times macro to expand
> expressions and change some control flows. I thought that I know
> macros, but now I know that doing some programming by analogy is not
> enough. In fact I still don't know the macros works, I don't know when
> and how is evaluated and how symbols are evaluated. Problem below is
> something which I'm not able to solve with my current "knowledge".
>
> Let say that I wrote macro map-fnc
>
> and I want to use it like
>
> (map-fnc (function1 [] "hello")
>         (function2 [a] (println a)) )
>
> The result is map in which keys are names of methods as strings and
> body is a function with proper arity.
> So I can evalutate this:
>
> ((get (map-fnc (function1 [] "hello")
>                 (function2 [a] (println a)) ) "function1"))
>
> or this
>
> ((get (map-fnc (function1 [] "hello")
>                 (function2 [a] (println a)) ) "function2") "hello world")
>
> Any help?! I belive that solving this problem might give me more
> insight on how macro works.
>
> Thanks in advance!

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

Reply via email to