This also works, I believe: (defmacro migrate [& migration-syms] (let [migration-vars (for [sym migration-syms] `(var ~sym))] `(migrate* ~@migration-vars)))
On Thu, Nov 28, 2013 at 5:22 PM, juan.facorro <juan.faco...@gmail.com>wrote: > Hi Curtis, > > The *apply* is unnecessary if you use *unquote-splice* (*~@*), also > instead of the *into* and *for* usage you could just *map* over the list > of symbols. > > Here's how I would do it: > > (defmacro migrate [& syms] > `(migrate* ~@(map (partial list 'var) syms))) > > (macroexpand-1 '(migrate a b c)) > > ;= (user/migrate* (var a) (var b) (var c)) > > > Hope it helps, > > Juan > > On Friday, November 29, 2013 5:26:14 AM UTC+8, Curtis Gagliardi wrote: >> >> I wrote a macro last night and got the feeling I did what I did in a >> suboptimal way. >> >> I have have a migration function that I stole from technomancy that takes >> in the vars of migration functions: >> (migrate #'create-db #'add-users-table #'etc) >> >> It uses the name of the var from the metadata to record which migrations >> have been run. I wanted to try to make it so you didn't have to explicitly >> pass in the vars, and just have the migrate function call var for you. >> I've since decided this is a bad idea but I wrote the macro anyway just for >> fun. My first question is: could this be done without a macro? I didn't >> see how since if you write it as a function, all you recieve are the actual >> functions and not the vars, but I thought I'd ask to be sure. Assuming you >> did have to write a macro, does this implementation seem reasonable? I >> felt strange about using (into [] ...). >> >> https://www.refheap.com/21335 >> >> Basically I'm trying to get from (migrate f g h) to (migrate* (var f) >> (var g) (var h)), I'm not sure I'm doing it right. >> >> Thanks, >> Curtis. >> > -- > -- > 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.