James Reeves wrote:
> On 7 April 2011 06:48, Joost <jo...@zeekat.nl> wrote:
> > I think your choice of currying makes more sense, at least in the
> > context of validations, so it might be a good idea to switch pretzel
> > over to that scheme.
>
> Would it make sense for clj-decline?

Yes. The main idea of clj-decline is to get rid of unesessary
restrictions on predicates and validation errors, but curried
predicates to me fit in slightly better than in-line functions. valip
looks pretty similar in design with regards to the predicates.

> The Valip predicates are designed with HTML form validation in mind,
> so they have a couple of unusual properties:
>
> 1. Valip predicates expect to test strings, e.g.
>
>   ((between 1 10) "5") => true
>   ((between 1 10) "0") => false

Yup. I'm mostly in the same boat. That's why all the predicates I've
produced for now are in the pretzel.strings namespace. I expect to end
up with few non-string predicates, but those will have to go into
pretzel.numbers or whatever make sense.

> 2. I'm considering adding an extra :pass return value, to denote the
> case when the input string cannot be tested by the predicate. For
> instance:
>
>   ((between 1 10) "foo") => :pass
>   (integer-string? "foo") => false
>
> This is to ensure I don't get exceptions for predicates when the input
> is incorrect:
>
>   (defn validate-rating [rating]
>     (validate rating
>       [:score present? "should be present"]
>       [:score digits? "should be a number"]
>       [:score (between 1 5) "should be between 1 and 5"]))
>
>   (validate-rating {:score " "})
>   => {:score ["should be present"]}
>
>   (validate-rating {:score "foo"})
>   => {:score ["should be a number"]}
>
>   (validate-rating {:score "15"})
>   => {:score ["should be between 1 and 5"]}
>
> So the predicates I'm writing for Valip are somewhat customised for
> validating string data, and are not generic predicate functions. Is
> Pretzel designed for general-use predicates, or for predicates
> designed for form validation?

As I alluded to above, the predicates in pretzel.string expect a
string as an argument. As long as that requirement is met, they
shouldn't throw exceptions or return any special value. I see that as
"general use" for these kinds of functions. Either the argument is
"valid" or it is not. Any handling above that cannot be up to the
predicate, and this is one of the reasons I added the pretzel.combine
functions ~ though I'm not sure that the  functions in that namespace
are named well.

For your specific example of  (integer-string? "foo"), that should
just return false. The idea - for strings - is that any kind of input
string can be supplied, and the function should just test whether it
conforms to some kind of formatting. The same logic should, I think,
apply to functions operating on numbers and other types such as files,
if there's a need for those kinds of predicates.

Cheers,
Joost.

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