Re: Set equality bug?

2015-01-22 Thread Immo Heikkinen
I actually ran into this while comparing nested data structures from two different sources and spent a good part of my day figuring out what's happening. While it is a good advice to avoid mixing floats and doubles, it is inevitable that Clojure users will get bitten by this once in a while and hou

Re: [ANN] Reagent + Sente (+ Heroku) = Rente

2015-01-22 Thread Henrik Mohr
I'm not. The Datomic Transactor is on one of our own hosts. On Friday, January 23, 2015 at 12:43:28 AM UTC+1, Wei Hsu wrote: > > How are you running Datomic on Heroku? > > On Thursday, January 22, 2015 at 8:53:29 AM UTC-8, Henrik Mohr wrote: >> >> (still) a moderate load. Around 10-50 users online

Re: Satisfies? seems strangely slow

2015-01-22 Thread Tassilo Horn
Ghadi Shayban writes: > I don't think satisfies? is worth optimizing as using ton of it seems > antithetical to protocols. It signals to me that a caller does in fact > care about the implementation, whereas protocols are about not > caring. Like your PR, if you want to ensure a protocol's covera

Re: Satisfies? seems strangely slow

2015-01-22 Thread Ghadi Shayban
Clojure is caching protocol implementations explicitly with extra bytecodes, not the JVM. And it is very efficient. I don't think satisfies? is worth optimizing as using ton of it seems antithetical to protocols. It signals to me that a caller does in fact care about the implementation, where

Re: Satisfies? seems strangely slow

2015-01-22 Thread Michael Blume
Wait isn't this caching? https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L480 On Thu Jan 22 2015 at 8:44:09 PM Bobby Eickhoff wrote: > Clojure isn't doing the caching. The JVM is doing the caching. In this > case, Clojure just has mechanical sympathy for how the

Re: Satisfies? seems strangely slow

2015-01-22 Thread Bobby Eickhoff
Clojure isn't doing the caching. The JVM is doing the caching. In this case, Clojure just has mechanical sympathy for how the JVM operates. On Thursday, January 22, 2015 at 11:10:56 PM UTC-5, Michael Blume wrote: > > It sounds like basically dispatch is fast because we bothered to make it > fa

Re: Satisfies? seems strangely slow

2015-01-22 Thread Michael Blume
It sounds like basically dispatch is fast because we bothered to make it fast (by caching) and satisfies? is slow because we didn't. Is it worth throwing caching at satisfies? to make it fast or should satisfies? just not be on the critical path for Clojure code? (To give a motivating example, sat

Re: Satisfies? seems strangely slow

2015-01-22 Thread Ghadi Shayban
Protocol call sites build an inline cache to optimize dispatch. The benchmark is running many times and reaping benefit from the cache. satisfies? looks up the object's class in the protocol's implementation map [1], and the benchmark is stressing this. You'll see that code checks if the pro

Re: Satisfies? seems strangely slow

