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. ) However, (create_struct) seems like a natural generalisation of (create_struct & keys). Best, Nicolas. On Wed, 2009-06-24 at 10:27 -0500, Mark Volkmann wrote: > On Wed, Jun 24, 2009 at 10:07 AM, Nicolas Oury > <nicolas.o...@gmail.com> wrote: > > Dear all, > > Sometimes, when I write some macros and applied them to > special case, I > got a "create-struct : must supply keys" exception. > > I think it should be possible to write (create-struct) and > have an empty > structure definition returned. > > With (struct (create-struct)) more or less equivalent to > creating an > empty map. > > Currently, it results in some special case in macros or adding > a :dummy > field to any generated struct. > > If you don't know the keys in advance then why not create a map > instead? For me the point of using a struct is that you get optimized > access to a known set of keys and the struct documents the keys you > expect to use. You can't get those benefits without knowing the keys. > > -- > R. Mark Volkmann > Object Computing, Inc. > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---