<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -23,8 +23,13 @@
  [segments]
   (apply str &quot;/&quot; (interpose &quot;/&quot; (map #(java.net.URLEncoder/encode % &quot;UTF-8&quot;) segments))))
 
-(defn- prefix-route? [route]
-  (= '&amp; (peek route)))
+(defn- split-route [route default-etc]
+  (if-let [[l ll] (rseq route)]
+    (cond
+      (= '&amp; l) [(pop route) default-etc]
+      (= '&amp; ll) [(-&gt; route pop pop) l]
+      :else [route nil])
+    [[&quot;&quot;] nil]))
 
 (def #^{:doc &quot;Handler that causes the framework to fall through the next handler&quot;} 
   pass (constantly nil))
@@ -68,12 +73,12 @@
         simple-route (map #(if (simple-segment? %) % '_) route)
         params+alias (map #(if (vector? %) (conj % (gensym)) %) params)  
         args (map #(if (vector? %) (% 2) %) params+alias)
-        bindings (for [p params+alias :when (vector? p) :let [[v f alias] p]]
-                   [v (cond
-                        (regex? f) (list `re-matches f alias)
-                        (string? f) `(when (= ~f ~alias) ~f)
-                        :else (list f alias))])]
-    [simple-route (vec args) bindings]))
+        validators (for [p params+alias :when (vector? p) :let [[v f alias] p]]
+                     [v (cond
+                          (regex? f) (list `re-matches f alias)
+                          (string? f) `(when (= ~f ~alias) ~f)
+                          :else (list f alias))])]
+    [simple-route (vec args) validators]))
 
 (defn- compile-handler-shorthand [form]
   (cond
@@ -83,18 +88,19 @@
                   
 (defn- compile-route [segments [route form]]
   (let [handler (compile-handler-shorthand form) 
-        [simple-route args bindings] (extract-args route)
-        etc-sym (when (prefix-route? route) (gensym &quot;etc&quot;))
-        handler (if etc-sym `(alter-request ~handler assoc :uri (uri ~etc-sym)) handler)
-        args (if etc-sym (conj args etc-sym) args)
-        emit-bindings 
-          (fn emit-bindings [bindings]
-            (if-let [[binding &amp; etc] (seq bindings)]
-              `(when-let ~binding
-                 ~(emit-bindings etc))
-              handler))]
+        etc-sym (gensym &quot;etc&quot;)
+        [fixed-route tail-binding] (split-route route etc-sym)
+        [simple-fixed-route args validators] (extract-args fixed-route)
+        simple-route (if tail-binding 
+                       (concat simple-fixed-route ['&amp;]) 
+                       simple-fixed-route)  
+        args (if tail-binding (conj args tail-binding) args)
+        handler (if (= tail-binding etc-sym) 
+                  `(alter-request ~handler assoc :uri (uri ~etc-sym)) 
+                  handler)
+        emit-validator (fn [body validator] `(when-let ~validator ~body))]
     `(when-let [~args (match-route ~segments '~simple-route)]
-       ~(emit-bindings bindings)))) 
+       ~(reduce emit-validator handler (reverse validators))))) 
 
 (defn- compile-router [forms]
   (let [segments (gensym &quot;segments&quot;)</diff>
      <filename>src/net/cgrand/moustache.clj</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>705cde1ebc9a9a8b3426cea3c54bdddee1bf0678</id>
    </parent>
  </parents>
  <author>
    <name>Christophe Grand (cgrand)</name>
    <email>christophe@cgrand.net</email>
  </author>
  <url>http://github.com/cgrand/moustache/commit/96cf5a47041f81d44e45418f4e5fbc26135d5098</url>
  <id>96cf5a47041f81d44e45418f4e5fbc26135d5098</id>
  <committed-date>2009-06-08T08:34:29-07:00</committed-date>
  <authored-date>2009-06-08T08:34:29-07:00</authored-date>
  <message>fixed a bug: destructuring wasn't supported in tail-binding</message>
  <tree>cfb68efe11fabb601c374dcbc91b138847437409</tree>
  <committer>
    <name>Christophe Grand (cgrand)</name>
    <email>christophe@cgrand.net</email>
  </committer>
</commit>
