On Fri, Mar 25, 2011 at 5:09 AM, Thorsten Wilms <t...@freenet.de> wrote: > On 03/25/2011 01:34 AM, Ken Wesson wrote: >> >> What about this? First, use :title and :body keywords instead of >> "title" and "body" strings as keys in form-params. Then define this >> utility function: >> >> (defn get-seq [m & kws] >> ((apply juxt kws) m)) >> >> which takes a map and one or more keywords (cannot be other types of >> key) and returns a seq (actually a vector) of the corresponding >> values, in order; do this > > I don't get to chose the keys, with wrap-params I get whatever is used in > the form as strings, inside a :form-params inside the request map.
Well, that's too bad. (apply juxt (map (fn [k] #(get % k)) kws)) it is, then. >> (defn new-article [path timestamp title body] >> (Article. path title body timestamp)) > > Interesting, but you just listed title and body twice, where the goal was to > not list them at all (except in the definition of Article and in the html > form, of course, though theoretically, the form could be generated from a a > bit richer single definition, I suppose). I extracted them from save-article to what's basically a Clojure-friendlier constructor for Article. Is there a reason for you to consider this goal supremely important? >> so you can use apply. And then this: >> >> (defn save-article >> [path form-params timestamp] >> (ds/save! >> (apply new-article path timestamp >> (get-seq form-params :title :body)))) > > By now I'm rather sure this would trigger an error, as nothing but an > immediate call of Article. seems acceptable for ds/save!. Why do you say that? Either your ds-save! is a function that accepts Article objects, and that apply expression returns one; or else your ds-save! is a macro that accepts an s-expression that will become part of its expansion and which works if it evaluates to an Article object at run-time, which the apply expression does. If for some reason you've made it a macro that accepts an s-expression, but parses it itself and expects it to be a constructor invocation, then I suggest you rewrite it to accept any s-expression. Otherwise, the style should be separate parameters, e.g. (defmacro ds-save! [classname & ctor-args]) to make it simpler to implement and to make it clear to its users that it cannot take general-purpose sexps that return the appropriate Java type. But really, it should accept pure function invocations happening in its context, at least -- and the only possibly-impure thing in the apply/getseq/new-article chain there is the Article constructor invocation itself, which would be there anyway. -- 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