This, or wrap user-pass with seq in the conditional, which will return nil
for an empty list:

(defn authenticate?
 [uri name pass]
 (loop [user-pass (seq (partition 2 (.getStringArray *conf*
"authentication")))]
   (if (seq user-pass)
     (if (re-matches (re-pattern (ffirst user-pass)) uri)
       true
       (recur (rest user-pass)))
     false)))

In Clojure, the only values that evaluate to false are nil and false.  The
empty list ('(), which rest returns on your last iteration, does not
evaluate to false as in some languages).

 - Mark

On Mon, Jun 13, 2011 at 5:35 PM, Meikel Brandmeyer <m...@kotka.de> wrote:

> Hi,
>
> Am 13.06.2011 um 22:04 schrieb Razvan Rotaru:
>
> > (defn authenticate? [uri name pass]
> >         (loop [user-pass (partition 2 (.getStringArray *conf*
> > "authentication"))]
> >               (if user-pass
> >                         (if (re-matches (re-pattern (ffirst user-pass))
> uri )
> >                                 true
> >                                 (recur (rest user-pass)))
> >                         false)
> >                ))
>
> (defn authenticate?
>  [uri name pass]
>   (loop [user-pass (seq (partition 2 (.getStringArray *conf*
> "authentication")))]
>     (if user-pass
>      (if (re-matches (re-pattern (ffirst user-pass)) uri)
>        true
>         (recur (next user-pass)))
>      false)))
>
> You probably want something more like this. Note the tactically placed seq
> and the use of next instead of rest. Does that solve your problem? (I
> suspect, that you get a nil from the ffirst. rest doesn't give you a nil
> (next does), so your loop doesn't stop correctly. But I haven't tested
> this.)
>
> Sincerely
> Meikel
>
> --
> 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
>

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