#clojure logs

2014-08-03

00:05awwaiidDo I really have to put the full version of core.async as a dependency, as in [org.clojure/core.async "0.1.303.0-886421-alpha"] ? I'd love to do [org.clojure/core.async "0.1"] and have it just get the latest 0.1.*
00:10rhg135_idk about emacs but i :r!cat ~/.casync in vim
00:11rhg135_keep the coordinatine in the file
00:11rhg135_to save typing
00:27awwaiidwha? like you keep that version string in that file and read it in at your leisure when you want to update it?
00:30rhg331Yes
00:39awwaiidah. Not quite what I was looking for :)
00:43acagle1(quit)
00:43acagle1quit
00:43acagle1exit
00:43TEttingeracagle: /quit
00:44TEttingeracagle1: /quit
01:26jeremyheilercb
01:35ChouLinhi everyone, I wonder if there's a non-recursively 'flatten' ? I want (nr-flatten ['([1 2] [3 4]) '([5 6] [7 8])]) return ([1 2] [3 4] [5 6] [7 8]) and still be 'Lazy'.
01:35ChouLinI've tried 'concat' , not working.
01:36rhg331Apply it maybe?
01:37ChouLinyes! apply it is!
01:37ChouLinhow stupid I am.
01:52swgillespieHi all, I'm getting a really strange compile error here: https://gist.github.com/swgillespie/7325058250c7190d5881
01:53swgillespieit works when I use the repl to define it, but when I try to compile it from my buffer I get this ClassCastException on line 6
01:53swgillespieis there something weird going on here?
01:55swgillespiealso, when I comment out the uuid function, the last line in the namespace macro gets the same error...
02:04ddellacostaswgillespie: I think the line number is out of sync--it seems rather that it's complaining about not being given a protocol/interface for the deftype call
02:04swgillespiehmm
02:04swgillespiethat's strange
02:05ddellacosta&(defprotocol Foo (test [this]))
02:05swgillespiebut that makes sense, thanks ddellacosta
02:05ddellacosta&(deftype Foo [] (test [this] "blah"))
02:05ddellacosta(deftype Foo IFoo [] (test [this] "blah"))
02:05ddellacostad'oh
02:05ddellacosta&(deftype Foo IFoo [] (test [this] "blah"))
02:05ddellacostahmm, can I not make protocols/types with lazybot?
02:06ddellacostaswgillespie: sure thing, hope that helps
02:06ddellacosta,(defprotocol Foo (test [this]))
02:06clojureboteval service is offline
02:06ddellacostaright
02:06ddellacosta_,(defprotocol Foo (test [this]))
02:06clojurebotWarning: protocol #'sandbox/Foo is overwriting function test\n#<SecurityException java.lang.SecurityException: denied>
02:06swgillespieddellacosta: it does :)
02:06ddellacosta_swgillespie: great. :-)
02:07ddellacosta_,(deftype Foo [] (test [this] "blah"))
02:07clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol>
02:07ddellacosta_swgillespie: yeah, *that* was what I was trying to dump out ^
02:07swgillespiethat's kind of a strange error message for this
02:07ddellacosta_swgillespie: well, it makes sense if you think about it
02:07ddellacosta_,(deftype Foo [] IFoo (test [this] "blah"))
02:07clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: IFoo in this context, compiling:(NO_SOURCE_PATH:0:0)>
02:07swgillespieit's interpreting the [] as a symbol for a protocol?
02:07ddellacosta_whoopos
02:08ddellacosta_,(defprotocol IFoo (test [this]))
02:08clojurebotWarning: protocol #'sandbox/IFoo is overwriting function test\n#<SecurityException java.lang.SecurityException: denied>
02:08ddellacosta_,(deftype Foo [] IFoo (test [this] "blah"))
02:08clojurebot#<CompilerException java.lang.NullPointerException, compiling:(NO_SOURCE_PATH:0:0)>
02:08ddellacosta_d'oh
02:08ddellacosta_anyways
02:08swgillespiehaha
02:08ddellacosta_swgillespie: yeah, it's attempting to interpret the function as the name of the protocol --so it wants a symbol but is getting a list
02:09swgillespieddellacosta_: gotcha, makes sense
02:09ddellacosta_I guess that denied means...I can't do that.
02:10gws,(defprotocol IFoo (test-1 [this]))
02:10clojurebotIFoo
02:10gws,(deftype Foo [] IFoo (test-1 [this] "blah"))
02:10clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.Var cannot be cast to java.lang.Class>
02:10ddellacosta_gws: oh, duh, 'cause I'm using the fn "test" huh
02:11gwsyeah that's how i interpreted the error at least
02:11ddellacosta_but, what is that last exception?
02:11ddellacosta_works in my repl, don't get that
02:12ddellacosta_oooh, no it doesn't, not like that
02:12ddellacosta_okay, wait a sec
02:12ddellacosta_(deftype Foo [] IFoo (test_1 [this] "blah"))
02:12taliostechnomancy - http://central.sonatype.org/articles/2014/Aug/03/https-support-launching-now/ - with details for maven, leiningen, etc. etc.
02:12ddellacosta_,(deftype Foo [] IFoo (test_1 [this] "blah"))
02:12clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.Var cannot be cast to java.lang.Class>
02:12ddellacosta_,(defprotocol IFoo (test1 [this]))
02:12clojurebotIFoo
02:12ddellacosta_,(deftype Foo [] IFoo (test1 [this] "blah"))
02:12clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.Var cannot be cast to java.lang.Class>
02:12ddellacosta_okay, I'm spacing something obvious here
02:14swgillespieis there a naming convention for protocols?
02:14swgillespiesort of like the "-able" interfaces in java?
02:14ddellacosta_swgillespie: often times you'll see an "I" prefix
02:14ddellacosta_for interface, I believe
02:15ddellacosta_,(defprotocol IOnceMoreWithFeeling (testa [this]))
02:15clojurebotIOnceMoreWithFeeling
02:15swgillespiecool, thanks
02:15ddellacosta_,(deftype OnceMoreWithFeeling [] IOnceMoreWithFeeling (testa [this] "okay now"))
02:15clojurebotsandbox.OnceMoreWithFeeling
02:16ddellacosta_yeah, right, there's something going on with using the same names, maybe I'm not understanding how compilation is working. Hmm
02:16ddellacosta_(testa (OnceMoreWithFeeling.))
02:16ddellacosta_,(testa (OnceMoreWithFeeling.))
02:16clojurebot"okay now"
02:24gwshow often does the sandbox get cleaned out?
02:26ddellacostagws: yeah, I dunno, I wonder if there's a way to flush it? Maybe create a new ns? Not sure if that's allowed
02:27ddellacosta(ns SandboxPart2)
02:27ddellacostaer
02:27ddellacosta_,(ns SandboxPart2)
02:27clojurebotnil
02:27ddellacosta_(def foo "foo")
02:27ddellacosta_,(def foo "foo")
02:27clojurebot#'sandbox/foo
02:27ddellacosta_,*ns*
02:27clojurebot#<Namespace sandbox>
02:28ddellacosta_huh, guess not, unless I forgot something, which is equally possible
02:30gws,(ns myns) (println *ns*)
02:30clojurebotnil
02:30ddellacostagws: I'm guessing you have to add , to each form
02:30gws,(do (ns myns) (println *ns*))
02:30clojurebot#<Namespace myns>\n
02:30ddellacosta_,(println *ns*)
02:30clojurebot#<Namespace sandbox>\n
02:31ddellacosta_right, so I guess you can change ns local to a form then
02:31ddellacosta_,(do (ns local-ns) (println *ns*)) ,(println *ns*)
02:31clojurebot#<Namespace local-ns>\n
02:31ddellacosta_well then, that didn't work
02:31ddellacosta_,(prinltn *ns*)
02:31clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: prinltn in this context, compiling:(NO_SOURCE_PATH:0:0)>
02:31ddellacosta_,(println*ns*)
02:31clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: println*ns* in this context, compiling:(NO_SOURCE_PATH:0:0)>
02:32gwslol
02:32ddellacosta_,(println *ns*)
02:32clojurebot#<Namespace sandbox>\n
02:32ddellacosta_some day, I will learn to type
02:40rhg331,(do (do (ns hi) (println *ns*)) (print *ns*))
02:40clojurebot#<Namespace hi>\n#<Namespace hi>
03:19ChouLinI wonder if it's safe to read & loop a file like this: (map #(...) (line-seq (clojure.java.io/reader *in*))]) , should I always use 'with-open' ?
03:19ChouLinor even worse, explicitly open and close ?
03:21expezuse (with-open [rdr (io/reader "some/file")] (map #(...) line-seq))
03:21kovrikGuys, if I use (clojure.walk/postwalk #(println %) coll) - it prints each form it walks. What should I do if I want it not to print each form, but add each form to a collection and return this collection?
03:21expezthat last line-seq should be rdr, obv ><
03:24expezkovrik: (let [forms (atom []) (postwalk #(swap! forms conj coll)) then finally you can return the contents of the atom with @forms
03:25expezkovrik: conj will add to the end of a [], if you want the reverse order you can conj onto a regular list instead of a vector
03:26kovrikThanks! But is it possible to solve this problem without atoms? Atoms are overkill here, IMO, no?
03:26expezYou need something that is mutable, most stuff in clojure is not :)
03:26gws,(clojure.walk/postwalk (partial conj []) [1 2 3 4])
03:26clojurebot#<ClassNotFoundException java.lang.ClassNotFoundException: clojure.walk>
03:27gwskovrik: try that approach, see if it suits what you're trying to do
03:28kovrikIt works! Thanks!
03:28gwscool! np
03:30expezwhat is the difference between binding and with-redefs when redefining a function? Is it that binding only works on vars that are marked as ^:dynamic?
03:30kovrikBut I don't get it. How it works? postwalk walks each form and calls a function on each form. Shouldn't it return the last call of a function to the last form of the collection?
03:31gwsclojure.walk/postwalk:
03:31gws Performs a depth-first, post-order traversal of form. Calls f on
03:31gws each sub-form, uses f's return value in place of the original.
03:31gws Recognizes all Clojure data structures. Consumes seqs as with doall.
03:32kovrikOh, I see. Thank you!
03:33gwsif you check the return value when you do the original postwalk with #(println %) as you had done - you'll see that the return value has a collection of nils, one for each time you called println
03:35kovrikCan I control the way it walks the form? If I have a binary tree (represented as vector of vectors), can I have 2 postwalks - each uses depth-first, but one goes left subtree first and another goes right subtree first?
03:36rhg331,(do (require 'clojure.walk) (clojure.walk/postwalk (partial conj []) [1 2 3 4]))
03:36clojurebot[[[1] [2] [3] [4]]]
03:38kovrikTo be clear: I'm trying to solve this problem: https://www.4clojure.com/problem/96 It is very easy to solve it, for example, in Java. But I'm stuck with Clojure
03:39kovrikAnd label "Difficulty: Easy" makes me feel stupid :)
03:40TEttingerit is number 96
03:40TEttingerso I guess it's easy for almost 100 programs in
03:40rhg331Wouldn't that be an equality among branches?
03:41kovrikNo. Branches are not equal - they are 'mirrored'
03:44kovrikAs far as I understand, the solution in Java is to walk each branch with DFS, but in left branch we go left subtree first, and in the right branch we go right subtree first. We record our path while walking and then compare two paths. If they are equal, then binary tree is symmetric
03:45rhg331I see now
03:46kovrikBut I can't get it work in Clojure...
03:47ChouLinthank you expez , its works, but personlly I'm trying to avoid a outside 'with-open' . I'm using (... (map #(..) (clojure.java.io/reader "myfile"))) all the time, just want to ensure if I'm just lucky or it's a right way.
03:48rhg331I think recursion might help but it's only a hunch
03:49expezChouLin: you will be leaking file handles if you don't close open files, this may or may not become a real problem
03:55ChouLin guess I've been lucky for a while. I also found a simple loop & print, apart from jvm start time, clojure is much slower than Python. Am I missing something or Python is too good at this ?
03:56ChouLin(with-open [F (clojure.java.io/reader *in*)]
03:56ChouLin (let [line (line-seq F)]
03:56ChouLin (println line)))
03:56ChouLin
03:57ChouLinI collect 1000 copy of 'wget' man page, then `cat 1000.manpage | clj print_std.clj 1>/dev/null` , it takes 10 times longer than Python code.
03:58ChouLinimport sys
03:58ChouLinfor line in sys.stdin:
03:58ChouLin print line
03:58ChouLin
03:59gwsChouLin: how are you discounting JVM start time?
04:00ChouLinI give a 10 line file as input, count the whole process time as jvm start time.
04:01ChouLinthe manpage I give later has 170million, I guess the start time is independent with file size.
04:02gwsi'm not sure - you can try something like (doseq [line (line-seq F)] (println line))
04:02gwsthat's inside the with-open form
04:15ChouLinthank you gws, still slow. But fast enough for me either way :)
04:21ddellacostaChouLin: in general, Clojure is really not well suited to doing that kind of scripting. You could check out Grenchman though, it may scratch some itches: https://github.com/technomancy/grenchman
04:23ddellacostaChouLin: another approach for your specific task is to use conch inside the repl, and process the output of a shell command that way: https://github.com/Raynes/conch
04:49ChouLinthank you ddellacosta , I'll try conch later. My current goal is use Clojure as text processor, most job are easy, so far so good. at this stage I want use less dependency as possible.
04:53ddellacostaChouLin: sure thing--you can also just try using a Java ProcessBuilder (which conch is just wrapping) to exec stuff, if you still want to try the "all in repl" approach (which is how most folks do stuff like this because of the horrendous Clojure startup time).
04:54ddellacostaChouLin: in any case, good luck. :-)
05:12kovrikYay! I've solved 4clojure's problem 96 :) https://gist.github.com/kovrik/8e47bccfbe68586060bf
05:13TEttingerwoo kovrik
05:13kovrikIs there a way to simplify the code? or make it more idiomatic?
05:14TEttingerlooks pretty clear to me
05:14kovrikThanks :)
05:14TEttingerprobably making it shorter would make it harder to understand, here
05:14gwsyeah i'm with TEttinger that looks clear to me too
05:18kovrikI wish there was something like conditional 'let'-form. Not if-let (which binds result of the evaluation). But something like (let [(if (condition) [a b] [b a]) v] ...)
05:30ddellacostakovrik: I often find myself doing something like (let [x (if (some-pred? x) (do-something-to-x x) x)] ...)
05:31ddellacostakovrik: not exactly what you were asking about, but similar
05:32pyrtsaddellacosta: cond-> could work for that, although I think it's a bit hard to read at times. (let [x (cond-> x some-pred? do-something-to)] ...)
05:32kovrikYes, looks similar. But in my case it will make solution more complicated
05:32ddellacostapyrtsa: yeah, that may be superior, not sure
05:33ddellacostakovrik: yeah, I think what you have in your specific example is not bad
05:34pyrtsaI've found myself wanting something similar to Haskell's do notation at times with Clojure. Ended up making my own variant of the let macro which does all the short-circuiting of nil values and that, but it certainly could be better.
05:34ddellacostaI'm struggling to see how to refactor in such a way that it would be cleaner, I think it's pretty good as is
05:34ddellacostapyrtsa: would be interested to see it
05:36pyrtsaddellacosta: Actually, wrapping the `for` macro inside an (apply concat (for [...] ...)) gets you quite close to it. The only thing to remember (and where the Clojure compiler doesn't really help) is that you must return a seqable thing in the body.
05:37ddellacostapyrtsa: interesting, I'll have to play with that some more
05:38gwsi've used the Maybe monad in clojure for that kind of thing too
05:38pyrtsa,(defmacro forcat [exprs body] `(apply concat (for ~exprs ~body)))
05:38clojurebot#'sandbox/forcat
05:38pyrtsa,(forcat [x [1] y (if (odd? x) [:bar])] [(str x y)])
05:38clojurebot("1:bar")
05:38pyrtsa,(forcat [x [2] y (if (odd? x) [:bar])] [(str x y)])
05:38clojurebot()
05:38pyrtsaEt cetera.
05:39pyrtsa(Btw, forcat is very useful for recursively defining Datomic transactions from nested data.)
05:41pyrtsaI haven't checked what it's like to play with monads in Clojure + core.typed, but without type checking, monads just get on the way in plain Clojure.
05:43pyrtsakovrik: Here's my solution to 4clj #94 with some more destructuring: https://gist.github.com/pyrtsa/c66630466396064cee24
05:43pyrtsaI mean, #96.
05:44gwswhat is a better way to clean up the nested-if antipattern here? https://gist.github.com/gws/3d091805d6ba1b359c5d
05:45kovrikpyrtsa: very concise!
05:46pyrtsagws: That's exactly the kind of use case I was talking about above. My above forcat macro _could_ (but should not) be used for that.
05:47pyrtsaOther options I've used with varying success are 1) a custom let macro (call it e.g. `ret`) that short circuits when it sees a special value being bound (similar to reduce & reduced), 2) throwing exceptions.
05:48thhellergws: not sure why you'd call nested if an anti-pattern
05:48thhellerbut a monad seems pretty overkill to me
05:48gwsthe anti-pattern is repeating the else clause n times
05:48thhellertry https://gist.github.com/thheller/cda2a325c5e36b5f479c
05:48thhellerthere are other ways to get rid of it ;)
05:48gwsobviously
05:49gwsi never said a monad was the only way, and i even suggested it wasn't the best way
05:49pyrtsathheller: That works there. What keeps troubling me is that it's always a slightly different trick you'd play when the nesting is different. A uniform way to get around it would be nicer.
05:50thhellerwell you can't solve it in a uniform way
05:50thhellercause every case is different
05:50thhellersometimes you need to carry state
05:51thhellerbut imho its always better to try an simplify before going the macro route
05:51pyrtsaThe do notation of Haskell is a uniform way to solve it, state or not. I'm just saying Clojure doesn't seem to have it's own way here.
05:52pyrtsa*its
05:52thhellerhttps://gist.github.com/thheller/cda2a325c5e36b5f479c
05:52thhellerdont know haskell very well
05:52pyrtsaNo worries.
05:57pyrtsathheller, gws: The latest Gist further simplified with if-let: https://gist.github.com/pyrtsa/878491ba0f6d97fe91f1
05:57gwsi'm missing how these scale to multiple short-circuitable tests
05:57thhellerhehe I did that too after the last paste :)
05:58pyrtsagws: Yeah, that's what I'm missing too.
05:58thhellergws: Its not a uniform solution, its just a simple solution to your example
05:58gwsif i want to add a second test in the monadic version, it's just a second binding form below the 'ident' line
05:58thhellergws: YAGNI :)
05:59gwsin most cases yes, in this case i will but i haven't written the code for it yet
06:21pyrtsagws, thheller: Here's what it would look like with my silly `ret` macro. https://gist.github.com/pyrtsa/1af9fdd56267a3631b0c
06:41gwspyrtsa: thanks for that example
08:30kovrikWhy do we need to write recur (or loop-recur) explicitly? If we write a recursive call to a function not in a tail-position, then compiler will throw an exception: 'Can only recur from tail position'. So, the compiler determines that our recursive call is not in a tail position. If the complier can determine such things, then why can't we just make a recursive call without loop-recur? Can't compiler add loop-recur forms automatically?
08:32LauJensenIve just switched to cider-mode in Emacs and most shortcuts and so on work, but when I type "(reduce" emacs would normally show me the argumentlist for reduce below the modeline, but this does not happen. It works in the nrepl window, but thats it. Any idea why?
08:34expezLauJensen: (add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
08:34expezthere's a long readme for cider on github
09:06LauJensenexpez: I already had that, an ElDoc mode is active
09:12visofhi
09:13visofi'm using java interop but i got strange error which is http://sprunge.us/gSGO ?, what maybe cause this error and how can i fix it?
09:14visofi just tried to execute (.getVertices graph "name" "foobar"))
09:26hyPiRionvisof: can you try to do (import 'com.tinkerpop.blueprints.util.DefaultGraphQuery)?
09:27visofhyPiRion: (:import (com.tinkerpop.blueprints.util DefaultGraphQuery) is right too?
09:28hyPiRionvisof: yeah, sure. Just something which attempts to import it
09:30hyPiRionI'm guessing you don't have that class on your classpath – you may have to add blueprints to your dependencies
09:34visofhyPiRion: that's the full error http://sprunge.us/JfDH , what i try to do is transform this java List<Vertex> r = graph.getRawGraph().command(new OCommandGremlin("g.V[1].out.out.in")).execute(); to clojure println (. (.command (.getRawGraph g) (OCommandGremlin. "g.V[1].out.out.in")) (execute (object-array []))))
09:38hyPiRionvisof: Yeah, I remember from yesterday. You're using leiningen as a project manager, right?
09:38visofhyPiRion: yeah
09:40hyPiRionvisof: try to add [com.tinkerpop.blueprints/blueprints-core "2.5.0"] to your :dependencies vector, and check if that helps
09:40hyPiRioninside project.clj
09:42visofhyPiRion: there is no 2.5.0 i'm already added 2.4.0
09:43hyPiRionhuh, I see it on maven central
09:43hyPiRionhttp://mvnrepository.com/artifact/com.tinkerpop.blueprints/blueprints-core/2.5.0
09:44hyPiRionbut if that doesn't help, then I don't know :x
09:49visofhyPiRion: Thanks man
09:49hyPiRionvisof: did it work? Or is it still not working?
09:50hyPiRionvisof: Oh, I found someone with the same problem: https://groups.google.com/forum/#!msg/orient-database/Dv3EY4MdJo8/57n7Ld1-qO4J – so apparently, adding using version 2.5.0 should fix the problem
09:51visofhyPiRion: works man
09:51hyPiRionnice
09:52sveriHi, I have a list of maps, when I do a two step operation on them, first, I update-in a key for each map in that list, then I take the new list, and do an update-in in the map again on a different key and return the result, I am pretty sure there is a way to do this in a more idiomatic way, anyone feels like looking at it? Here is the function: http://pastebin.com/Li1gsNv7
09:55hyPiRionsveri: is `es` `events`?
09:56hyPiRionat the end of line 4
09:57sverihyPiRion: ah yea, copy and paste error, repl state makes it possible :D
09:57hyPiRionhehe
10:00hyPiRionsveri: something like this? http://pastebin.com/CUGDeEPE
10:01sverihyPiRion: that looks nice
10:02hyPiRionI guess you could probably factor even more out, but there's always this question on readability vs. cleverness
10:04sverihyPiRion: yea, I find myself struggling much more in doing refactoring in clojure than any other language
10:04sveriand sometimes I think , jeez, I could have done 3 features in that time :D
10:05hyPiRionsveri: It comes with experience as well :) After some time, you can easily read and reason around "normal" Clojure code quite easily
10:06sverihyPiRion: yea, I hope so, and it has the effect to learn more, so I guess it's worth to spend this time doing a lot of refactorings and looking for more idiomatic ways
10:06hyPiRionright
10:08sverihyPiRion: I like the fact you defined the functions first and than the function sequence, I always do it the other way around
10:11hyPiRionsveri: It sort of depends from time to time. I did it this way because the function calls were essentially equivalent (minus the val to update) and because they are so long that it's useful to name them something (for readability)
10:11hyPiRionNow whether the names are sensible or not is another matter.. :p
10:14sverihyPiRion: my names almost never are sensible
10:16hyPiRionhaha
10:29jgtHow can I create a delay before calling a function?
10:30tadniAre there any general "introduction to programming" texts for Clojure?
10:31jgtsomething with Thread/Sleep ?
10:36kovrikjgt: yes. (do (Thread/sleep 10000) (println "Done"))
10:36jgtcheers
10:37kovrikor (future ((Thread/sleep 10000) (println "Done"))) if you need to do it asynchronously
10:37jgtyeah, I probably need it async
10:38jgtI’m just tinkering with Clojure; trying out the sleeping barber problem
10:42hyPiRionIsn't that's a problem which fits nicely with core.async?
10:45jgtno idea; I’m very much a Clojure beginner :)
10:45jgtI’m also very much a FP beginner
10:51hyPiRionah
11:29ruzutadni: http://www.braveclojure.com/ perhaps?
11:31pandeiroanyone have a workflow suggestion for building/signing/deploying clojure artifacts from jenkins to a repository? i am caught up on how to integrate gpg w/ jenkins
12:22jjwatt /quit
12:33schmeehey all, I have this piece of code: (binding [*out* (io/writer socket)]
12:33schmee), but I actually want to write to multiple sockets, something like (binding [*out* (io/writer socket1 socket2)]
12:33schmee)
12:33schmeeI just need some pointers in the right direction. Proxy, reify, something else?
12:52gfredericksreify should suffice
12:53gfredericksmaybe there's a builtin class for that already though?
12:53gfredericksI don't know jvm socket stuff
12:54bbloom_java.io.Writer is an abstract class
12:54bbloom_it doesn't have any useful interfaces really
12:55bbloom_there's Appendable, but that doesn't cover the more common "write" operations
12:58bbloom_schmee: java.io isn't great for these sorts of things, there's java.nio which has lots more support for multiplexing
12:58bbloom_and there's interop at the top level for java.io, so you can still use *out* (if you insist)
13:00schmeealright, I'll take a look at nio, thanks
13:15OldTreehas anybody used Stuart Sierra's Component framework with something like Korma?
13:38pandeiroso i ended up creating a gpg key w/o passphrase for my jenkins user and using that to encrypt credentials.clj and sign artifacts (w/o having to enter a passphrase during automated builds/deploys) -- is this a terrible idea?
14:09H4nspandeiro: it depends on what threat you're addressing.
14:10ro_stis it possible to temporarily expand the classpath for a clojure app with a leiningen project's dependency map, and then dispose it again?
14:11jeremyheilerro_st: what are you trying to do?
14:12ro_sti'm using shadow-build to compile cljs for multiple cljs projects. i want fast compilation so i'm doing it all from a single jvm, to avoid startup time etc. i'd like to give shadow access to the deps for the cljs lein project in question so that it can resolve deps etc
14:13ro_stright now i have all the deps from all the projects in the host of shadow-build. that's proving painful
14:18danxensenare there any preferable places to blog about clojure and programming?
14:20xeqiro_st: nothing built in to lein, but you might be able to build something w/ alembi+classlojure
14:20xeqi* alembic
14:22ro_stxeqi: interesting, thank you. i'll have a dig around those
14:23pandeiroH4ns: i am just trying to do the sensible thing in integrating a private maven repo into a continuous integration... not really addressing anything in particular. the two options i saw were do passphraseless or just don't sign
14:45AeroNotixpandeiro: uhm, no
14:45AeroNotixthat
14:45AeroNotixThat's not a bad idea (having Jenkins sign stuff)
14:46AeroNotixProviding that there's proper ACLs on the Jenkins box
14:46AeroNotixthis is what $DAYJOB does
14:49ToBeReplacedhow do i tell eastwood "use all linters"? all i can see is that i manually add the linters that are disabled by default; is that the best way?
14:56Balvedayogthos, are you on?
15:00mi6x3mhey, how do I get the name of a namespace?
15:01xeqi,(.name *ns*)
15:01clojurebotsandbox
15:01dnolen_,(doc ns-name)
15:01clojurebot"([ns]); Returns the name of the namespace, a symbol."
15:02mi6x3mxeqi: implementation spefic
15:02mi6x3minc dnolen_
15:02dnolen_mi6x3m: some implementations don't have reified namespaces
15:02dnolen_mi6x3m: i.e. ClojureScript
15:02mi6x3mthanks dnolen_ :)
15:04mi6x3mdnolen_: what do you mean reified?
15:07justin_smithmi6x3m: I think that means in clojurescript namespaces aren't actual objects you can access
15:08mi6x3mjustin_smith: ehm, isn't this a language requirement?
15:08mi6x3mi mean, of the stdlib
15:12dnolen_mi6x3m: no
15:12dnolen_mi6x3m: reified namespaces nor many concurrency constructs or host IO specific things do not exist in ClojureScript
15:17mi6x3mdnolen_: is there something like ns? then
15:18dnolen_mi6x3m: first classes namespaces do not exist in ClojureScript, thus no supporting APIs either
15:19dnolen_in ClojureScript namespaces are a static construct only
15:19dnolen_you only manipulate / inspect them via macros
17:53so_haltHi, I'm having trouble with a compojure webapp. I'm trying to get basic-authentication for a part of my routes, but not all of them.
17:53so_haltI defined my routes as (defroutes r public-routes (wrap-basic-authentication admin-routes authenticate)) (def app (-> r wrap-params wrap-json-params))
17:54so_haltbut everything under admin-routes gets me a 404 not found
17:55so_haltIf I reorder the admin-routes and public-routes the admin-routes start working again, but now all routes (public-routes included) require basic-auth.
17:55so_haltDoes anybody know, what I'm doing wrong?
17:59so_haltI found this https://stackoverflow.com/questions/10822033/compojure-routes-with-different-middleware stackoverflow post, but the solution proposed there unfortunately doesn't seem to work.
18:00gfredericksso_halt: I'd suggest pasting your code a bit more formally (e.g. refheap.com); I can't read your code in IRC very well
18:00so_haltOk, sorry. You're right. It's quite painful to read it that way.
18:03so_halthttps://www.refheap.com/14db7cc5a74f8336346e10458
18:04so_haltadmin-routes and public-routes are both defined with defroutes
18:10rksm_re namespaces: are there plans to make them first class?
18:15so_haltI guess I found the source of my "bug". had the not-found handler at the end of the public-routes. That was holding me up for the last hour or so. Well, sometimes just staring long enough at the code helps…
18:16so_haltAnd I thought all the time it had to do with me composing my routes wrong in the final step.
18:50technomancyrksm_: I don't think so
18:54gfredericks,#"(?<=SHA256-s\d+--)\w{64}"
18:54clojurebot#<SecurityException java.lang.SecurityException: denied>
18:54gfredericks,#""
18:54clojurebot#""
18:54gfredericks&#"(?<=SHA256-s\d+--)\w{64}"
18:57justin_smithhttp://www.regular-expressions.info/lookaround.html "
18:57justin_smithJava takes things a step further by allowing finite repetition. You still cannot use the star or plus, but you can use the question mark and the curly braces with the max parameter specified. Java determines the minimum and maximum possible lengths of the lookbehind. "
18:57gfredericksit didn't even like it when I replaced + with {,20}
18:58justin_smithtry {1,20} or {20,20} if that is absolutely the number to be found
18:59TimMc"PatternSyntaxException Look-behind group does not have an obvious maximum length near index 16"
19:05TimMcgfredericks: Java needs an explicit lower bound in repetition ranges, I think.
19:08gfredericks,#"x{,20}"
19:08clojurebot#<NoClassDefFoundError java.lang.NoClassDefFoundError: Could not initialize class java.util.regex.PatternSyntaxException>
19:08gfredericks&#"x{,20}"
19:08gfredericksI give up
19:09gfredericksthere was an easy enough workaround
19:09tickingclojure seems to handle more than one namespace declaration per file pretty well, is that behaviour accidental or hacky yet acceptable
19:10rksm_technomancy: ok. is there currently ongoing work towards a self-hosted clojurescript? https://github.com/lazerwalker/clojurescript-in-clojurescript seems not to be active anymore
19:11technomancyticking: I don't know if it was accidental, but it's definitely not acceptable in codebases I maintain.
19:11technomancyrksm_: I don't really know anything about clojurescript
19:13tickingtechnomancy: yeah it seems rather nasty, but it's the simplest way to inject a helper namespace into clojurescript compiled from within clojure
19:20justin_smith,ping
19:20clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: ping in this context, compiling:(NO_SOURCE_PATH:0:0)>
20:49blaenkhow can I turn a map into a list of key followed by value? that is, not a list of pairs but a list of :key value :key2 value
20:49blaenkI tried running it through something like (comp concat seq) but it doesn't seem to flatten it?
20:52bbloom_,(apply concat {:x 1 :y 2 :z 3})
20:52clojurebot(:y 2 :z 3 :x ...)
20:53bbloom_blaenk: your error is that concat operates on multiple arguments
20:53bbloom_comp will only thread a single argument through the composition
20:53bbloom_and (concat anything) is anything
20:53blaenkwhat about (concat (seq themap))
20:53blaenkI guess that's unnecessary but wondering why it wouldn't work
20:53bbloom_(doc concat)
20:53clojurebot"([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."
20:53bbloom_notice the overloads ^^
20:54bbloom_check (source concat) in your repl too, you'll see that the single arity overload is a no-op
20:54bbloom_,(concat [1 2 3])
20:54clojurebot(1 2 3)
20:54bbloom_,(concat [1 [2 3] 4])
20:54clojurebot(1 [2 3] 4)
20:54blaenkohhh that's right
20:54blaenkthanks bbloom_
21:36rksm_Macro question: I want to splice in a conditional function call and combine it with a gensym arg like here: https://gist.github.com/rksm/562cd712cf843080cf4c
21:37DomKMHow does one implement clojure.lang.IMapEntry? Inlining it is producing an AbstractMethodError.
21:38bbloom_rksm_: you can splice a vector
21:38bbloom_,`[1 2 ~@(when true [3]) 4 ~@(when false [5]) 6 7]
21:38clojurebot[1 2 3 4 6 ...]
21:38rksm_The problem is the gensym
21:38bbloom_DomKM: what do you mean by "inlining it"
21:39bbloom_rksm_: oh, just use gensym explicitly in a let
21:39rksm_The problem is that the gensym inserted in the spliced form is not the same as defined in the let before. The ` in `(~fn arg#) seems to forget the arg name
21:39rksm_bound in the outer let
21:39bbloom_,(let [env (gensym "env")] `(let [~env 123] ....
21:39clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
21:39DomKMbbloom_: ,(deftype Foo [] clojure.lang.IMapEntry (key [_] 1) (val [_] 2))
21:40TEttinger(doc deftype)
21:40clojurebot"([name [& fields] & opts+specs]); (deftype name [fields*] options* specs*) Currently there are no options. Each spec consists of a protocol or interface name followed by zero or more method bodies: protocol-or-interface-or-Object (methodName [args*] body)* Dynamically generates compiled bytecode for class with the given name, in a package with the same name as the current namespace, the given fields, and, optionally,
21:40bbloom_DomKM: that's just a normal interface implementation... nothing "inlined" about it. when do you get the abstract method error?
21:40DomKM,(deftype Foo [] clojure.lang.IMapEntry (key [_] 1) (val [_] 2)) (key (Foo.))
21:40clojurebotsandbox.Foo
21:40bbloom_rksm_: you just can't use the auto gensym feature, just manual gensym
21:41DomKMwell that didn't work
21:41TEttinger,(deftype Foo [] clojure.lang.IMapEntry (key [_] 1) (val [_] 2))
21:41clojurebotsandbox.Foo
21:41bbloom_DomKM: clojurebot only evaluates one form, you can use (do ...)
21:41bbloom_or two lines
21:41TEttinger,(key Foo.)
21:41clojurebot#<CompilerException java.lang.ClassNotFoundException: Foo., compiling:(NO_SOURCE_PATH:0:0)>
21:41TEttinger,(key (Foo.))
21:41clojurebot#<AbstractMethodError java.lang.AbstractMethodError: sandbox.Foo.getKey()Ljava/lang/Object;>
21:41DomKM,( do(deftype Foo [] clojure.lang.IMapEntry (key [_] 1) (val [_] 2)) (key (Foo.)))
21:41clojurebot#<AbstractMethodError java.lang.AbstractMethodError: sandbox.Foo.getKey()Ljava/lang/Object;>
21:41bbloom_DomKM: look at (source key) it uses java.util.Map$Entry
21:42bbloom_it's looking for getKey():Object, not key():Object
21:42DomKMbbloom_: How is IMapEntry used?
21:42bbloom_also IMapEntry extends Map.Entry: https://github.com/clojure/clojure/blob/c9e70649d2652baf13b498c4c3ebb070118c4573/src/jvm/clojure/lang/IMapEntry.java#L15
21:42bbloom_i have no idea if IMapEntry is used at all, quite honestly
21:43bbloom_DomKM: seems like you just have no choice but to implement both key/val and getKey,getValue
21:44rksm_bbloom_: okay, thanks.
21:44bbloom_rksm_: seems like a historical accident: https://github.com/clojure/clojure/commits/master/src/jvm/clojure/lang/IMapEntry.java
21:45bbloom_seems like rich just made his own interface and only later discovered that Map$Entry existed, probably b/c it is sorta stealth, being an inner class and all
21:45bbloom_also, MapEntry has setValue too, which seems *insane*
21:45bbloom_you can just omit those
21:46bbloom_it never ever makes sense to mutate values in a map, lest you break the hashing
21:46DomKMThanks bbloom_
21:46bbloom_well, i guess that's key, can maybe change value but not key
21:46bbloom_either way
21:46bbloom_silly idea
22:03AWizzArdWhat is Incanter’s equivalent to Python’s (numpy’s) “linspace” function?
22:15shanemhansen AWizzArd : maybe http://clojuredocs.org/clojure_core/clojure.core/range ?
22:17blaenkis there a way to have lein repl autoload all namespaces in my project?
22:17blaenkor am I missing something?
22:17AWizzArdshanemhansen: range can be used, however, linspace is nice and is doing some math in the background.
22:18AWizzArdfor example, say you want the range -5 to 5 and you want 10 numbers. Then what is the right stepping? (solution: 1.11111…)
22:19AWizzArd,(range -5 5 (float 10/9))
22:19clojurebot(-5 -3.8888888359069824 -2.777777671813965 -1.6666665077209473 -0.5555553436279297 ...)
22:19AWizzArdHowever, I need to calculate the stepping myself. Thought there could be something in Incanter already.
22:20shanemhansenAWizzArd, oh I see. So like you kind of need to map a linear space to something like a logspace?
22:21shanemhansen(using logspace as an example of non-uniform point distribution, not implying you're actually using logarithms)
22:21blaenkanyone?
22:21clojurebotanyone is anybody
22:21AWizzArdYes, could well be.
22:43TEttingerblaenk, uh maybe. how many namespace are we talking?
22:44blaenkjust the namespaces in my project, under 10 I think. the weird thing is it seems it loaded them this time and I don't know why
22:44blaenkbut I can access them by fully qualifying them now
22:45TEttingerblaenk: here http://dequeue.blogspot.com/2014/01/reloading-lein-repl.html
22:46TEttingerit has a dev-dependency, but you can just call (refresh) in their lib and itreloads all of them
22:46blaenkthanks, knew about that, I meant when I first start it, being able to access the namespaces from the beginning
22:46TEttingerohhhh
22:46blaenkI don't know why but it seemed like it wasn't working before, maybe I was doing something wrong
22:46TEttingerso you want to import/require multiple at once?
22:46blaenkbut now it works. I can fully qualify them as project.something.whatever/function
22:47TEttingerhow are you requiring them?
22:47blaenkI'm not, actually
22:47blaenkI just start lein repl and I can refer to them that way
22:47blaenkwhich is what I wanted I think
22:47blaenkbut I thought it wasn't working before so I was wondering if there was something I had to do
22:49TEttingerah, here blaenk http://dev.solita.fi/2014/03/18/pimp-my-repl.html
22:49TEttingerthe nice thing about clojure is that people seem to blog every possible tweak you can do...
22:50blaenkthanks TEttinger
22:50TEttingerwell, and how short code is, how well all the seqs work, and lisp in general :P
22:50TEttingerno prob blaenk, I never got into full-fledged repl dev and this would probably help me