On Wed, Jun 24, 2009 at 11:41 AM, Nicolas Oury<nicolas.o...@gmail.com> wrote:
>
> This is useful when you write a macro that generates a structure with a
> known set of fields at macro-expansion time. But sometimes this
> known set of fields will be empty.
>
> ( Imagine a macro allowing to shortly write some kind of records with
> some attributes modified/added/ removed by the macro.
> Internally, your macro expand to :
>
> `(let [my_struct (create_struct ~...@keys_generated_by_my_macro)]
>    in ....
>   (defn ....)), for example.
>
> if create_struct fails with no keys, then you have to write
>
> (if (empty? keys_generated_by_macro)
>   (defn ...)
>   (let [my_struct ...] ....))
>
> Resulting in code duplication: less readable, harder to modify, error
> prone.
> )
>
You could do:

`(let [my-struct (if (empty? keys) {} (create-struct ~...@keys))]
  (defn ...))

Right?

-- 
/mike.

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