<[email protected]> writes:
> Phillip, Paul - thanks a lot for you suggestions!
>
> Phillip - I will definitely give your trick a try.
>
> Right now, without experimenting, I see two shortcomings. First, as Paul
> mentioned, checking assertion status via call to Java function will
> introduce performance penalty, whereas the use of pure Java assert
> construct would leave minimal overhead when disabled.
Not convinced that this is true. The Java assert construct only has
minimal overhead because of a JVM trick -- that is the if check is
compiled out. In Java this requires JVM support, but in lisp as far as I
can tell, it's trivial; you just do the check in a macro. Consider...
;; this is the "are assertions on or off" variable
(def assertions-on true)
;; this is our macro -- which prints to tell us when the if statement evals.
(defmacro assrt [body]
(println "checking assertions on")
(if assertions-on
body))
;; this is the condition that we are checking
(def y true)
;; and here we test 100 times
(doseq [k (range 100)]
(assrt
(when y
(println "Yikes!!!"))))
The "checking assertions on" is only run once (actually, it appears to
happen twice for me, and I have no idea at all why). Same trick as
Java -- optimise the check away at compile time.
Indeed, this is how Clojure's assert works.
> Second issue is that with the described hack it would be difficult to
> switch assertions on/off on a per module basis, which is allowed by
> the jvm options.
Okay.
>
> So let me be a bit more precise. It would be great to have
>
> (awesome-assert (some-test x y z))
>
> which one can switch on/off on a per 'ns' basis via Java options + which
> leaves the smallest possible overhead when disabled.
I think that you are worried about the overhead unnecessarily, though.
The assert status is checked at macro expansion time. If per module
switching on and off is what then I would suggest that you build on top
of the existing assert.
Phil
--
--
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.