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

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.

Paul, if I understand you correctly this would require some changes in 
Clojure itself. Question to Clojure gurus - would it be very difficult to 
introduce such awesome feature to Clojure? 

I have put a comment on the JIRA issue mentioned by Paul. Is there any 
other channel to put it as feature request?

Again, thanks in advance for all your comments and suggestions on the issue!

Best regards,
MichaƂ

On Friday, October 11, 2013 1:12:43 PM UTC+2, Paul Stadig wrote:
>
> The problem is that you would still have a performance hit. As I 
> understand, the reason that Java assertions have no runtime penalty when 
> disabled is because they depend on the value of a final field in a class 
> which the JIT will eliminate as dead code when that final field is set to 
> false. The only way to get Clojure's asserts eliminated at runtime would 
> seem to require a compiler change.
>
> Paul
>
> On Friday, October 11, 2013 7:02:24 AM UTC-4, Phillip Lord wrote:
>>
>> <lop...@gmail.com> writes: 
>> > Is it possible to use Java assertion system in Clojure? 
>> > 
>> > I want to put invariant checks in my code which can be turned on/off at 
>> > runtime with java -ea/-da. 
>> > 
>> > 
>> http://docs.oracle.com/javase/7/docs/technotes/guides/language/assert.html 
>> > 
>> > The only mention touching this issue in Clojure I could find is 
>> > 
>> > https://groups.google.com/forum/#!topic/clojure-dev/kUCVUEALmWI 
>> > 
>> > it does not give any constructive suggestions, though. 
>> > 
>> > Has anybody used this JVM facility in Clojure code? 
>> > 
>> > Thanks in advance for any of your hints! 
>>
>>
>> I guess you could use the assertion status of Java to set the *assert* 
>> variable, and then just use the Clojure assert facility. 
>>
>> Unfortunately this is a bit of a pain as there doesn't appear to be an 
>> API to check the assertion status. So, you'd need a bit of java code... 
>>
>>
>> static boolean assertsEnabled(){ 
>>     boolean assertsEnabled = false; 
>>     assert assertsEnabled = true;   
>>
>>     return assertedEnabled; 
>> } 
>>
>> Bit ugly. 
>>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to