Fork me on GitHub
#clojure
<
2016-05-03
>
cddr06:05:31

Has anyone written a blog post on all pain you cause for downstream apps/libraries if you AOT compile your library.

joost-diepenmaat08:05:34

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.

joost-diepenmaat08:05:46

Switching over to #C0744GXCJ

joost-diepenmaat08:05:35

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

cfleming08:05:01

@joost-diepenmaat: There’s nothing like this right now, sorry, although it’s something that has been requested frequently.

cfleming08:05:07

So hopefully coming soon.

joost-diepenmaat08:05:22

I was hoping there would be some workaround involving lein test-out or something similar that outputs junit xml results

cfleming08:05:23

Sadly, not that I’m aware of. There may be something in IntelliJ that supports that.

cfleming08:05:37

I’m planning to add a proper test runner soon, though.

joost-diepenmaat08:05:25

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 simple_smile

cfleming08:05:45

Yes, no doubt simple_smile

borkdude08:05:01

@joost-diepenmaat: why the switch? I've been going back and forth between emacs and Intellij myself

joost-diepenmaat08:05:19

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

borkdude08:05:47

@joost-diepenmaat: that was often my main reason too, interoperability between colleagues

joost-diepenmaat08:05:02

So I’m going to use IJ for a few weeks to get myself up to speed.

borkdude08:05:03

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 😉

cfleming08:05:04

@borkdude: I don’t think that’s just you, a lot of people tell me that.

cfleming08:05:39

@joost-diepenmaat: Let me know in #C0744GXCJ if you have issues or more questions.

cfleming08:05:04

Or just comments about things that are annoying.

borkdude08:05:24

@cfleming: Are you still the only one working in cursive btw?

cfleming08:05:35

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.

hans12:05:53

can anyone recommend a simple key/value store for clojure? i basically need on-disk hash tables, low volume, easy deployment.

hans12:05:31

@bojan.matic: looks server based? i'm really looking for something that is colocated with my clojure code, in the same jvm

hans12:05:41

@bojan.matic: i don't even need concurrent access

bojan.matic12:05:00

cassandra, riak or couchdb then? haven't used any, though

hoopes12:05:10

sqlite maybe

hans12:05:21

@bojan.matic: thanks for trying. simple_smile

borkdude13:05:56

@hans: slurp/spit? 😉

hans13:05:53

@borkdude: if all fails. but i'm rather amazed that something as simple as that is not just available somewhere.

hans13:05:59

Maybe I'll try Apache Derby.

rauh13:05:25

@hans: No experience with it, but Immutant caching has persistance option and it shouldn't need a server.

hans13:05:10

@rauh: Isn't Immutant rather clunky to begin with?

rauh13:05:38

@hans immutant.web is pretty slim. Not sure about other stuff. The infinispan (cache) jars shouldn't be too big though.

danielsz13:05:58

@hans: That was the previous incarnation of Immutant. They rewrote everything and now it is awesome. simple_smile

borkdude13:05:52

@hans what do you mean available? slurp/spit was always available simple_smile

borkdude13:05:17

@hans: in combination with edn/read-string, it's all the power you need probably

yogsototh13:05:40

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.

yogsototh13:05:48

typically (doseq [x (g/sample 100 MySchema) (testing (is (= X Y)) (is = Z W)))

Chris O’Donnell13:05:31

@yogsototh: I haven't tried it, but you might be able to do it with reduce and reduced

yogsototh13:05:40

@codonnell: thanks, I’ve never heard about reduced

Chris O’Donnell13:05:24

If you call (reduced x) from within a reduce, it will short-circuit and return the value x

borkdude13:05:31

It's amazing what the atom abstraction can accomplish simple_smile (thinking of Reagent and the library I just mentioned)

Chris O’Donnell13:05:40

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.

danielsz13:05:11

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

shreyas.n14:05:30

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?

aan14:05:25

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.

conormcd14:05:43

@aan A leading zero on a number causes it to be read as octal.

borkdude14:05:46

@aan try typing 00012345 in inside a REPL simple_smile

aan14:05:30

doh! Thanks! simple_smile

bronsa15:05:52

@shreyas.n: you're trying to treat a sequence of chars as a string

bronsa15:05:10

'(\f \o \o) ¬= "foo"

mpenet15:05:03

bojan.matic: redis should do it, or even something embedded like mapdb

mpenet15:05:35

bojan.matic: cassandra and riak are not exactly "simple k/v stores"

shreyas.n15:05:48

@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.n15:05:26

i was attempting to split over a sequence before. pls ignore it.

shreyas.n15:05:44

How to overcome lazy sequence?

hans15:05:29

@shreyas.n: I've finished my task using Apache Derby and it worked just fine.

hans15:05:50

@shreyas.n: but i'll have a look at mapdb, maybe next time.

nkraft15:05:07

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.

octahedrion15:05:21

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 ?

jimmy16:05:08

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

octahedrion16:05:41

@jr ahah...but i still get the error with {:read-cond true} ?

jr16:05:13

:preserve and :allow are the read-cond values

jr16:05:53

using :allow you will have to specify a feature like :features #{:clj} to read only clj

jr16:05:08

or :preserve to get the unspliced code

ddellacosta16:05:28

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

ddellacosta16:05:47

granted, that assumes vectors

ddellacosta16:05:23

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

taylor.sando16:05:27

(first (apply min-key second (map-indexed vector [5 3 1 0])))

pithyless16:05:32

@nxqd: @ddellacosta: what about map-indexed?

pithyless16:05:46

ah, Taylor got to it first :]

