The {} form is normal Clojure destructuring. There's a detail
description of the syntax on the Clojure home page:
http://clojure.org/special_forms#Special Forms--(let [bindings* ] exprs*)
For instance, if you want the parameters and the request map, you can
use the following binding:
{params :params :as request}
This will work in let-forms and fn arguments as well as in Compojure routes.
The [] form is a Compojure-specific destructuring, loosely based on
the Clojure kind.
To bind normal parameters, you can just use:
[x y z]
If you want to bind all remaining unbound parameters, you can use "&":
[x y & z]
This is equivalent to:
(let [x (-> req :params :x)
y (-> req :params :y)
z (dissoc (req :params) :x :y)]
...)
You can also just use:
[& params]
To bind all of the parameters to a map.
Finally, you can use the same :as keyword as in normal Clojure destructuring:
[& params :as request]
This is equivalent to the Clojure destructing:
{params :params :as request}
You can also embed Clojure destructuring in Compojure's destructuring, e.g.
[x y z :as {session :session}]
However, normal parameter symbols can't have embedded destructuring,
because Compojure needs to know the name of the symbol to find the
corresponding parameter. For example, this won't work:
[x [y z]]
Because Compojure won't know which parameter [y z] should be bound to.
I should really put all this on the wiki. I thought I had, but it
turns out I was mistaken. I'll try and get something up today.
- James