Fork me on GitHub
#clojure
<
2017-03-18
>
cfleming01:03:26

@hiredman swank-inject looks nice, thanks - I was wondering whether the JDI would be a solution. I’m pretty sure that it’s not on by default though, even after JDK 5.

hiredman01:03:12

Oh, I expect you would know more about that than me

cfleming01:03:00

I actually don’t know what the performance hit is of always running a process under the debugger, if you don’t have any breakpoints etc set.

cfleming01:03:40

Something that a lot of people have asked for is the ability to always see locals on an exception, and JDI is pretty much the only way to do that.

tbaldridge02:03:24

Depending on the code it can be pretty high. Some code I've worked on runs about 50% slower with debugging enabled.

devn03:03:15

This is my experience also

Pishty03:03:14

hello guys, i know this has nothing to clojure, but am curious with java streams, how can make the following code more functional

paulocuneo04:03:17

your code seems wrong. the key is always the same. "More Functional" than what? Optional.ofNullable(copyOfRange) .filter (list-> !list.isEmpty ()) .map(list -> list.get(x.size()-1)) .map(singleElem -> { Map m = new HashMap (); m.put (1991, Float.valueOf(singleElem)) return m; }).orElse(new HashMap ())

Pishty04:03:43

hey man thank u for the answer

Pishty04:03:17

yes the code was wrong, but i would like to know how to implement counters

Pishty04:03:19

using the stream apis

paulocuneo04:03:51

dont know what you mean by counter, to me a counter it something/somewhere to store the result or partial result of counting

paulocuneo04:03:40

i guess from your code, it meant to convert a list to a map

paulocuneo04:03:55

something like : IntStream.range (0, copyOfRange.size()) .mapToObj(i-> new Object [] {1990 + i, Float.valueOf(copyOfRange.get(i)) }) .collect (Collectors.toMap (arr -> arr [0], arr-> arr [1]))

paulocuneo04:03:08

["0" "1" "2"] => {1991 0f 1992 1f 1993 2f}

paulocuneo04:03:13

its fine to use imperative for in this case, i think it read better, as stream doesnt have a zip with index

paulocuneo04:03:46

