#clojure logs

2016-01-15

02:37ulischinzhey there
02:37ulischinzi
02:40ulischinzi'm trying to transform a vector of maps to a map of vectors, maybe someone can help me
02:40ulischinzgiven [{:a 1, :b 2, :c 3, :d 4, :e 5} {:a 9, :b 8, :c 7, :d 6, :e 5}]
02:40ulischinzi'd like to get {5 [{:a 1, :b 2, :c 3, :d 4, :e 5} {:a 9, :b 8, :c 7, :d 6, :e 5}]
02:42ulischinzi tried a lot but i cant manage... best result so far was a list of vectors :)
02:42ulischinz(for [p [{:a 1 :b 2 :c 3 :d 4, :e 5} {:a 9 :b 8 :c 7 :d 6 :e 5}]] [(:e p) p])
02:44ulischinzbut thats not really what i want..
02:52qsyswhere's the 'p' comming from?
02:58Kneivaulischinz: each map has an :e that you want to use as the key?
02:59luma(group-by :e maps)
03:06ulischinzsry tel...
03:08ulischinznow... @qsys i'd say that p is each element in that array...
03:08ulischinzKneiva: exactly
03:09ulischinzluma: maps is ment to be the array of maps?
03:09lumayes
03:09Kneivaulischinz: then what luma said above.
03:10ulischinzgonna check it out
03:10Kneiva,(group-by :e [{:a 1, :b 2, :c 3, :d 4, :e 5} {:a 9, :b 8, :c 7, :d 6, :e 5}])
03:10clojurebot{5 [{:a 1, :b 2, :c 3, :d 4, :e 5} {:a 9, :b 8, :c 7, :d 6, :e 5}]}
03:10ulischinzuhhhh how nice, thank you a lot
03:27ulischinzthanks again, its workig in my dev-environment with my production data...
03:30Kneiva(inc luma)
03:30Kneiva:/
03:33yunfanwhat do you guys recommend for using clojure developing website?
04:32TEttingeryunfan: depends what you want
04:33TEttingera lot of people prefer to avoid using a stack of existing libraries that must be used together (ruby has this with rails, it has good and bad sides)
04:34TEttingerif you want a stack like that but a little more clojure-y, there's caribou
04:34TEttinger~caribou
04:34clojurebotExcuse me?
04:34TEttingerI think luminus is also a thing
04:35TEttingerotherwise, the various ring stuff may be what you're after, maybe look at how Om examples are hosted
04:35yunfanwell i dont need rails like TEttinger
04:36yunfanit should be better to use a flask like one for me
04:36TEttingerhttp://www.clojure-toolbox.com/
04:50qsysyunfan: I usually use vert.x, which is not clojure. However, client-side I like clojurescript (rum) a lot, client side, I call clojure code from Java. vert.x just makes all kind of auth, communication, ... extremely easy. vert.x 2 could handle clojure. There's a clojure implementation on the way in vert.x 3, I hope :p.
04:50qsys... server side, I call clojure code from Java...
05:09yunfanqsys: thanks
08:31neoncontrailsI think this is syntactically okay: (sql/db-do-commands "postgresql://localhost:5432/sandbox” (sql/create-table-ddl :testing [:data :text]))
08:32neoncontrailsI got it from the Heroku Clojure/Postgresql quick start guide.
08:32neoncontrailsBut I'm getting the following error:
08:32neoncontrailsBatchUpdateException Batch entry 0 CREATE TABLE testing (data text) was aborted. Call getNextException to see the cause. org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError (AbstractJdbc2Statement.java:2762)
08:34neoncontrailsHow do I call getNextException? (and on what?) I found some solutions, but the wrapper they used is since deprecated.
08:34justin_smithneoncontrails: you get the exception object e, and call (.getNextException e)
08:35justin_smithyou get that object by catching it, or in the repl, it will be bound to *e
08:36neoncontrailsThat asterick might be what was throwing me off. I'll try that
08:36justin_smithneoncontrails: *e is just the magic value in the repl
08:37justin_smithin real code you would do (try .... (catch BatchUpdateException e (println e) (println (.getNextException e)))) -- something like this
08:40justin_smithneoncontrails: also, I think the root issue is that db-do-commands does a transaction, and transactions and ddl don't mix
08:41neoncontrailsjustin_smith: weird. Let me make sure it's the same command I borrowed from Heroku
08:44neoncontrailsYeah, that's the same command as here: http://webcache.googleusercontent.com/search?q=cache:EOVSDgZ_WHgJ:https://devcenter.heroku.com/articles/clojure-web-application+&cd=1&hl=en&ct=clnk&gl=us (original seems to be down at the moment)
08:44justin_smithneoncontrails: https://clojure.github.io/java.jdbc/#clojure.java.jdbc/db-do-commands
08:46justin_smithneoncontrails: maybe ddl can be done in a transaction? anyway, getNextException will show you more info, if you catch the exception, log it, and then do the same with the nested exception
08:48neoncontrailsGood idea. Thanks for telling me about *e, I had tried it the way and couldn't understand why it wasn't working
08:48neoncontrails*the other way
10:45justin_smithamalloy_: so did that compojure GET trick with runtime symbols work?
11:32kungiI am trying to compile an uberjar and keep getting "Method too large" errors from my compojure routes ...
11:33kungiAny Idea what I might be doing wrong?
11:33tcrayford____kungi: do you have lots of routes? Do they call lots of code?
11:34justin_smithkungi: put the body of the handler in a function, and call the function in the route
11:34kungijustin_smith: I do that everywhere.
11:34justin_smithunless the problem is having thousands of routes...
11:35kungiNo not thousands. Less than 100.
11:35justin_smithkungi: are you using any macros like core.match or core.async inside the route definitions?
11:35kungijustin_smith: no
11:36kungiFirstly I wrapped all routes in a record to use them as components. Which worked fine.
11:36kungiI usually compile my application to an uberjar.
11:37kungiThen I added a small middleware function and the compilation started to fail.
11:37justin_smithmaybe it would help to make sure you are not destructuring in the route definitions, and move the destrucuring into the individual handler functions
11:37kungiSo I put all routes back into defroutes and eleminated the wrapping records etc...
11:37justin_smithor to split up the routes - you can define a set of routes as a handler
11:38kungijustin_smith: I did this. But it still fails.
11:39kungiI had the same problem a couple of days ago with my api routes (depending on compojure-api). I unwrapped them from their records and put them in compojure-api/defroutes* and it worked fine.
11:41kungiSomehow building an uberjar merges all the handlers together or ... something
11:43ikitommi_kungi: pre 1.0.0 compojure-api uses compile-time route resolution, which might cause that. With 1.0.0, the route tree is resolved at runtime. Should remove these issues
11:43kungiikitommi_: there is a 1.0.0 compojure api?
11:44kungiI am using 0.24.4
11:44ewilazarushey there guys. i need a little help with this function: http://pastebin.com/W3dDne9k - how could i break out of a for loop?
11:44MJB47you cant in clojure
11:44lumaewilazarus, for isn't a loop
11:44MJB47if you need to you can use loop recur, or reduce/reduced
11:45lumait's a list comprehension
11:45MJB47or just normal recursion
11:45ikitommi_kungi: soon, see https://github.com/metosin/compojure-api/blob/runtime-route-resolution/CHANGELOG.md#100-snapshot
11:45lumaif you want a loop, use recursion or loop/recur
11:45ewilazarusok, but in that case would i be able to break?
11:47kungiikitommi_: I'll try compiling it with 1.0.0-SNAPSHOT
11:47kungiikitommi_: 1.0.0. is not on clojars yet?
11:47ikitommi_kungi: not at clojars yet, will finalize things on weekend
11:48justin_smithewilazarus: in a loop, all you need to do is not call recur, and it won't continue
11:48lambda-11235Are clojure's symbols the same as other lisps in that they have a comparison time of O(1)?
11:48ikitommi_need to write migration guide & make better error messages.
11:49justin_smithewilazarus: if you use for, and generate a comprehension, it's lazy, so you can just top taking values from the list comprehension when you get "enough", whatever that means in your case
11:49ewilazarusjustin_smith thanks
11:49justin_smithewilazarus: also, the for list comprehension has a :while key where you can specify a condition that makes the results stop
11:49justin_smithbut it's not a loop, it's generating a list
12:20orzAre there any software engineers here who might be willing to answer a few career-related questions from someone just starting out? I promise not to take up much of your time.
12:35kungiorz: sure
12:38blake__orz: Sure.
12:42mpenetikitommi_: compojure-api looks sweet
12:43mpenetanyone cared to bench compojure routing ("clout") vs bidi for instance, I am curious?
12:58blake__I've got ClojureScript added into my Compojure project: Yay, me.
12:58bitfxaffirmative :)
12:58blake__I created a clojure function called "log-message".
12:58blake__And I'm calling it from Compojure like: :onchange "cmart.core.log_message.call(null, 'Hello from Clojure!')"
12:59bitfxahh, the exiting moments when trying out a new new language.
12:59lokienexiting :^)
13:00blake__Is that about how it goes? I know inside of cljs I can be all Clojure-y. But to talk from Compojure, I need the ugly Javascript?
13:01blake__Or is there some way to alias?
13:03ridcullyblake__: just to have it asked: does this still work with :advanced compilation?
13:06blake__ridcully: Dunno, but thanks for asking. I wondered about name-mangling.
13:07blake__I'll have to check it out.
13:07blake__So what does one do?
13:11blake__Or am I the only one doing this? We either go big, all ClojureScript, or go home (to Javascript, shudder).
13:30ikitommi_mpnet: thanks ;) there is some bench at bidi readme https://github.com/juxt/bidi/blob/master/README.md#contributing
13:32amalloyjustin_smith: yeah
13:33amalloy(apply routes (for [uri [...]] (GET [uri] ...)))
13:34justin_smithcool
13:34justin_smithI'm guessing that feature came after we did our own wacky solution
13:36blake__So, :advanced compilation doesn't seem to change anything, which makes me think I did it wrong.
13:36blake__But maybe it doesn't name mangle?
13:36justin_smithadvanced should definitely be name mangling
13:38amalloyjustin_smith: tbh i'm guessing that features has been there for a long long time. weavejester's stuff tends to support arbitrary inputs, and then additionally optimize for compile-time-known inputs
13:39blake__Maybe it's too simple a case.
13:39amalloylike how (html [:div foo]) compiles to like (str "<div>" foo "</div>"), but (let [tag :div] (html [tag foo])) still works, by analyzing the tag at runtime
13:45blake__OK, so I'm thinking the safe, clean way to do this is to export my clojurescript functions.
14:34itruslovescgilardi you're back!
14:48TimMc\o/
14:49TimMcMr. Scenario C. Gilardi
14:51amalloyhaha
15:17lokienhow are you guys so quiet today? now I feel bad about that I'm procrastinating
15:18lokiennot reading interesting irc stuff or anything
15:23TEttingerheh. I'm complaining about Firefox crashing constantly in #perl6 to someone I suspect may be a Mozilla fan
15:25lokienand you're.. a chromium fan?
15:25kwladykais any nicer method to write ((first coll-f)) ? something like (run (first col-f)) or something less confuse?
15:27TEttingerlokien: if Firefox didn't crash for me and use hefty memory since an update several years ago, I would still be a firefox fan
15:27lokienTEttinger: several years ago and you're still mad at it? oh man
15:29TEttingerwell I still need to open it occasionally
15:29TEttingeruptime: 54 milliseconds before crashing
15:30lokienaand you're on windows?
15:42domgetterI'm having trouble understanding namespaces. I'm trying to make a Luminus app, and when I'm in the repl, I can access myapp.views.index/html, but in the code in myapp.routes, I can't access that function unless I (ns myapp.routes (:require [myapp.views.index :refer :all]))
15:42domgetterDoes the repl behave differently than my code does when I lein run it?
15:47tdammersdepends how you start the repl, but yes
15:59domgetterIs there something like a let-ns which lets you do something in a namespace, but when the form ends, goes back to the previous namespace?
16:00justin_smithdomgetter: wanting to write code in another ns is a symptom of a design problem, from what I have seen the solution is usually that you need another ns that accesses both of them
16:01domgetterjustin_smith: I'll admit I may be doing something problematic. I'm trying to make a web framework that will be familiar to Rails developers.
16:02domgetterThat is, this framework will be "opinionated"
16:03justin_smithwell surely one can be opinionated without being wrong, and wanting to put code in another namespace is usually a sign you are doing it wrong
16:04justin_smithperhaps you need to inject a dependency, protocols are good for this
16:04lokienaren't our frameworks good enough though?
16:05domgetterlokien: Yes, I'm just trying to make something with the explicit goal of feeling familiar to Rails devs
16:06domgetterjustin_smith: I'm trying to make it so that when a route is generated from, say {:get "/photos"}, a helper is available in the views for (photos-path) that makes a link to that route
16:07justin_smithdomgetter: then I would create the namespace using create-ns and use intern to create the values, and make it clear that the ns is a runtime thing only and has no static file corresponding to it
16:07justin_smithit's still ugly, but at least that way it's possible
16:08justin_smithdomgetter: also, consider that instead of an ns you could have a simple hashmap of keys to functions
16:08justin_smithespecially since it would not be meant to map to any ns that actually exists
16:08justin_smith(as a file, that is)
16:19domgetterjustin_smith: ah interning is the solution for which I was looking. I do promise to consider the hashmap with keys to functions solution.
16:20justin_smithdomgetter: a pattern that has worked for me in the past is attaching keys to the request object, containing hash maps that the request handler can look in to find runtime resources, or custom handler functions that can't be provided at compile time
16:20justin_smitheg. a map that you can look in to find a cache of db results, or the current db config, or an asset pipeline the handler should invoke
16:24hiredmandomgetter: you are not the first person to come from rails to want something like that, https://github.com/macourtney/Conjure comes to mind, but no one who uses clojure regularly seems to want that
16:47domgetterhiredman: Interesting. I like what they did with generators, but I think I have a pretty slick idea for routing. We'll see how it pans out
16:58nanukoanyone know why prismatic has moved to plumatic on github?
17:02justin_smithnanuko: google fu, the libs interfering with the result standing of their product?
17:03justin_smithnanuko: maybe this is a sign ... http://getprismatic.com/home
17:04justin_smithnanuko: "On December 20 2015 the company closed its consumer-facing apps and focuses on offering its machine learning algorithms to publishers and hedge funds.[5]" https://en.wikipedia.org/wiki/Prismatic_(app)
17:11nanukojustin_smith: yeah, after poking around a bit, i found an article http://venturebeat.com/2015/12/11/prismatic-is-shutting-down-its-news-app-for-ios-android-and-web-on-december-20/
17:42princesojustin_smith: are you into caribou man?
17:59justin_smithprinceso: I am one of the caribou devs, but we haven't been working on it very actively lately
18:19domgetterHow come + is available everywhere without requiring clojure.core?
18:20domgetterIs it possible to make something like that myself? Or would I have to modify Clojure itself?
18:20domgetter(I'm not saying I want to, I'm just trying to understand)
18:20justin_smithdomgetter: the ns macro implicitly calls refer-clojure
18:20justin_smithwhich is basically (require '[clojure.core :refer :all])
18:21justin_smithdomgetter: vinyasa has tools for doing similar stuff with your own stuff for dev
18:21domgetterahh I see
18:29WickedShellGotta be a stupid question: I'm porting some Java code to clojure and woking with interop i have a case where in java I would pass Rectangle.class what would the equivlent be in clojure?
18:30amalloy,String
18:30justin_smithRectangle
18:30clojurebotjava.lang.String
18:30WickedShelljust pass it directly? well thats farrrr more convient
18:51justin_smithis it possible to request that clojure.data.xml be more lax about input? or perhaps there is anotherl lib that similarly does lazy sax based parsing and is flexible about input validity?
18:52amalloyjustin_smith: tagsoup or a relative?
18:55justin_smithamalloy: the "lazy" option of clj-tagsoup is not actually lazy in terms of consuming the input, or even parsing.
18:56justin_smithamalloy: just fixed a thread leak in my app caused by the thread clj-tagsoup uses to generate elements never exiting if you don't fully consume the stream it creates
18:56justin_smith(doall x) - wow, 4000 threads is now 400 threads
18:56amalloywell, when you have a clojure library that wraps a java library badly, go to the source
18:57justin_smithright, right
18:57amalloytagsoup alleges to expose a sax-like api
18:57justin_smithI spent a little time reading tagsoup, and ... yeah, I guess I know what's going to be giving me a headache this weekend :)
18:57amalloybut i can't easily find api docs
18:57justin_smithyeah, looks like I'
18:57justin_smithll be making that wrapper
18:58amalloywell, "badly". arguably it wraps the java library in a way that is just at a different place on the convenience/correctness spectrum
19:00justin_smithright, right. I need specific features it wasn't providing.
19:01justin_smithbut "create a thread that never exits unless you consume all the elements of this lazy seq" is a hell of a gotcha
19:02amalloyyou'd be surprised how many people have created lazy seqs that assume you will fully consume them
19:05hiredman:(
20:25oraclehow to split [1 2 3 5 6 7] into [1 3 6] [2 5 7]
20:25oraclesplit by position
20:27justin_smith,(apply map list (partition-all 2 [1 2 3 5 6 7]))
20:27clojurebot((1 3 6) (2 5 7))
20:27justin_smith,(apply map list (partition-all 3 [1 2 3 5 6 7]))
20:27clojurebot((1 5) (2 6) (3 7))
20:27oraclegreat, thx
20:31ridcully,(apply map list (partition-all 2 (range 7)))
20:31clojurebot((0 2 4 6))
20:33justin_smith,(apply map list (partition 2 (range 7)))
20:33clojurebot((0 2 4) (1 3 5))
20:33justin_smithaha! a case where partition is a bit better behaved than partition-all
20:36TEttinger,(take-nth [1 2 3 4 5 6 7] 2)
20:36clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long>
20:36TEttinger,(take-nth 2 [1 2 3 4 5 6 7])
20:36clojurebot(1 3 5 7)
20:36TEttingeroh there was no 4
20:39ridcully,(let [r (range 6)] (map (partial take-nth 2) [r (rest r)]))
20:39clojurebot((0 2 4) (1 3 5))
20:39ridcully,(let [r (range 7)] (map (partial take-nth 2) [r (rest r)]))
20:39clojurebot((0 2 4 6) (1 3 5))
20:47pilnei blew up my clojure >.<
20:48pilnealthough it actually might be leiningen
20:49ridcullyerrors?
20:50pilneinstalled lein per the website, then ran "lein" and then when i tried to run "lein repl" i get all sorts of java.security.* errors
20:53justin_smithpilne: what lein version?
20:53pilne2.5.3
20:54justin_smithos and java?
20:54pilneubuntu 15.10 openjdk 1.8
20:54pilne64bit
20:54justin_smithhmm
20:55pilnei concur
20:56pilnelein run in a made project gives: Could not transfer artifact org.clojure:clojure:pom:1.7.0 from/to central (https://repo1.maven.org/maven2/): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
20:58justin_smithpilne: http://stackoverflow.com/questions/4764611/java-security-invalidalgorithmparameterexception-the-trustanchors-parameter-mus
21:00pilneyou the man
22:00kenrestivoi wonder how much time could be saved if IDEs had a "google" button that copied/pasted the error message into google
22:01kenrestivoi have to think that's the #1 debugging approach around. amazed it hasn't been automated yet
22:13pilnepretty sure it can be added to atom somehow, it has hoogle integration for haskell
22:40amalloydo people really google entire stacktraces?
22:40TEttingeryes.
22:40TEttingerme.
22:41TimMc"do people really google $FOO?" "yes"
22:41TEttingernormally you need to take some of it out
22:42TEttingeryeah amalloy, why are you asking that question? "do people really google twerking dogs?" might be more interesting
23:36sdegutisIs there a way to combine cond and let somehow?
23:37sdegutisI'd like to have a ton of conditions in the cond, and guard against bad values early on, and if they're good values, transform them and continue with the conditions.
23:37sdegutisI'm 99% certain it's not possible, but if it can be done, I'm 100% certain justin_smith would be the one to come up with the way :D
23:38lambda-11235sdegutis: You mean like if-let?
23:38sdegutisKinda, but within cond, so I don't have to have another cond within a cond.
23:38sdegutisI've seen cond-let, but I'm pretty sure it's one-shot like if-let is.
23:39sdegutisI'm thinking more like (cond (nil? email) :error, bind 'user (get-user email), (nil? user) :error, ... )
23:39sdegutisOr something weird.
23:40justin_smithsdegutis: I assure you good sir, your high esteem of my knowledge in all things clojure is undeserved, and on this question I must disappoint you. I'd probably end up making some terrible concoction using delay and deref chains. There might be something like what you want hidden in the depths of flatland/useful though.
23:40sdegutisHaha
23:41amalloynah, this massive let is not really a style we love. it exists, though, as egamble/let-else
23:42sdegutisHmmm interesting.
23:43sdegutisBut yeah, it's a bit gross.
23:43sdegutisI'll just have to get comfortable with nested conds.
23:43sdegutisOr an if-let at top.
23:43sdegutisMeh, nothing's perfect.
23:44justin_smithsdegutis: in all seriousness, in cases where I have complex logic that decides which bindings should be realized, I've found a let block full of delays, (some of which derefing other delays internally), combined with a cond block that decides which ones to deref given the runtime conditions works out OK
23:45sdegutisHmm. Interesting idea.
23:46amalloyflatland/useful *does* have let-later, to manage that for you
23:47sdegutisVery neat.
23:55sdegutisGood night amalloy and justin_smith.