This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-18
Channels
- # beginners (22)
- # boot (12)
- # cider (3)
- # cljs-dev (12)
- # cljsrn (8)
- # clojure (101)
- # clojure-nl (5)
- # clojure-russia (13)
- # clojure-spec (5)
- # clojure-uk (15)
- # clojurescript (158)
- # cursive (5)
- # datascript (16)
- # datomic (8)
- # hoplon (11)
- # lumo (33)
- # off-topic (3)
- # om (25)
- # parinfer (1)
- # pedestal (8)
- # protorepl (4)
- # re-frame (8)
- # reagent (5)
- # specter (18)
- # sql (1)
- # testing (11)
- # timbre (1)
- # unrepl (2)
- # untangled (1)
@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.
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.
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.
Depending on the code it can be pretty high. Some code I've worked on runs about 50% slower with debugging enabled.
hello guys, i know this has nothing to clojure, but am curious with java streams, how can make the following code more functional
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 ())
dont know what you mean by counter, to me a counter it something/somewhere to store the result or partial result of counting
i guess from your code, it meant to convert a list to a map
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]))
["0" "1" "2"] => {1991 0f 1992 1f 1993 2f}
its fine to use imperative for in this case, i think it read better, as stream doesnt have a zip with index
(let [copyOfRange ["1.0" "2.0"]] (into {} (map vector (iterate inc 1990) (map #(Float/parseFloat %) copyOfRange))))
Map<Integer, Float> myUsage = new HashMap<>(); int year = 1990; for(String myValue: copyOfRange) { myUsage.put(Integer.valueOf(year++), Float.valueOf(myValue)); }
Is it possible to catch multiple exceptions in the same clause as in java catch (SomeException|Another e)
?
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...
@billbarnhill do you have a stracktrace?
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
Sorry for response delay, pulled afk by 12 yr old daughter waking up 🙂
@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
missed
@paulocuneo So a curious thing. If I execute the commands within make-questions-table directly in the repl, they work. No exception.
Silly thought, but is the [] ( at end of (defn make-question-table [] ( somehow getting treated as a key to a vector?
i dont think so, maybe the exception is happening somewhere else, the fn seems fine
Thanks for the patience. Literally my first day coding with Clojure
scratch.clj line 7 ?
db should be a map, is it?
i see it!
(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))))
Function application: (some-function args) , example (inc 1) But since clojure have expression you could do something like this: ((if sunny inc dec) 1)
Yep, that did the trick. Thank you very much..I likely would have banged my head on that for quite a while
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?
is it normal that creating a new project using a template (for example chestnut) doesn't normally add anything about logging?
and for example running lein ring server
I then get the usual: log4j:WARN Please initialize the log4j system properly.
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
@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...
@andrea.crotti chestnut should come with ring logging middleware, look at log/server.log
@plexus right, but something in that setup is trying to use log4j and finding it unconfigured
not ring, but something...
ring itself definitely doesn't use log4j directly
@andrea.crotti at least this won't break request logging - because the ring middleware sets that up and won't use log4j
it's probably the webserver backend or a db adaptor or something
Hmm, if I do (type q) and it gives me clojure.lang.LazySeq, how do I convert that LazySeq to a value?
never mind! I was wrong
yeah I always saw that when I ran lein ring server
so I assumed it was related
https://github.com/pjlegato/ring.middleware.logger/blob/master/src/ring/middleware/logger.clj#L8
line 8 there is where the ring middleware tries to use log4j
so in short what's the "suggested" way to set up logging in Clojure projects?
yeah - if chestnut wants you to use that middleware, it should ship with a sensible log4j config
Just because I've never done it before
just log4j?
@andrea.crotti the whole thing is a mess, I don't even know how to do it right frankly
I just have a few approaches that are each 9/10 OK
using a log4j properties file
or using a wrapper via timbre
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
ah btw I just checked again in Chestnut and I found the properties file https://github.com/plexus/chestnut/blob/fa2764cfeb3bd0df80a244dbb8cc47f29b903c2d/src/leiningen/new/chestnut/resources/log4j.properties
and creating a new one places it in resources/
so it's actually just this project that I didn't originally create with Chestnut my bad
oh, that's better then
I'll have a look at timbre
thanks
timbre can control things like log4j via https://github.com/fzakaria/slf4j-timbre
and then sl4j has a DI in project.clj to control log4j, and that mostly works
is there something like range
, but instead of specifying end, I specify the start, and get a lazy infinite list ?
(iterate inc 2000)
Range can do that
So give it an end of Double/MAX_VALUE
this is weird becuase I think of range as ranges of ints, but then we specify a DOUBLE as the end
Range takes any numbers
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”]
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?
(map #(vector (keyword (first %)) (second %)) [ [”2312323” “blabla1”] [”45345345” “blabla2”] ... ])
Thanks @bherrmann ! I’ll give it a try
Is there a reason that ‘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
@xiongtx I don’t know about the reason for SortedMap, but Queue is an intrinsically mutable interface and PersistentQueue is immutable.
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
dunno, what about lein or boot?
or just a main that does run-all-tests
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.