The precondition should be a vector of expressions.

 (defn foo [x] {:pre [(not (nil? x))]} (* 3 x))


On Jan 9, 2012, at 12:53 PM, Tom Chappell wrote:

> Ok, I've got a couple thousand lines of Clojure under my belt, but
> this has me stumped, unless it's a compiler etc. issue.  If I'm
> missing something dumb, what is it, please?
> 
> I have a function that is failing a not-nil precondition.  Here are
> four versions of the same test; only #3 works correctly.  Obviously I
> can work around the problem, but am I doing something wrong?
> 
> user> (def fq (frequencies "abbccc"))
> #'user/fq
> 
> user> fq
> {\a 1, \b 2, \c 3}
> 
> user> (fq \a)
> 1
> 
> user> ; incorrectly fails :pre
> (defn test-fun1
>  [mp k]
>  {:pre (not (nil? (mp k)))}
>  (mp k))
> #'user/test-fun1
> 
> user> (test-fun1 fq \a)
> 
> Assert failed: (nil? (mp k))
>  [Thrown class java.lang.AssertionError]

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