While reading article "Challenged by Common Lispers":
http://kazimirmajorinc.blogspot.com/2009/01/challenged-by-common-lispers.html

I found in its comments interesting definition of 'memfn':
https://www.blogger.com/comment.g?blogID=5894839&postID=8563938547112716465

This is my version in Clojure:
(defmacro macrofn [mname]
  `(fn [& ~'args]
    (eval `(~'~mname ~...@~'args))))

And its use:
user=> (macroexpand-1 '(macrofn or))
(clojure.core/fn [& args] (clojure.core/eval (clojure.core/concat
(clojure.core/list (quote or)) args)))
user=> (apply (macrofn or) '(nil 1 2 3 nil 4))
1
user=> (map (macrofn or) '(1 nil 3) '(nil 2 nil))
(1 2 3)

It is also closely related to apply_macro.clj: make macros behave like
functions - work done by Stuart Sierra:
http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/apply_macro.clj

Warning: Beware of use of 'eval' !!! ;-)

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