On 7 May 2010 03:21, Micah Martin <[email protected]> wrote:
> I'm having trouble writing a macro and I hoping some one here can help.  My 
> desired result is the following:
>
> (defroutes all-routes
>  (GET "/one"   (foo "one"))
>  (GET "/two"   (foo "two"))
>  (GET "/three" (foo "three")))
>
> But I'd like to write it like so:
>
> (defroutes all-routes
>  (make-foos "one" "two" "three"))
>
> How do I write make-foos?  Does if have to be a macro, or can it be a 
> function?

It can be a function:

(defn make-foos [& things]
  (apply routes
    (for [x things]
      (GET (str "/" x) (foo x)))))

In Compojure, routes are just functions that either return a response
map, or nil if the route doesn't match. The "routes" function and
"defroutes" macro passes a request to each route in order until it
gets a non-nil response.

So because routes are just functions, you can combine them in any
fashion you choose.

- James

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

Reply via email to