2015-01-22 Thread Michael Blume
Extends seems to be defeated by superclassing. ie: (extends? my-protocol (class {})) => false because my-protocol is extended to IPersistentMap and (class {}) isn't IPersistentMap it's PersistentArrayMap (which implements IPersistentMap but extends? doesn't care) On Thu Jan 22 2015 at 5:28:30 PM

Re: Satisfies? seems strangely slow

2015-01-22 Thread Timothy Baldridge
The logic of extends? is much simpler, so try that. IIRC it's something like "extends? returns true if any method on the protocol is implemented by x", "satisfies? returns true if all methods of a protocol are implemented by x". The docs don't seem to give much help here, so play with it in the re

Satisfies? seems strangely slow

2015-01-22 Thread Michael Blume
(defprotocol my-protocol (foo [this])) (extend-protocol my-protocol clojure.lang.IPersistentMap (foo [this] "hello from map")) (criterium.core/quick-bench (satisfies? my-protocol {})) (criterium.core/quick-bench (foo {})) Simply calling foo on an empty map takes 7 ns, but checking whe

Re: Testing macros that throw errors at compile time?

2015-01-22 Thread Michael Blume
macroexpand-1 is a good start, I'd also recommend using the (is (thrown? ...)) special form, so (is (thrown? IllegalArgumentException (macroexpend-1 '(my-macro (ill-formed-arguments ...) On Thu Jan 22 2015 at 5:05:36 PM Ben Wolfson wrote: > (try (macroexpand-1 '(my-macro (ill-formed-argumen

Re: Testing macros that throw errors at compile time?

2015-01-22 Thread Ben Wolfson
(try (macroexpand-1 '(my-macro (ill-formed-arguments ...))) false ;; shouldn't get here (catch Exception _ true)) ;; whole expression should be true As long as you know that the *right* exception is being thrown. On Thu, Jan 22, 2015 at 4:41 PM, Scott Rabin wrote: > We have a few ma

Testing macros that throw errors at compile time?

2015-01-22 Thread Scott Rabin
We have a few macros in my employer's codebase that throw compile-time errors when you've given them invalid configurations, and have generally simply tested the result of these macros and not necessarily the direct expansion of said macros. What we would like to do is *test* that the macro blo

Re: [ANN] Reagent + Sente (+ Heroku) = Rente

2015-01-22 Thread Wei Hsu
How are you running Datomic on Heroku? On Thursday, January 22, 2015 at 8:53:29 AM UTC-8, Henrik Mohr wrote: > > (still) a moderate load. Around 10-50 users online at the same time. Not > an extreme load on the Datomic Peer library since not a whole lot of data > is stored per user (well, not fo

Re: Set equality bug?

2015-01-22 Thread Andy Fingerhut
Part of what you wish were true is already true: Using = to compare a double to a BigDecimal always returns false in Clojure, as does comparing a float to a BigDecimal. It is only (= float-value double-value) that can return true in Clojure, even though hash does not guarantee the usual hash consi

Re: Set equality bug?

2015-01-22 Thread Fluid Dynamics
On Thursday, January 22, 2015 at 2:12:52 PM UTC-5, Jozef Wagner wrote: > > As seen in CLJ-1372, this issue will probably cause some strong opinions. > I think this is an example of a leaky abstraction and the current approach > is to leave it as is, as there are some serious trade-offs and are th

[ANN] Clojure/West 2015 Registration Open

2015-01-22 Thread Alex Miller
## Registration ## Tickets are on sale now for Clojure/West 2015 - Apr 20-22 in Portland, Oregon! - Register: http://clojurewest2015.eventbrite.com - Early bird - $275 (and going fast) - Regular - $350 ## Workshops ## We will also have workshops on the weekend prior to Clojure/West (Apr 18-19th)

Re: Set equality bug?

2015-01-22 Thread Jozef Wagner
As seen in CLJ-1372, this issue will probably cause some strong opinions. I think this is an example of a leaky abstraction and the current approach is to leave it as is, as there are some serious trade-offs and are there is no rationale or real practical reason to fix this. Current implementation

Re: [ANN] Clojure 1.7.0-alpha5 now available

2015-01-22 Thread Aaron Cohen
This is a different though related problem to http://dev.clojure.org/jira/browse/CLJ-1315 That problem was trying to solve "require" un-necessarily importing classes, your example is a type hint with a similar issue. I do think you're correct, it looks like a reasonable change, but it would requi

Re: [ANN] Clojure 1.7.0-alpha5 now available

2015-01-22 Thread Adam Clements
Just to follow up, doing the obvious (though perhaps naïve) fix of changing forName to forNameNonLoading in the referenced maybeClass does seem to fix the issue and I can now AOT compile my application without needing the binaries for this machine. I don't know whether this change would have any ot

Re: [ANN] Clojure 1.7.0-alpha5 now available

2015-01-22 Thread Adam Clements
I think I am seeing static initialisers being run at AOT time when the class is used as a type hint tag. This isn't a regression from previous versions of clojure, but with the forNameNonLoading changes that have gone in recently I was under the impression that this shouldn't be a problem any more.

Re: [ANN] Reagent + Sente (+ Heroku) = Rente

2015-01-22 Thread Henrik Mohr
(still) a moderate load. Around 10-50 users online at the same time. Not an extreme load on the Datomic Peer library since not a whole lot of data is stored per user (well, not for all users at least). But the server does a lot of real time calculations all the time based on user actions. And y

Re: Set equality bug?

2015-01-22 Thread Luc Préfontaine
And how to you want to proceed knowing that floats and double can escape elsewhere in your app and create the same chaotic effect like for example, in some interop call to some obscure library ? The best ... consistency here seems to reflect what's occurring underneath instead of giving the false

Re: Set equality bug?

2015-01-22 Thread Andy Fingerhut
On the side of positive recommendations to avoid problems like this, here is some advice: + Don't mix floats and doubles in the same Clojure program. Given that Clojure uses double arithmetic by default, it is much easier to use doubles everywhere than it is to try to use floats everywhere. + Do

Re: [ANN] Reagent + Sente (+ Heroku) = Rente

2015-01-22 Thread gvim
On 22/01/2015 07:01, Henrik Mohr wrote: OT: I'm supporting a production app with Clojure/ClojureScript/Datomic/Ring/Sente etc. on a Heroku 2X dyno having 1 GB of RAM. It works like a charm! Best, Henrik What kind of load? Is a basic web app even do-able on a 1X dyno, ie. 512Mb RAM? It's jus

Re: Set equality bug?

2015-01-22 Thread Plínio Balduino
My one cent: But I think (and it's just my humble opinion) is in the scope of Clojure keep its consistency, am I right? I mean, if doubles and floats are different, and they are, I think we should always get equality test as false. Or always as true, if they're nominally the same value. Regards

core.async chan ex-handler

2015-01-22 Thread Derek Troy-West
>From the documentation: (chan buf-or-n xform ex-handler) "If a transducer is supplied a buffer must be specified. ex-handler must be a fn of one argument - if an exception occurs during transformation it will be called with the Throwable as an argument" Is there a reason the ex-handler fn does

Re: Set equality bug?

2015-01-22 Thread Andy Fingerhut
"It is out of scope for Clojure to fix this for Java types Float/Double" -- comments in CLJ-1036: http://dev.clojure.org/jira/browse/CLJ-1036 Andy On Thu, Jan 22, 2015 at 5:53 AM, Nicola Mometto wrote: > > Not sure if this is intended behaviour: > user=> (= (float 1.6) (double 1.6)) > false >

Re: Set equality bug?

2015-01-22 Thread Nicola Mometto
Not sure if this is intended behaviour: user=> (= (float 1.6) (double 1.6)) false user=> (= (float 1.5) (double 1.5)) true I.e. = (and ==) will return true when comparing floats with doubles IFF the float's .doubleValue roundtrips to the same double it's comparing to. user=> (.doubleValue (float

Re: Set equality bug?

2015-01-22 Thread Jozef Wagner
More on this behavior http://dev.clojure.org/jira/browse/CLJ-1036 On Thu, Jan 22, 2015 at 2:00 PM, Nicola Mometto wrote: > > Looking at the PHM impl, this looks like it's caused by (float 0.5) and > (double 0.5) hashing differently. > > user=> (= (float 0.5) (double 0.5)) > true > user=> (map ha

Re: Set equality bug?

2015-01-22 Thread Nicola Mometto
Looking at the PHM impl, this looks like it's caused by (float 0.5) and (double 0.5) hashing differently. user=> (= (float 0.5) (double 0.5)) true user=> (map hash [(float 0.5) (double 0.5)]) (1056964608 1071644672) Nicola Mometto writes: > Looks like it's a bug in PersistentHashMap: > user=> (

Re: Set equality bug?

2015-01-22 Thread Nicola Mometto
Looks like it's a bug in PersistentHashMap: user=> (contains? (hash-map {:a (float 0.5)} 1) {:a (double 0.5)}) false user=> (contains? (array-map {:a (float 0.5)} 1) {:a (double 0.5)}) true Immo Heikkinen writes: > (= (float 0.5) (double 0.5)) > => true > (= #{(float 0.5)} #{(double 0.5)}) > =>

Set equality bug?

2015-01-22 Thread Immo Heikkinen
(= (float 0.5) (double 0.5)) => true (= #{(float 0.5)} #{(double 0.5)}) => true (= {:a (float 0.5)} {:a (double 0.5)}) => true (= #{{:a (float 0.5)}} #{{:a (double 0.5)}}) => false Tested with both 1.6.0 and 1.7.0-alpha5. -- You received this message because you are subscribed to the Google Gro

Re: if-not implementation

2015-01-22 Thread Jan-Paul Bultmann
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