Turning off assertions

544 views
Skip to first unread message

Paul Stadig

unread,
Oct 4, 2012, 3:07:59 PM10/4/12
to cloju...@googlegroups.com
I have found assertions very helpful in developing code, but I'd like
to compile them away for a build that I would distribute. *assert*
gets interned as true in clojure.lang.RT, and it gets bound in
clojure.main. I can put a (set! *assert* false) at the top of my
source file, compile with lein, run code in a repl and everything is
fine, but if I try to run a main method or require that namespace from
somewhere I get an exception that I'm trying to set! *assert* when it
is not bound.

Would there be any interest in using *compiler-options* to control
assertions? Or is there some other way to compile with assertions off?


Paul

Alex Miller

unread,
Oct 4, 2012, 3:53:30 PM10/4/12
to cloju...@googlegroups.com
I believe they are standard Java assertions under the hood and should respond to normal JVM assertion handling properties like -da to disable assertions on the java command line. I'm not sure if there is a way to turn that on/off from within the jvm:


There are also some settings on the ClassLoader that may allow you to turn it off around your usage if you can control the classloader:



Paul

--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To post to this group, send email to cloju...@googlegroups.com.
To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.


Paul Stadig

unread,
Oct 4, 2012, 4:05:14 PM10/4/12
to cloju...@googlegroups.com
assert is just a macro that uses the value of *assert* to
include/exclude code before compiling.

https://github.com/clojure/clojure/blob/7d92c052d628d3d97c88781c304fa98772867b73/src/clj/clojure/core.clj#L4320-4331

There was some talk on http://dev.clojure.org/jira/browse/CLJ-250
about somehow tying into the JVM assertions, but that has not been
implemented as yet.

The JVM assertions are nice in that they can be toggled at runtime,
where as Clojure's must be toggled at compile time, but as I said
there doesn't seem to be a good way to actually toggle Clojure's
asserts.


Paul
Reply all
Reply to author
Forward
0 new messages