On Wed, 2009-06-24 at 11:53 -0400, Michael Reid wrote:
> >
> > (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?
>
I am not sure:
(struct {}) throws an exception.
I could do a multimethod like (in pseudo syntax for readbility):
my_struct {} = (hash-map)
my_struct a_struct &keys = (apply struct a_struct keys)
But it looks a bit strange and complicated.
On the other hand, most languages allow empty records.
Best,
Nicolas.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---