Thanks everybody for the pointers! I realized I was wrong about the
behavior being different in 1.2; rather it is the same since 1.1.0.
Shantanu
On Mar 20, 2:29 pm, Chas Emerick wrote:
> Using an explicit eval is generally not a good idea, as `bar` will be
> evaluated at least twice: once in va
Using an explicit eval is generally not a good idea, as `bar` will be evaluated
at least twice: once in validating the precondition, and again in the
macroexpansion. This can lead to all sorts of "interesting" problems if `bar`
happens to be a side-effecting expression.
- Chas
On Mar 20, 2012
try with {:pre [(string? (eval bar))]}
--
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 unsubscri
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 wrot
Hello,
I am not sure that anything has changed between Clojure 1.2.1 and
Clojure 1.3.0 with respect to pre- and post-conditions. However, I
think I have any idea as to what may be going on.
On Tue Mar 20 05:34 2012, Shantanu Kumar wrote:
> Hi,
>
> The way preconditions are invoked in Clojure 1.
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 sim
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 preconditio