(let [copyOfRange ["1.0" "2.0"]] (into {} (map vector (iterate inc 1990) (map #(Float/parseFloat %) copyOfRange))))

Pishty04:03:55

the clojure version is nice

Pishty03:03:18

Map<Integer, Float> myUsage = new HashMap<>(); int year = 1990; for(String myValue: copyOfRange) { myUsage.put(Integer.valueOf(year++), Float.valueOf(myValue)); }

yonatanel08:03:09

Is it possible to catch multiple exceptions in the same clause as in java catch (SomeException|Another e)?

istvan09:03:47

you can modify the macro to support the java 8 syntax

billbarnhill13:03:12

Just starting Clojure..can someone tell me why executing (helloworld.core/make-questions-table) in the lein repl throws the exception "IllegalArgumentException Key must be integer clojure.lang.APersistentVector.invoke (APersistentVector.java:292)" after loading a file containing this snippet...

yonatanel13:03:55

@billbarnhill do you have a stracktrace?

billbarnhill13:03:49

No, apparently. How can I get one from within lein repl? Java I’d wrap it in try catch and do ex.printStackTrace(), but no idea with clojure

billbarnhill13:03:19

Sorry for response delay, pulled afk by 12 yr old daughter waking up 🙂

paulocuneo13:03:19

@billbarnhill vectors and map support function interface, but vectors requires keys to be integer, some in ther e a vector is recibing a non integer key

billbarnhill13:03:50

@paulocuneo So a curious thing. If I execute the commands within make-questions-table directly in the repl, they work. No exception.

billbarnhill13:03:38

Silly thought, but is the [] ( at end of (defn make-question-table [] ( somehow getting treated as a key to a vector?

paulocuneo13:03:28

i dont think so, maybe the exception is happening somewhere else, the fn seems fine

billbarnhill13:03:02

Thanks for the patience. Literally my first day coding with Clojure

paulocuneo13:03:56

scratch.clj line 7 ?

paulocuneo13:03:15

db should be a map, is it?

paulocuneo14:03:57

(defn make-questions-table [] ( <-- this parens is trying to use the result of the execute! expression as a function (sql/execute! db ["drop table if exists countries"]) (let [cs (sql/create-table-ddl :countries [[:id :integer :primary :key :autoincrement] [:name :text] [:capital :text]])] (sql/execute! db cs))))

paulocuneo14:03:39

Function application: (some-function args) , example (inc 1) But since clojure have expression you could do something like this: ((if sunny inc dec) 1)

billbarnhill14:03:09

Yep, that did the trick. Thank you very much..I likely would have banged my head on that for quite a while

lvh15:03:59

I’m using core.match and I have a few rules that are almost the same. I match on a regex, something like #”abc-(p|q|r)-xyz” — the response is almost identical, I just need to know what that captured group was. Is there an elegant way to use I guess guards + function applications? In what order do they apply?

lvh15:03:59

Oh, I forgot about :as

andrea.crotti16:03:41

is it normal that creating a new project using a template (for example chestnut) doesn't normally add anything about logging?

andrea.crotti16:03:59

and for example running lein ring server I then get the usual: log4j:WARN Please initialize the log4j system properly.

andrea.crotti16:03:56

I just wanted to see ring logging all the requests that were done, and normally in other languages the default would be at least to log out to standard output

noisesmith16:03:50

@andrea.crotti yeah, the logging situation on the jvm is a total mess, and packages have a dilemma - they can assume you haven't configured logging, and then break everything if you were trying to use some other logging setup, or assume you will set up logging, which will be broken until you do so. I guess the template is timid about setting up your logging...

plexus16:03:18

@andrea.crotti chestnut should come with ring logging middleware, look at log/server.log

noisesmith16:03:45

@plexus right, but something in that setup is trying to use log4j and finding it unconfigured

noisesmith16:03:49

not ring, but something...

noisesmith16:03:09

ring itself definitely doesn't use log4j directly

plexus16:03:45

Yeah, totally possible. An issue on the chestnut github for this would be appreciated

noisesmith16:03:47

@andrea.crotti at least this won't break request logging - because the ring middleware sets that up and won't use log4j

noisesmith16:03:13

it's probably the webserver backend or a db adaptor or something

billbarnhill16:03:14

Hmm, if I do (type q) and it gives me clojure.lang.LazySeq, how do I convert that LazySeq to a value?

noisesmith16:03:16

never mind! I was wrong

andrea.crotti16:03:16

yeah I always saw that when I ran lein ring server so I assumed it was related

noisesmith16:03:34

line 8 there is where the ring middleware tries to use log4j

andrea.crotti16:03:29

so in short what's the "suggested" way to set up logging in Clojure projects?

noisesmith16:03:30

yeah - if chestnut wants you to use that middleware, it should ship with a sensible log4j config

andrea.crotti16:03:40

Just because I've never done it before

noisesmith16:03:53

@andrea.crotti the whole thing is a mess, I don't even know how to do it right frankly

noisesmith16:03:06

I just have a few approaches that are each 9/10 OK

noisesmith16:03:14

using a log4j properties file

noisesmith16:03:20

or using a wrapper via timbre

noisesmith16:03:30

you could use a different middlware that doesn't assume log4j - it would be easy to write if it doesn't exist yet, but I'm sure it's out there

andrea.crotti16:03:06

and creating a new one places it in resources/

andrea.crotti16:03:36

so it's actually just this project that I didn't originally create with Chestnut my bad

noisesmith16:03:45

oh, that's better then

andrea.crotti16:03:22

I'll have a look at timbre

noisesmith16:03:27

timbre can control things like log4j via https://github.com/fzakaria/slf4j-timbre

noisesmith16:03:29

and then sl4j has a DI in project.clj to control log4j, and that mostly works

qqq16:03:56

clojure how do I say hide 'get' from clojure.core ?

qqq17:03:05

(I have a namesapce in which get is redefined to something else)

bronsa17:03:20

(:refer-clojure :exclude [get]) in your ns decl

qqq17:03:40

thanks; I was googling for "hide" not "exlcude", and not getting anything

qqq18:03:57

is there something like range, but instead of specifying end, I specify the start, and get a lazy infinite list ?

paulocuneo20:03:06

(iterate inc 2000)

tbaldridge18:03:55

Range can do that

qqq18:03:07

(range)(range end)(range start end)(range start end step)

qqq18:03:20

There isn't one for specifying only the start.

qqq18:03:33

however, TIL there is (range) which starts from 0

tbaldridge18:03:02

So give it an end of Double/MAX_VALUE

qqq18:03:23

wow; that worked

qqq18:03:25

I can't believe it

qqq18:03:51

this is weird becuase I think of range as ranges of ints, but then we specify a DOUBLE as the end

tbaldridge18:03:22

Range takes any numbers

jmp19:03:52

Hi Clojurians! I’m here with another super noobie questions. I have a function that gives me a sequence of vectors with two strings in it, as in: [”2312323” “blabla1”] [”45345345” “blabla2”] [”7547545” “blabla3”] [”574535” “blabla4”]

jmp19:03:10

and so on for many many of them

jmp19:03:57

So my question would be: How do I manage to iterate on each one of them? Let’s say if I wanted to change the first string in each vector to a keyword or remove one of the strings in the vector for example?

bherrmann20:03:00

(map function-to-produce-replacement-element collection)

bherrmann20:03:08

(map #(vector (keyword (first %)) (second %)) [ [”2312323” “blabla1”] [”45345345” “blabla2”] ... ])

jmp20:03:56

Thanks @bherrmann ! I’ll give it a try

xiongtx20:03:53

Is there a reason that clj‘s sorted maps don’t implement the SortedMap interface, and PersistentQueue doesn’t implement the Queue interface? https://docs.oracle.com/javase/8/docs/api/java/util/SortedMap.html https://docs.oracle.com/javase/8/docs/api/java/util/Queue.html

lvh20:03:51

@xiongtx I don’t know about the reason for SortedMap, but Queue is an intrinsically mutable interface and PersistentQueue is immutable.

lxsameer20:03:37

hey folks, I'm looking for a fast and easy to use test runner for clj and cljs , any recommendation ? a test env setup recommendation would be awesome

paulocuneo21:03:31

dunno, what about lein or boot?

paulocuneo21:03:46

or just a main that does run-all-tests

paulocuneo21:03:23

i do use cider, and had some issues with reloaded code, where test keep failing after code has changed. Workaround it by switch to test-ns and running test in there.