ddellacosta16:05:28

@taylor.sando: isn’t that going to go through the collection twice?

taylor.sando16:05:38

I guess it would be n^2 time.

ddellacosta16:05:13

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

rickmoynihan16:05:49

What is the preferred mustache templater in clojure these days? Is it clostache, stencil or something else?

jimmy16:05:51

@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!

borkdude16:05:36

@nxqd: do you need concurrency or just a mutable value?

jimmy16:05:59

@borkdude: no, not in this case

borkdude16:05:04

@nxqd: cause there's also volatile! which is more performant

jimmy16:05:30

nice, didn't know about that, will try it out

ghadi16:05:36

note volatile is not an atomic swap

borkdude16:05:18

that's why I asked if he needed concurrency. if you use only 1 thread you're safe right?

jjfine16:05:25

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

borkdude16:05:44

but you end up in imperative/mutable world if you go that route

ddellacosta16:05:37

yeah, I was imagining something more like what jjfine just posted ^

ddellacosta16:05:05

I’d stay away from atoms and whatnot when this is perfectly solvable using clojure immutable data structures

ddellacosta16:05:24

or volatile! rather

ddellacosta16:05:29

but, depends on what you’re after I guess

borkdude16:05:22

(vreset! (volatile! 0) 1) oh boy...

fasiha16:05:52

@nxqd: practicing my loop above

fasiha16:05:50

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 😞!

fasiha16:05:09

reverse there is because min on vectors seems to look at the first element. With reverse, you get [val idx] out of map-indexed.

octahedrion17:05:39

@jr afternoon tiredness - got it thanks so much

Nicolas Boskovic17:05:52

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

Nicolas Boskovic17:05:07

no exception throwing*

Nicolas Boskovic17:05:17

The other issue is that the function the service is calling works just fine

Nicolas Boskovic17:05:04

that's the endpoint

jjfine17:05:41

do you have to urlencode the comma?

Nicolas Boskovic17:05:00

compojure api doesn't seem to

Nicolas Boskovic17:05:50

If I put 259,260 it does

Nicolas Boskovic17:05:54

Like, in the text box

Nicolas Boskovic17:05:12

But not if I put it as it asks, one per line (in the Swagger API page)

Nicolas Boskovic17:05:50

I think the error is in the endpoint per se

Nicolas Boskovic17:05:08

If I search by one category, it goes in the function and performs

Nicolas Boskovic17:05:14

If I search by 2, it breaks

Prakash17:05:45

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?

Nicolas Boskovic17:05:52

I got it, I just made the service take one string and split it later

rauh17:05:07

@pcbalodi: filter followed by second would be lazy. count realizes the entire seq.

fasiha17:05:32

@ddellacosta @taylor.sando: map-indexed is lazy, so would min-key on a lazy list still be O(N^2)? Or O(N)?

Prakash17:05:10

@rauh: oh okay, thanks simple_smile

ddellacosta17:05:33

@fasiha: I don’t think laziness is relevant here, because you have to evaluate the entire sequence to determine which value is least

fasiha17:05:11

@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)

ddellacosta17:05:59

@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)

fasiha17:05:03

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?

fasiha17:05:45

Or would min-key evaluate the entire lazy sequence before proceding?

ddellacosta17:05:27

@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)

ddellacosta17:05:32

would like to be corrected if I’m wrong though

ddellacosta17:05:06

laziness only helps us if we aren’t doing evaluation

micahasmith18:05:08

and the answer looks like its a no

dimiter20:05:47

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.

dimiter20:05:25

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

dimiter20:05:18

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

jjfine21:05:08

There's also the (Classname/staticmethod args) form:

(defn connect []
  (OpswareClient/connect "https" "someip" (short 443) "user" "password" true))

dimiter21:05:58

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

dimiter21:05:21

In Java/JRUby I just access the properties directly.

dimiter21:05:31

So I can do f.expression=“SomeExpression"

Lambda/Sierra21:05:05

@dimiter (set! (.-fieldName object) "some value") if the field is mutable and public.

Lambda/Sierra21:05:29

Public fields are rare in Java libraries, the standard practice is to use setter methods as in your example.

Lambda/Sierra21:05:03

Clojure also provides the doto macro as a syntactic convenience for this common pattern.

dimiter21:05:12

Thanks. This particular library has some fields that are public and missing setters.

lfn321:05:11

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?

Lambda/Sierra21:05:19

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.

Lambda/Sierra21:05:40

For small code bases it probably won't matter.

Lambda/Sierra21:05:12

But if your application grows, you may want different "connection" objects at different points in the application.

Lambda/Sierra21:05:36

That refactoring is difficult when you have references to one global db-connection scattered throughout the code.

lfn321:05:34

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.

Lambda/Sierra21:05:27

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.

lfn321:05:17

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.

lfn321:05:55

Thanks for the advice, I’m gonna think on it a little more before I commit to either option.

coltnz23:05:52

any interest in a another arity for file-seq ?

coltnz23:05:56

(file-seq f :dirs|:files|:children|:child-dirs)