Another option: create a helper function to do the work and have the macro call that:
(defn foo* [bar body-thunk] {:pre [(string? bar)]} (body-thunk)) ;or whatever (defmacro foo [bar & body] `(foo* ~bar (fn [] ~@body)) Justin On Tuesday, March 20, 2012 9:07:45 AM UTC-4, Chas Emerick wrote: > > Your second `foo` call fails in 1.2 as well. If there was ever a time > when it would have succeeded, it would have been a bug. Since `foo` is a > macro, it receives its arguments unevaluated, so `(str "baz" 34)` will > always be received as a list of three values. > > The syntax-quote precondition simply expands into a list containing the > symbol 'clojure.core/string? and the value of bar; this is a logically-true > value, and so does not trigger any error. > > You want something like: > > (defmacro foo > [bar & body] > `(let [bar# ~bar] > (when-not (string? bar#) (IllegalArgumentException. "msg")) > ...)) > > - Chas > > On Mar 20, 2012, at 8:34 AM, Shantanu Kumar wrote: > > > Hi, > > > > The way preconditions are invoked in Clojure 1.3.0 seems to have > > changed since Clojure 1.2: > > > > (defmacro foo > > [bar & body] > > {:pre [(string? bar)]} > > ...) > > > > (foo "bar34" ...) ; doesn't complain, which is OK > > (foo (str "baz" 34) ...) ; Error! (I wanted this to pass) > > > > When I write the precondition like this: > > > > {:pre [`(string? ~bar)]} > > > > It doesn't seem to check the precondition at all in 1.3.0. > > > > Can somebody suggest me what am I missing? I want both the examples > > above to be verified and passed as OK. > > > > Shantanu > > > > -- > > 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