Hi,
Jeff correct me if I'm wrong but I think you are after something along the
following lines.
Instead:
(defn f [x] {:pre [(some-fancy-validation x)]} ..)
To have something like this:
(defn f [x] {:pre [^{:msg "here goes description of what has not been valid"}
(some-fancy-validation x)]} ..)
It could turn precondition to a bit more user-friendly construct.
I would also like to have assert-args public.
Cheers,
Hubert.
On Feb 10, 2011, at 8:10 PM, Daniel Werner wrote:
> On 10 February 2011 17:05, Jeff Rose <[email protected]> wrote:
>> Sorry for the reply spam, but I've just remembered another error
>> reporting issue: pre and post conditions. They are a great feature
>> and I'd like to use them more often, but the error messages they
>> produce are virtually useless in comparison to just writing your own
>> check with a custom exception. How about having optional error
>> messages for the conditions?
>
> You can make your pre/post condition AssertionErrors more
> human-readable by factoring out their logic into helper functions:
>
> (defn valid-article-id? [art-id]
> (or (and (> (mod x 42) 3) (frobz x)) (qux x)))
>
> (defn buy-article [art-id]
> {:pre [(valid-article-id? art-id)]}
> ...)
>
> Thus, the AssertionError message will complain about
> "valid-article-id?" failing instead of the rather cryptic "or and
> mod". If you need even more flexibility, it is also possible to throw
> an exception from the helper function. Not pretty, though.
>
> That said, I'd really wish for the private clojure.core/assert-args
> macro to be made public. It's very comfortable to work with and
> provides for semi-standardized error messages (offending argument name
> always in front).
>
> --
> 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
--
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