This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-25
Channels
- # admin-announcements (2)
- # beginners (36)
- # boot (37)
- # cider (65)
- # cljsrn (92)
- # clojars (3)
- # clojure (225)
- # clojure-austin (5)
- # clojure-belgium (2)
- # clojure-brasil (3)
- # clojure-china (1)
- # clojure-greece (2)
- # clojure-mexico (3)
- # clojure-news (2)
- # clojure-quebec (1)
- # clojure-russia (14)
- # clojure-spec (24)
- # clojure-uk (53)
- # clojurescript (34)
- # cursive (14)
- # datascript (9)
- # datomic (4)
- # defnpodcast (8)
- # devcards (30)
- # dirac (7)
- # editors (7)
- # emacs (1)
- # figwheel (1)
- # hoplon (85)
- # immutant (2)
- # incanter (1)
- # luminus (5)
- # off-topic (41)
- # om (18)
- # onyx (11)
- # perun (2)
- # re-frame (11)
- # reagent (9)
- # ring (3)
- # spacemacs (2)
- # spirituality-ethics (1)
- # test-check (19)
- # testing (12)
- # untangled (14)
- # yada (9)
I'm working on a project where there are different test paths under different profiles. Is this a common paradigm? Right now cider can't run these tests in the project when you say run all tests in project, and i'm wondering if this would be a common request for people, or if tests under different profiles isn't that common of a setup
Anyone know the best posgres lib for Clojure?
just look for a decent JDBC/SQL library. What postgres specific stuff would you need in a Clojure lib?
@dpsutton: this is something you can do pretty well, but yes, you'll need to write some logic that handles this
Is there a more Clojure-y version of TimeLimiter - https://google.github.io/guava/releases/snapshot/api/docs/com/google/common/util/concurrent/TimeLimiter.html If you’re unfamiliar with the library, the concept is limiting the amount of time functions can run and giving them, essentially, a timeout value. So I’m interested in something along the lines of:
(limit my-function 5000 “default-value”)
Which I’d expect to run my-function
, and if it doesn’t return in under 5 seconds, returns the string “default-value” instead.Ah, thanks! I wasn’t aware of the deref w/ timeout option, that looks pretty perfect.
just be carefull with future, it uses an cachedthreadpool (basically an unbounded thread pool)
let's say you had a java method that took java lambdas as an argument, how would you pass it clojure functions instead?
@josh_tackett: Please have a look at https://github.com/bsvingen/squirrel
anyone use expectations
for testing? have this dummy test
(let [x 10]
(expect 20 x))
(let [x 20]
(expect 20 x))
expect
expands to a defn
so having it inside a let
may well confuse the symbol generation it uses for the name.
and
is a macro, so you may need to do something like (reduce #(and %1 %2) [true false true])
contains?
is only for sets and maps.
(contains? [:a :b :c :d] 2) ;=> true)
because vectors are associative collections with integer indices as keys.
The minimal case I can reduce it to is if there’s a string of a certain length (only happing to me when it’s around 140+ bytes long) transit-clj fails to decode msgpacked data if the string is stored like D9 <len>, but works if it’s encoded as DA 00 <len>,
msgpack can read the data though, so it seems to be something specific to transit parsing
does anyone have an idea where I should look? Or do I just need to report a bug to transit-clj?
Maybe @alexmiller can point in the right direction if he's around
Best to file an issue on transit-clj
Then everyone gets notified
If you have a simple repro that would be ideal
I'm trying to use a transducer to do some work on some meshes. I have something like (transduce (map first) min (:collision-mesh player))
i could provide an init value, but it would look ugly. I would need to select the highest number possible, to ensure that it is immediately replaced in the reduction
another approach would be to let the init be the first (or any) value of the collision-mesh, which feels a little better but still feels kind of wonky
In the initial value case you could use Long/MAX_VALUE or double or whatever is appropriate
There is a actually a monoid function in the reducers namespace that can also be used to patch in the no arg case iirc
its a shame that min doesn't have a 0 arity that defaults to the maximum value representable
I'm aware of completing but I thought we were talking about 0 arity
It's for this need - adding the 0 arity to a reducing function
i had considered taking the first value as the init, and letting the collection that the transducer operates on be the "rest"
that feels a little better, but i was just wondering if you guys have ever used transducers this way
so right now i'm considering (transduce (map first) min (first (:collision-mesh player)) (rest (:collision-mesh player)))
i like being able to just tell what code does without thinking about what i'm looking at, and the transducer here is better than the hard-coded init type, but it isn't quite as good as i'd like
Do you need transduce at all?
You could just min of map first?
what did you have in mind? what would i gain from doing a (reduce fn init (map first (:collision-mesh player)))
(apply min (map first (:collision-mesh player)))
?
(reduce min (map first (:collision-mesh player)))
?
that one’s probably more efficient
than apply
the reason i figured on using transducers in the first place was trying to come up with something more efficient than reduce
apply is going to build an intermediate sequence before applying
I don’t think so?
oh, well apply will be one more
transduce would be better, but you just need to cover the initial case
i think i'll just put it in a let and do [some-point (first (:collision-mesh player)) other-points (rest (:collision-mesh player))
that first/rest can be destructured
(let [[f & r] (:collision-mesh player)] (transduce (map first) min f r))
more compact, should be same efficiency-wise
i'd like to ask a different question, do you guys think this is an abuse of transduce?
nope, makes sense
no, it’s fine
for the reasons you mentioned above - you want to make a single pass through the input, map out the first of each, and then use min to decide which to keep
so it’s more efficient than either the reduce or apply versions above
so, I’d say: not hacky, but good use
the non-0 arity of min was the only sticking point
but that’s not something that can be done (as min is polymorphic across all number types)
If you wanted to you could wrap min' in a function that answers for the 0-arity case, but that's the hacky version compared to what's been suggested
then the first seems equally good :)
but that is specific to min perhaps, and the fact we chose "first" or "last" is an arbitrary choice
that is the apply version
i think the point of transducers, besides efficiency, is decomplecting process from data
i feel its a good policy to make your algorithms no more specific than they have to be
how many of these things things are there?
and have you actually considered reducers?
b/c they can fold in parallel, giving you additional gains if you have a lot of values
where “lot” is probably at least 1k
yeah i'm considering that, but given the fact that at the "highest level" most of my transducers are composed entirely of maps
It seems like you may need to make a decision between the most performant solution and the most philosophically correct
I like the transduce personally :)
Silly question, but isn't there a name/concept in clojure for an item that's not a collection? Similar to Lisp atoms?
Well, independent of context, I think. The set includes numbers, strings(?), symbols, keywords, characters, (and what else?)
It's fair to just use the lisp terminology, but of course most people will think clojure atoms are something else
mmm I don't think there is something analogous to atom?
you can maybe fabricate your own with symbol?
keyword?
...
Things that are not collections are typically called either symbols (+, defn, and) or values/literals (7, "foo", :keyword). I'm not sure there's an official universal term for everything, and if there is it's not widely used.
But there would be no reason for a predicate to exist to test it, because any possible parameter would return true.
@em also in Clojure these checks are based a lot on the underlying Java Interface (not saying this is good, but it is what it is) -> http://clojuredocs.org/clojure.core/coll_q
hrmph. apparently (reduce min (map first coll)) isn't the same as (transduce (map first) min (first coll) (rest coll))
for instance, if i use [[0 0] [0 1] [1 0] [1 1]] as the coll, i'll get a class cast exception
the extra first is required because the "init" isn't passed through the transducer (the map to first in this case)
i have more complex ones, and I don't want to have to push a single value through it all the time
@bcbradley: that makes sense, the transducer will only be called on a collection, and init
isn't always going to be the collection
in other words, you really want the init to be pushed through the fun, but transduce isn't doing that.
transducers are functions of reducing functions, not individual values. this has less to do with transduce and more to do that you can't give the reducing function (min) a sensible init value
if you really want to use transduce with this case:
(transduce (map first) min Long/MIN_VALUE coll)
that way there is something for the first element of coll to be compared to, and it will always win
i don't like it because i may not necessarily know the type of the number in the mesh
i suppose i could create my own transduce that wraps the standard transduce, converts the init into a single element collection, performs the transduction on it to generate an single element sequence that contains the init, and use first to pass it to the standard transduce
gotcha. polymorphic math costs will dominate anything you're worried about wrt transduce
i'm using this specific pattern 8 times alone in just this one function. I'd say probably about 12% of all the lines of code i'm writing is this exact pattern
most of the collisions code i've seen written doesn't aim for strict reproducability
the tiny errors that occur in floating point ops generally doesn't matter in most applications because they don't accumulate
there is a concept in math called chaos, it means that tiny changes in the initial conditions result in enormous changes in final conditions
and that it isn't possible to ascertain the difference in the final based on the difference in the initial
the "gotcha" of floating point ops isn't that they error, its that the error between two computers may be different
they serve as an authority on the state of the game, so that diverging simulations know what the "true" state ought to be
if you've ever played a game and had a brief glitch where your avatar sort of tunneled through a wall , moved all wonky and then finally started acting normal
thats what happens when the client simulation and server simulation get vastly out of sync
i want to avoid that so that I can have a wide peer to peer network infrastructure with no central server
i figured i could avoid the floating point chaos at first by asking for a majority consensus on the state