Macros should be avoided if you don't need them. Otherwise they drastically reduce code readability. In this case you just have some predicates and maps that need to be combined conditionally, so nothing macros do is needed. The real question here is why you would need a macro? Macros usage is, to me, a question of need, meaning I need to convince myself that you need it or I wouldn't sacrifice code readability for it.
Things macros are good for: - delayed code evaluation - DSL creation - moving computation to compile time (comes up occasionally) - other metaprogramming, which I usually only consider worth it if it reduces duplication enough Alex On Thu, Feb 21, 2013 at 9:11 AM, Ryan <arekand...@gmail.com> wrote: > I got confused a bit with the reason that a macro would not be appropriate > for this case. Can you please explain again? > > Ryan > > > On Thursday, February 21, 2013 7:05:11 PM UTC+2, Alex Baranosky wrote: > >> A function could be appropriate, but a macro not appropriate, since >> everything you need here can be done with using macros. >> On Feb 21, 2013 7:53 AM, "Ryan" <areka...@gmail.com> wrote: >> >>> Thanks for your input Alex. >>> >>> Do you think a macro would be appropriate if I use this more than once >>> in my code? >>> >>> Ryan >>> >>> On Thursday, February 21, 2013 5:41:49 PM UTC+2, Alex Baranosky wrote: >>>> >>>> I'd often just write it like this: >>>> >>>> (defn create-map [] >>>>> (merge {:foo "a" >>>>> :bar "b" >>>>> ... many more keys} >>>>> (when (some-condition-true) >>>>> {:extra-key value))) >>>> >>>> >>>> Alex >>>> >>>> On Thu, Feb 21, 2013 at 7:27 AM, Ryan <areka...@gmail.com> wrote: >>>> >>>>> Thanks Meikel for your reply. >>>>> >>>>> It wasn't clear on my example, but I wish to use *merge *inside my >>>>> create-map function. Do you think I should bind my hash-map to a let >>>>> variable first and then apply merge, or do you have another proposal? What >>>>> i mean is this: >>>>> >>>>> (defn create-key-value [value] >>>>> >>>>> (when (some-condition-true) {:extra-key value)) >>>>> >>>>> >>>>> (defn create-map [] >>>>>> (let [my-map {:foo "a" :bar "b"}] >>>>>> (merge my-map (create-key-value "some-value"))) >>>>> >>>>> >>>>> Is the above "clojurish" or is there a better way? For example if the >>>>> my-map was a big hash-map, and not with just two pairs, wouldn't it be >>>>> ugly >>>>> with the above way? or..it's just fine and no better way is possible? >>>>> >>>>> Ryan >>>>> >>>>> On Thursday, February 21, 2013 5:02:21 PM UTC+2, Meikel Brandmeyer >>>>> (kotarak) wrote: >>>>>> >>>>>> Hi, >>>>>> >>>>>> merge works with nil. So (merge (create-map) (create-key-value >>>>>> "some-value")) should work as you intend with the functions as they are >>>>>> defined now. >>>>>> >>>>>> Kind regards >>>>>> Meikel >>>>>> >>>>>> -- >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Clojure" group. >>>>> To post to this group, send email to clo...@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+u...@**googlegroups.com >>>>> For more options, visit this group at >>>>> http://groups.google.com/**group**/clojure?hl=en<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+u...@**googlegroups.com. >>>>> For more options, visit >>>>> https://groups.google.com/**grou**ps/opt_out<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 clo...@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+u...@**googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/**group/clojure?hl=en<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+u...@**googlegroups.com. >>> For more options, visit >>> https://groups.google.com/**groups/opt_out<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. > > > -- -- 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.