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.

(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).


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!. Really not a big deal, just Java-interop making things un-lispy.

is neat and tidy and easily extensible to added form-params later (add
them to the end of new-article's arg list and to the get-seq keyword
list in the same order; pass them to the amended Article constructor
appropriately).


--
Thorsten Wilms

thorwil's design for free software:
http://thorwil.wordpress.com/

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