Thanks Sean and Alan, I had noticed the same issue with moving (read-string) inside the macro - it works great for literals, but then why bother.
I had almost resigned myself to that fact that this would require eval, but I wanted to exhaust all macro options first. Thanks, Rob On Thursday, June 14, 2012 12:29:54 AM UTC+1, Rob Harrop wrote: > > Hi, > > I have a use case where I'd like to load small forms in String format from > a database and wrap them in functions. This is to support some basic > runtime customisation. > > I'm having problems getting read-string and macros to play nicely, a > problem which can be distilled as below: > > ; a simple macro to return a fn > (defmacro xr [f] > `(fn [] ~f)) > > ; calling the macro normally > (apply (xr (println "hello")) []) ; nil (and prints hello) > > ; calling with the result of read string > (apply (xr (read-string "(println \"hello\")")) []) ; (println "hello") > (and prints nothing) > > I'm sure I'm missing something very obvious here but I had assumed that > since (= '(println "rob") (read-string "(println \"rob\")")) that the above > example would work. > > Regards, > > Rob Harrop > -- 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