This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-03
Channels
- # admin-announcements (6)
- # beginners (73)
- # boot (84)
- # cider (9)
- # cljs-edn (5)
- # cljs-site (8)
- # cljsrn (2)
- # clojure (158)
- # clojure-austin (1)
- # clojure-canada (1)
- # clojure-dusseldorf (2)
- # clojure-ireland (1)
- # clojure-russia (45)
- # clojure-sg (2)
- # clojure-uk (28)
- # clojurebridge (2)
- # clojurescript (142)
- # core-async (43)
- # cursive (23)
- # datascript (5)
- # datomic (9)
- # dirac (4)
- # emacs (23)
- # funcool (1)
- # garden (1)
- # hoplon (280)
- # jobs (1)
- # ldnclj (6)
- # leiningen (37)
- # luminus (6)
- # om (30)
- # om-next (1)
- # onyx (6)
- # perun (24)
- # re-frame (10)
- # reagent (20)
- # remote-jobs (1)
- # rethinkdb (2)
- # ring-swagger (4)
- # rum (3)
- # spacemacs (6)
- # untangled (36)
- # yada (5)
Has anyone written a blog post on all pain you cause for downstream apps/libraries if you AOT compile your library.
is there any way to get IntelliJ/Cursive to run “lein autotest” or something similar in the background? I’m specifically looking for an option to run all tests in a project in a clean environment and getting clickable errors so I can navigate to failing tests/inspect output etc.
Switching over to #C0744GXCJ
yeah but that 1) requires manually starting tests after every change 2) runs only the current namespace or test 3) does not reload / refresh the application state
@joost-diepenmaat: poke @cfleming in #C0744GXCJ
@joost-diepenmaat: There’s nothing like this right now, sorry, although it’s something that has been requested frequently.
I was hoping there would be some workaround involving lein test-out or something similar that outputs junit xml results
Sadly, not that I’m aware of. There may be something in IntelliJ that supports that.
I’m completely new to intellij so it’s hard to figure out how all of this is hanging together. A complete test runner for clojure would be nicest ofcourse
@joost-diepenmaat: why the switch? I've been going back and forth between emacs and Intellij myself
Mostly because I’ll be giving a workshop on clojure and the candidates are already familiar with IntelliJ and I don’t want to waste precious time teaching them Emacs
@joost-diepenmaat: that was often my main reason too, interoperability between colleagues
So I’m going to use IJ for a few weeks to get myself up to speed.
also I find it easier to navigate between files/overview the whole project in Intellij, but that must be because I'm still an emacs n00b after 5 years 😉
@joost-diepenmaat: Let me know in #C0744GXCJ if you have issues or more questions.
@cfleming: thanks I will
I could do with some help, but future revenue is a bit uncertain for that right now. I’m going to get some contract help for specific things, probably.
can anyone recommend a simple key/value store for clojure? i basically need on-disk hash tables, low volume, easy deployment.
redis?
oh, on-disk
@bojan.matic: looks server based? i'm really looking for something that is colocated with my clojure code, in the same jvm
@bojan.matic: i don't even need concurrent access
cassandra, riak or couchdb then? haven't used any, though
datascript?
@bojan.matic: thanks for trying.
@borkdude: if all fails. but i'm rather amazed that something as simple as that is not just available somewhere.
@hans: No experience with it, but Immutant caching has persistance option and it shouldn't need a server.
@hans immutant.web is pretty slim. Not sure about other stuff. The infinispan (cache) jars shouldn't be too big though.
@hans: That was the previous incarnation of Immutant. They rewrote everything and now it is awesome.
Hi all! Could someone help me, I’ve got a lot of loop in my tests, I would really like to be able to stop doing tests after the first failure of my test.
@hans: or what about: https://github.com/alandipert/enduro
@yogsototh: I haven't tried it, but you might be able to do it with reduce
and reduced
@codonnell: thanks, I’ve never heard about reduced
If you call (reduced x)
from within a reduce
, it will short-circuit and return the value x
It's amazing what the atom abstraction can accomplish (thinking of Reagent and the library I just mentioned)
I'm not sure how you would extract the test success/failure, but that's the only way I know of short-circuiting a "loop" in clojure. I suppose you could also use loop-recur.
system
is redesigning one of its core features, code reloading. This is a very exciting time to contribute. We currently have a challenging issue open on github. Everybody is welcome, although I have to admit that this is probably most suited for experienced Clojure developers with a firm grasp of the runtime internals. https://github.com/danielsz/system/issues/79
Hello. im loading a json in my function, extracting some parameters and assigned to a variable. When i call another function using this variable, i get the below exception: "ClassCastException clojure.lang.LazySeq cannot be cast to java.lang.CharSequence clojure.string/split (string.clj:219)”. How to overcome this?
Hello everyone, I wondered if anyone would know why this (clojure.edn/read-string "00012345")
returns 5349
? I looked at the source for clojure.lang.EdnReader but it’s making my eyes bleed.
@shreyas.n: you're trying to treat a sequence of chars as a string
@bronsa : looks like it. but my origin problem seems to be that when i pass this variable (a vector) to a function, its a lazy sequence. My function does not get processed.
@shreyas.n: I've finished my task using Apache Derby and it worked just fine.
@shreyas.n: but i'll have a look at mapdb, maybe next time.
For anyone wondering, yesterday when I was asking about how to get CSS/JS files found in a Compojure/Ring/Selmer app, we tried all sorts of ideas to solve the 404's I was getting. Turned out to be simple: (route/resources "/"). Don't know how I missed that. Oh, well.
how can I make this error RuntimeException Conditional read not allowed clojure.lang.Util.runtimeException (Util.java:221)
go away when doing (read-string with reader-conditionals ?
hi guys, what is an efficient way to find the index of the minimum key in a seq ? some thing like (min-fn [1 23 0 9 1 -1]) ;; => [-1 5]
, 5 is the index of -1 in the seq
@jr ahah...but i still get the error with {:read-cond true} ?
nxqd: here’s one way, which is O(n), which seems like the most efficient you’re going to get it:
> (defn min-fn [coll] (reduce-kv #(cond (nil? (seq %1)) [%3 %2] (> (first %1) %3) [%3 %2] :else %1) [] coll))
#’user/min-fn
> (min-fn [1 23 0 9 1 -1])
[-1 5]
>
granted, that assumes vectors
for seqs I suppose you’d need something with loop
/`recur`, but perhaps someone more clever than I can figure out a way to do it with reduce, for example
(first (apply min-key second (map-indexed vector [5 3 1 0])))
@nxqd: @ddellacosta: what about map-indexed?
@taylor.sando: isn’t that going to go through the collection twice?
I guess it would be n^2 time.
yeah, I can’t see how you’d do it with map-indexed
without making it at least O(n*2). I think you need a reduce/fold operation here regardless
What is the preferred mustache templater in clojure these days? Is it clostache, stencil or something else?
@taylor.sando, @ddellacosta how about using map-indexed with 2 atom to track index and value ? I'm not so sure about the cost of deref and reset!
or hbs?
that's why I asked if he needed concurrency. if you use only 1 thread you're safe right?
Here's my stab at it.
(defn min-fn [coll]
(rest (reduce (fn [[index min-value min-index] x]
(cond
(nil? min-value) [(inc index) x index]
(< x min-value) [(inc index) x index]
:default [(inc index) min-value min-index])) [0 nil nil] coll)))
yeah, I was imagining something more like what jjfine just posted ^
I’d stay away from atoms and whatnot when this is perfectly solvable using clojure immutable data structures
or volatile!
rather
but, depends on what you’re after I guess
Oh, here's something using transducers and map-indexed, @nxqd
cljs.user=> (transduce (map-indexed (comp reverse vector)) min [1 2 3 -1 9])
; (-1 3)
Edit: Doh! This works only in ClojureScript (testing in Planck), min
yells at you in Clojure 😞!reverse
there is because min
on vectors seems to look at the first element. With reverse
, you get [val idx] out of map-indexed
.
@jr afternoon tiredness - got it thanks so much
xposting from #C06GSN6R2: I'm having an issue with sending an array as a path-params request [2:11] The request looks like this [2:11] curl -X GET --header 'Accept: text/html' 'http://localhost:3000/product-api/list/by-categories/259,260' [2:11] Passing individual categories works fine, but multiple ones gets me a 404 error with exception throwing whatsoever
no exception throwing*
The other issue is that the function the service is calling works just fine
that's the endpoint
compojure api doesn't seem to
If I put 259,260 it does
Like, in the text box
But not if I put it as it asks, one per line (in the Swagger API page)
I think the error is in the endpoint per se
If I search by one category, it goes in the function and performs
If I search by 2, it breaks
Hi, wats the best way to check if there is only occurrence of an element in a collection, is filter
followed by count the right way?
I got it, I just made the service take one string and split it later
@ddellacosta @taylor.sando: map-indexed
is lazy, so would min-key
on a lazy list still be O(N^2)? Or O(N)?
@fasiha: I don’t think laziness is relevant here, because you have to evaluate the entire sequence to determine which value is least
@ddellacosta: right, so min-key
will definite be O(N). I'm wondering if adding map-indexed
into the mix makes it N^2 or 2*N, or if it remains O(N)
@fasiha by my calculations you are doing O(n) once in map-indexed
, then you do O(n) once more when you do (apply min-key second …)
, so O(n*2)
That would certainly be the case if map-indexed were eager, i.e., creating a new list of N 2-tuples first. But since it's lazy, wouldn't it hand min-key the elements of that new list one at a time?
@fasiha: if all the values are realized in the lazy seq that map-indexed returns, then I don’t see how you can get past it being O(n) (map-indexed) + O(n) (apply min-key)
would like to be corrected if I’m wrong though
laziness only helps us if we aren’t doing evaluation
and the answer looks like its a no
@micahasmith: try in #C05423W6H
oh cool thx
Hi, Given the following Method signature in Java, how could I invoke it (It would be on the Singleton class)
static void connect(java.lang.String protocol, java.lang.String host, short port, java.lang.String user, java.lang.String password, boolean setupSSL)
Create a connection to the specified Opsware Server.
In JRuby I do something like this to cast the proper Java types:
def initialize
@connection = Sasync::OpswareClient
@retries = 2
end
def connect
@connection.connect("https".to_java(:string), Sasync.server.to_java(:string), Sasync.port.to_java(:short), Sasync.user.to_java(:string), Sasync.password.to_java(:string), true.to_java(:boolean))
@connected=true
end
nm. Found the way to cast it:
(ns cljsa.core
(:import [com.opsware.server ServerRef ServerService]
[com.opsware.client OpswareClient]))
(def client OpswareClient)
(defn connect []
(. OpswareClient (connect "https" "someip" (short 443) "user" "password" true)))
There's also the (Classname/staticmethod args)
form:
(defn connect []
(OpswareClient/connect "https" "someip" (short 443) "user" "password" true))
Thanks. Just curious, is there any way to set a property on an object. So for example right now I have this:
(defn server-filter-new []
(let [f (new Filter)]
(.setExpression f "ServerVO.hostName CONTAINS somehostname")
(.setObjectType f "device")
f))
@dimiter (set! (.-fieldName object) "some value")
if the field is mutable and public.
Public fields are rare in Java libraries, the standard practice is to use setter methods as in your example.
Clojure also provides the doto
macro as a syntactic convenience for this common pattern.
Hey so can I get a sanity check on a chunk of code:
(def db-connection)
(defn -main [& args]
(let [{:keys [cass]} (parse-config args)]
(alter-var-root #'db-connection (fn [_] cass))))
I feel like using alter-var-root
might be a bad idea, but can anyone give me a reason why in this case?alter-var-root
isn't the problem, but I would consider it a potential source of problems to have db-connection
be a global singleton definition.
For small code bases it probably won't matter.
But if your application grows, you may want different "connection" objects at different points in the application.
That refactoring is difficult when you have references to one global db-connection
scattered throughout the code.
Agreed. It is and will probably remain a small code base, so I’m kinda okay with making it a global in this case - considered using component or mount but there’s a bit of work that would be involved in ripping apart other stuff to use it and I might not be able to get the buy in for it.
If you want to preserve some flexibility without 'Component', you could initialize the database connection in -main
and then pass it to other functions as an argument.
Yeah, we do that in a lot of other places. In this case it would have to pass through several other functions that don’t use the database in order to reach the function that does. I feel like that’s almost as bad in terms of style as using a global.