Hi Ken, > Shoundn't be too hard. Something like
[snip] Thanks, looks good. I haven't had a chance to play with the code yet but it looks like a very good start. > > You probably want it to omit bmi from the argument lists and compute > it -- that will complicate things, something like: > [snip] > used with something like > > (defentity person > {:name {:type String} > :id-number {:type Integer} > :height {:type Double :default 100.0} > :weight {:type Double :default 100.0} > :bmi {:type Double :computer (/ weight height)}}) > > Note that both the :default and the :computer can be s-expressions > that just get inserted verbatim as code. The two differences are: > > 1. A field with :computer will not ever be a constructor parameter. > > 2. The :computer s-expression can refer to any of the fields; the > :default can only refer to earlier ones and non-optional ones. > > I hope this shows how one might go about constructing a macro to take > a definition similar to your original person-entity map and turn it > into a record, constructor function, and possibly other structures. > For example it could put code in the constructor function to run a > :validator, if present, on that field, where the :validator throws an > exception; or to turn a :validator field into a test and throw > exception clause where the :validator is a boolean expression; etc. Yes, that is great thanks! Cheers, David -- 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