if-not implementation

252 views
Skip to first unread message

Leon Grapenthin

unread,
Jan 21, 2015, 2:51:37 PM1/21/15
to clo...@googlegroups.com
I am surprised to find the two branch implementation of if-not as follows:


([test then else]
   
`(if (not ~test) ~then ~else))


What I expected was:


([test then else]
   
`(if ~test ~else ~then))

Mikera

unread,
Jan 21, 2015, 7:32:35 PM1/21/15
to clo...@googlegroups.com
Interesting -  there seems to be a very slight performance advantage to your version on my machine (consistently about 25% faster for if-nots in a tight loop).

I think the problem is actually with "not" - which isn't getting inlined currently. If I patch not so that it is inlined, the difference disappears.

Worth a quick patch maybe?

Jan-Paul Bultmann

unread,
Jan 22, 2015, 7:07:38 AM1/22/15
to clo...@googlegroups.com
Even with inlining the code is rather silly ;)

[x] (if x false true)

so you'd get,

(if (if test false true) then else)

Which relies a bit too much on the JVM's JIT for my taste :D

I've always wondered what the reason for the original implementation is.
Keep closer to the implementation of not, so that no incompatibilities arise
should not become a protocol one day?

Cheers Jan


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages