#clojure logs

2015-03-20

00:49Daniel_anybody out there?
00:58Daniel_how do i get involved with clojure open source?
01:10justin_smithDaniel_: do you want to contribute to clojure the language, specifically, or just the clojure community including libraries and tools and such?
01:10justin_smithif the latter, leiningen has tickets on github that are tagged as newbie friendly
01:18lvhIs there a smarter `every?`for tests that tells me which items didn't match?
01:19lvhOr do I write (= (filter pred coll) '())
01:20justin_smithlvh: you could also use (group-by pred coll) and then get a hash map with each unique result mapped to the inputs that led to it
01:20justin_smith,(group-by even? (range 10))
01:20clojurebot{true [0 2 4 6 8], false [1 3 5 7 9]}
01:21lvhjustin_smith: and then (nil? (m false))?
01:21justin_smithlvh: or empty?
01:21justin_smithbut if all you want to check is that none were false, group-by may be overdoing it
01:22justin_smithbut if you also wanted to check other mappings of in to out, group-by can be quite handy
01:22lvhwhoa, nil is empty? that sounds like more nil punning than I was expecting from clj
01:22justin_smith,(cons :because ())
01:22clojurebot(:because)
01:22justin_smitherr
01:22justin_smith,(cons :because nil)
01:22clojurebot(:because)
01:22justin_smiththat's why
01:23lvhfor some reason that surprises me less
01:23justin_smithwell if cons x nil makes a collection, then it makes sense to say nil is empty
01:23lvhright, sure
01:24lvhso, now I'm still confused as to what to write
01:24lvhI have a defspec with (every pred coll) in it, and I'm getting false back
01:25justin_smithwell, that's why group-by can be more informative
01:25lvhI wanted "these elements (not (pred elem))" or equivalent
01:25justin_smithyou can look at the coll of things that were falsey
01:26justin_smithor you could do an equality ##(= {false [1 3] true [0 2]} (group-by even? (range 4)))
01:26lazybot⇒ true
01:26justin_smithand then the error output will be more informative, right?
01:27lvhjustin_smith: ok, yeah; I'll do that. Thanks :)
01:27lvhjustin_smith: Is there a way to see values in stack frames when I look at stack traces?
01:28lvhI'm using cider; maybe I should use another editor for debugging
01:28justin_smithlvh: via debug connection, yeah - cursive has good tooling for that
01:28justin_smithalso, there is a browser based tool, schmetterling, that allows looking at locals
01:28anecider is awesome, it is getting a debugger, but cursive is the only one i think
01:28justin_smithit doesn't do stepping though, just looking at locals and evaluating in frame
01:29Daniel_hey guys i'm new to clojure and i want to get my hands dirty by doing some open source, but don't know where to start. can you guys point me to something?
01:29justin_smiththe cool thing about schmetterling is you don't add it to your project - it connects via a debug connection (like a profiler would)
01:29justin_smithDaniel_: did you see my question to you above?
01:30Daniel_justin_smith: damn, no i didn't. sorry about that
01:31justin_smithnp - do you want to contribute to clojure itself, or one of the clojure libraries / tools?
01:31justin_smithleinengen has a tag for beginner friendly tickets on github
01:31Daniel_justin_smith: i'm looking for something related to compilers?
01:32justin_smithas in the clojure compiler, or tools to build compilers using clojure?
01:32Daniel_the latter
01:32justin_smithDaniel_: you could check out instaparse for starters maybe
01:32justin_smithsee if there are any contributions you could make
01:33Daniel_justin_smith: thanks i'll check that out right now!
01:34Daniel_justin_smith: just wondering, how did you get started with clojure?
01:34justin_smithDaniel_: I got a job where it was being used, they sought me out because I had experience with other functional languages (scheme and ocaml)
01:35Daniel_did you look at any books in particular?
01:36justin_smithyeah, Programming Clojure and Joy of Clojure - I wouldn't recommend the latter unless you are experienced with common lisp or scheme, or already have some clojure experience and want to learn more
01:36justin_smithbut Programming Clojure is an excellent introduction
01:42irctcHello?
01:43justin_smithola
01:45irctcDoes anyone have experience compiling clojurescript from clojure?
01:46Daniel_justin_smith: thanks man. are you on the mailing list?
01:48justin_smithI check it sometimes
01:49justin_smithirctc: yeah, I have used the "
01:49justin_smithlein cljsbuild" plugin
01:49justin_smithbut not extensively
01:51irctcHmm okay
01:52irctcHave you ever encountered this error: SC_MISSING_PROVIDE_ERROR. required "cljs.core" namespace never provided ?
01:52irctcI'm totally stumped
02:05justin_smithno, that's one I have never seen
02:05justin_smithsorry
02:18mmitchellanyone know if it's possible to configure leiningen to use a different maven directory?
02:22irctcAh that's okay, thanks
05:23michaelr`morning
05:23michaelr`kind of..
05:24daniel`morning
06:03zotanybody know if there's a way to stack feature-expression and metadata declaration? specifically, this: (deftype Foo [#+cljs :mutable #+clj :volatile-mutable m])
06:04zotoops
06:04zots/:/^:/g
06:04zoti can duplicate the 'm' declaration, or just declare both w/o the feature-expr, but wondered if there's a better way
06:05TEttingerare feature expressions just metadata? I actually have no idea
06:07hyPiRionTEttinger: no
06:07TEttingeryay hyPiRion, someone who can answer questions is here!
06:12hyPiRionOr well, afaik there has been no decisions yet, but the proposal for reader conditionals is here: http://dev.clojure.org/jira/browse/CLJ-1424
06:14arav93Is there anyone familiar with typed clojure?
06:18zothyPiRion: interesting; sounds like i'm sticking w/ the hacks for now
06:24TEttingerarav93, you can ask a question and someone may see it later and be able to answer
06:24TEttinger~anyone
06:24clojurebotJust a heads up, you're more likely to get some help if you ask the question you really want the answer to, instead of "does anyone ..."
06:29zotlol. i don't think i ever start a question without something like "does anybody know …" :)
06:44kungi\o/
06:48clojerHas anyone tried running Clojurescript on JXCore, the threaded NodeJS alternative? If so, what implications for the number of threads it can service?
07:18borkdudewhat's a good way to add the appropriate content type to a binary file that is served from liberator?
07:18ordnungswidrigborkduke: the :available-media-types declaration
07:18borkdudefor a wide range of possible files: .doc, .pdf, etc without doing anything manual
07:19borkdudeit can be any type of upload
07:21ordnungswidrigborkdude: in this case I suggest detect the content type using http://ring-clojure.github.io/ring/ring.util.mime-type.html#var-ext-mime-type
07:21borkdudeI'll probably need this: https://github.com/ring-clojure/ring/blob/1.3.1/ring-core/src/ring/util/mime_type.clj
07:21ordnungswidrig:-)
07:21borkdudethanks ordnungswidrig :)
07:21ordnungswidriguse that in :available-media-types
07:22ordnungswidrigbeware that you need to return a collection of media types, so you might want to wrap the result in []
07:34borkdudeordnungswidrig I have one problem: in available-media-type I have to search for the files extension that I want to serve, since it's not available from the request, but that logic is in exists?
07:35borkdudeordnungswidrig I might as well set the Content-Type in :handle-ok
07:38ordnungswidrigyou can move the logic to available-media-types and store what you need in :exists? into the context. In :exists? you can access the information in the context again.
07:41borkdudeordnungswidrig so I can return a context map in available-media-types?
07:43borkdudeordnungswidrig I'm not sure where the actual media types go then. like this? {:available-media-types [....], ::file ...}
07:43borkdude?
07:43borkdudeor probably :representation
07:45ordnungswidrigAh, sure. sorry, that's not possible currently. You'd need to use `:media-type-available?` and call "conneg/best-allowed-content-type" yourself. I guess it's simpler to do the file type lookup in an earlier decision (I typically use `service-available`). And use that information in :available-type-types and :exists?
08:05jonathanjhmm, i have :java-source-paths ["resources/css2fopnew1_6_2.jar"] in my project.clj
08:05jonathanjbut i get this trying to use it: #<CompilerException java.lang.ClassNotFoundException: be.re.css.CSSToFOPNew, compiling:(documint/css2xslfo.clj:1:1)>
08:06jonathanja listing of the jar contents reveals that it is there: 8530 08-23-10 19:53 be/re/css/CSSToFOPNew.class
08:20TEttinger,(defn stateful-random[[^long s _]](let[R bit-shift-right,X bit-xor,a(unchecked-long(+ s 0x9E3779B97F4A7C15)),b(*(X a(R a 30))0xBF58476D1CE4E5B9),b(*(X b(R b 27))0x94D049BB133111EB),o(X b(R b 31))](print o)[a,o]))
08:20clojurebot#'sandbox/stateful-random
08:20TEttinger,(stateful-random 7)
08:20clojurebot#error{:cause "nth not supported on this type: Long", :via [{:type java.lang.UnsupportedOperationException, :message "nth not supported on this type: Long", :at [clojure.lang.RT nthFrom "RT.java" 905]}], :trace [[clojure.lang.RT nthFrom "RT.java" 905] [clojure.lang.RT nth "RT.java" 855] [sandbox$stateful_random invoke "NO_SOURCE_FILE" 0] [sandbox$eval50 invoke "NO_SOURCE_FILE" -1] [clojure.lang.Co...
08:21TEttinger,(stateful-random [7 8])
08:21clojurebot#error{:cause "bit operation not supported for: class clojure.lang.BigInt", :via [{:type java.lang.IllegalArgumentException, :message "bit operation not supported for: class clojure.lang.BigInt", :at [clojure.lang.Numbers bitOpsCast "Numbers.java" 1097]}], :trace [[clojure.lang.Numbers bitOpsCast "Numbers.java" 1097] [clojure.lang.Numbers shiftRight "Numbers.java" 388] [clojure.core$bit_shift_righ...
08:21TEttingersigh
08:22TEttinger,(defn stateful-random[[^long s _]](let[R bit-shift-right,X bit-xor,a(unchecked-long(+ s 0x9E3779B97F4A7C15)),b(unchecked-long(*(X a(R a 30))0xBF58476D1CE4E5B9)),b(unchecked-long(*(X b(R b 27))0x94D049BB133111EB)),o(X b(R b 31))](print o)[a,o]))
08:22clojurebot#'sandbox/stateful-random
08:22TEttinger,(stateful-random [7 8])
08:22clojurebot7565168461108830500[-7046029254386353124 7565168461108830500]
08:22TEttingersweet
08:23TEttinger(take 5 (iterate stateful-random [23 0]))
08:23TEttinger,(take 5 (iterate stateful-random [23 0]))
08:23clojurebot(4763265388078209808[23 0] 7406151029654480375[-7046029254386353108 4763265388078209808] 5903060928641107144[4354685564936845377 7406151029654480375] 4132843093337229763[-2691343689449507754 5903060928641107144] [8709371129873690731 4132843093337229763])
08:23ordnungswidrigTEttinger: I hope you're not implementing anything cryptographic ;-)
08:23TEttingernope
08:23TEttingerit's an RNG with 64 bits of state
08:24TEttingerit keeps its state around with it in a pair
08:24TEttingerso it could be used in pure functions
08:29ordnungswidrigTEttinger: can you split it?
08:29TEttingerheh
08:29TEttingerit's derived from the source to java 8'
08:29TEttingerit's derived from the source to java 8's splittable RNG
08:29TEttingerhttp://xorshift.di.unimi.it/splitmix64.c
08:30ordnungswidrigI see. but can you split it into two "stream", e.g. to be used in different threads.
08:32TEttingerI'm reading the docs on splitting the random
08:32TEttingerit uh
08:32TEttingerdoesn't seem to be much different
08:33TEttingerit looks like splitting a SplittableRandom just changes the state in some way of a new SRNG
08:43gfredericksTEttinger: what's this java 8 thing?
08:44TEttingerhttp://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html
08:44TEttinger^ gfredericks
08:47TEttingerhere's a big run of it https://www.refheap.com/98665
08:48TEttingerI'm not sure why they're all positive
08:49TEttingeris there an unchecked-xor, gfredericks?
08:51gfredericksTEttinger: I don't think that would make sense
08:51gfredericksthere's nothing to check for with xor
08:51TEttingersign bit?
08:51clojurebotexcusez-moi
08:51TEttingernearly 6 AM here
08:51gfredericksTEttinger: there's no such thing as overflow
08:51TEttingertime for beddie bye
08:52TEttingerright
08:52TEttingerok
08:52gfredericksTEttinger: "all positive" might mean you're representing 32 bit numbers with a long?
09:36timvisherhow crazy would i be to suggest that the repl should have the current ns on one line and `> ` on the line afterward?
09:36timvisherthat's how i do my `PS1` and it really helps when you're deep in a directory structure
09:37Empperi(clojure.main/repl :prompt (fn [] "this shall be your prompt >"))
09:38Empperireplace hardcoded string with what you want, eg. current namespace
09:39Empperiand to be fair, at least on my side of things "lein repl" shows the currently active namespace
10:08JeffsenTrying to run Clojure inside a Spring XD module. With Leiningen I made an überjar which contains clojure 1.6. I am calling from Java into Clojure.
10:09JeffsenWhen I place Clojure under the general lib folder I can find its classes. But not in a module. Can this happen because of Spring using its own classloader?
10:11JeffsenI clearly see that clojure.lang.Compiler is in my .jar file. In this jar I am running a java class.
10:11JeffsenAnd inside one of the methods of this class I do a Class.forName("clojure.lang.Compiler"); which fails.
10:27herrwolfeis it just me or is cider kind of difficult to get up and running reliably?
10:27justin_smithnot just you
10:27justin_smith~cider
10:27clojurebotcider is rage-inducing
10:28herrwolfeyeah - I've followed the directions exactly, and it never seems to work
10:28herrwolfethanks for validating my experience!
10:52stuartsierraDon't track CIDER master or dev snapshots, pick a stable version and stick with it.
10:54justin_smithit's too bad the official cider page doesn't suggest that
10:56stuartsierra~cider
10:56clojurebotcider is rage-inducing
10:57mpenetwell it does suggest to use melpa-stable an a non snapshot release in profiles.clj
10:57justin_smithit doesn't help that emacs doesn't make it easy to stick to stable packages.
10:57justin_smithmpenet: oh, I didn't see that just now
10:58justin_smith"Keep in mind that MELPA packages are built automatically from the master branch, meaning bugs might creep in there from time to time. Never-the-less, installing from MELPA is the recommended way of obtaining CIDER, as the master branch is normally quite stable and "stable" (tagged) builds are released somewhat infrequently."
10:58nullptrjustin_smith: it's pretty easy https://github.com/derekslager/dotfiles/blob/master/emacs.d/derek/package.el#L10
10:58justin_smithto quote the Princess Bride "you keep using that word"
10:59mpenetI have to say I never had an issue running from vanilla MELPA tho
10:59justin_smithgood to know
11:00nullptrthe mix of stable/unstable has worked better than expected -- some of the stuff on melpa-stable is really old
11:08mpenetDid anyone try dunaj? seems like an interesting experiment
11:08JeffsenHow can I find out which classloader was used to load a specific class C? I would like to load Clojure, which sits in a jar together with C.
11:10tomjackwow, multireducers
11:13tomjackhmm, I wonder what the "don't require excluding Clojure from deps" alternatives looked like, and why they were rejected
11:14tomjackPresumably existing Clojure libraries wouldn't behave as desired if they used Clojure instead of Dunaj?
11:15tomjackindent metadata! hah
11:20herrwolfempenet: what is odd, is i am tracking melpa-stable, yet I'm still getting the the nrepl too old error. Even after haviing nuked elpa packages
11:21herrwolfeI'm running vanilla emacs, installed from homebrew, with (doubtful that it matters) leiningen installed from brew
11:21mpenetherrwolfe: I never used stable, I wouldn't know where to start, but try pinging cider's maintainer, he's very friendly and helpful
11:21herrwolfempenet: gotcha - thanks!
11:49tomjackif you were starting a ring-style middleware library from scratch (i.e. not using any existing ring middleware), would you stick with -> or switch to comp?
11:50tomjackI guess maybe a similar sort of composition via comp has gotten Rich's stamp of approval through transducers, so comp may be more politically viable now? :)
11:51tomjackoh, I guess like transducers one would maybe want to support both, which is kind of troublesome :(
11:59gfrederickstomjack: you're just asking about the syntax for composing middleware?
11:59gfredericksnot about implementing middleware?
11:59gfredericksmaybe I'm confused
11:59gfrederickscomp is less general isn't it?
11:59gfrederickser
12:00tomjackthe question is whether you write (fn with-foo [foo] (fn [app] (fn [req] ...))) or (fn with-foo [app foo] (fn [req] ...))
12:01gfrederickswhat is app?
12:01gfredericksis this not about http servers?
12:01tomjackam I confused? it's the ring app
12:02tomjackanother (fn [req] ...) which returns a response
12:02gfrederickstraditional ring middlewares are (fn [handler] (fn [req] ...)) right?
12:02tomjackoh, ok, s/app/handler/
12:02gfredericksokay gotcha
12:02gfredericksand foo is just a way to customize the middleware?
12:02tomjackyeah, like say the root domain name of your app or something
12:02gfredericksgotcha
12:03gfredericksit's funny you have 3 fns and I often think of the alternative of 1 fn
12:03gfredericksusually when monkeypatching with alter-var-root though
12:03gfrederickse.g. (alter-var-root #'some-func (fn [orig] (fn [& args] ...)))
12:03tomjack(my case is not actually about http servers, but asking the question about a from-scratch ring works too)
12:03gfrederickscompared to robert.hooke (add-hook #'some-func (fn [orig & args] ...))
12:04tomjackeh, I just want to do (-> fallback with-foo with-bar) or ((comp with-bar with-foo) fallback) :)
12:05tomjackyou could try to write (fn with-foo ([foo] ...) ([handler foo] ...)) but this doesn't always work out so nicely
12:05tomjackso I suspect it's best to just pick one way
12:06tomjack(I sometimes wonder if the reason we don't have a (partition 2 1) transducer is just hil-arity)
12:17timvisherdoes anyone know how midje can creep into your execution path?
12:18timvisherwhen i load files, it suddenly decides to start running tests on each request
12:18timvisherthe test ns is not required anywhere that i can tell
12:18timvisheris it auto-test by default or something?
12:19timvisheri.e. i `C-c C-l` in emacs over cider-nrepl
12:30timvishermaybe another question i could be asking is what exactly `cider-load-file` does. i don't understand how midje is getting into the mix at all
12:31timvisherbut loading the file produces the behavior consistently
12:34timvisheri have `[midje "1.6.2"]` in my `:dev :dependencies`, `[lein-midje "3.1.3"]` in my `:dev :plugins`,
12:34timvisheri'm starting the repl via `:nrepl {:start? true}` in `:ring` project.clj config
12:36timvisherif something in the `(ns ...)` declaration is pulling in the test by extension, i should see the same behavior if i just eval the ns form right?
12:38timvisherEmpperi: i didn't know about that. sadly, doesn't look like cider supports configuring that at the moment.
12:42timvisherevaling the ns form didn't do it...
13:30jcromartieI feel like it's a bit of a code smell when type names are all over our code
13:30jcromartiedefrecords or deftypes
13:31jcromartieis there a good discussion about API design and protocols/records?
13:32gfredericksjcromartie: well for records you don't need to use the type name directly for constructing
13:32gfrederickssince the constructor fns get defined; but maybe that's not what you meant
13:33jcromartieeven those
13:33jcromartie(map->Whatever ...)
13:33gfredericksgotcha
13:33jcromartieI just mean, having a lot of code related to dealing with certain specific types seems to defeat the point of polymorphism
13:33gfredericksit is still indirection
13:34gfredericksmap->Whatever doing (Whatever. ...) is technically in impl detail and could change
13:35gfredericksbut regardless
13:35gfredericksjcromartie: you could use protocols for all the things your types do and maybe only reference the types at a top-level component-style system definition
13:35jcromartiewe've got a fairly detailed data model
13:35jcromartieand it's lots and lots of records, nested with in each other
13:36jcromartiemakes constructing and manipulating a little tricky
13:36Glenjaminis there a reason they're not just maps?
13:36jcromartiesay, you want to represent a polygon
13:36jcromartiewhich is a bunch of records
13:36jcromartie(defrecord Polygon [rings]) (defrecord Ring [points]) (defrecord Point [lon lat])
13:36jcromartieit gets cumbersome
13:37jcromartiebut I don't have a better example :)
13:37jcromartieI mean I don't have a good alternative to offer to that design
13:44lvhIs there a name for constraininga n integer to an interval?
13:44lvhI know how to write it with #(min (max low %) high), but idk if there's a thing for that somewhere already
13:45gfredericksdon't think so
13:45gfredericksI saw that named "clamp" in a google lib somewhere
13:45gfredericksclosure probably
13:45lvhaaah that's the word I was looking for :)
13:46gfredericksoh I thought you were looking for an existing function
13:46gfredericksglad I accidentally answered the question anyways
13:46lvhgfredericks: I was
13:46lvhgfredericks: I was hoping not to have to look for it at all, but if I have to write it I might as well give it a name
13:46gfredericksokay I retract my misconceived gladness
13:47gfredericks(-> % (max low) (min high))
13:56charlespwdCan someone explain why (def log (.-log js/console)) (log "hi") throws an Illegal invocation where (def cos (.-cos js/Math)) doesn't?
13:59charlespwd,((.-log js/console) "hi")
13:59clojurebot#error{:cause "No such namespace: js", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: No such namespace: js, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6535]} {:type java.lang.RuntimeException, :message "No such namespace: js", :at [clojure.lang.Util runtimeException "Util.java" 221]}], :trace [[clojure.lang.Util...
14:01crash_epbecause .log is a method, not a property
14:01charlespwd.-log is
14:02charlespwdno?
14:02clojurebotno is tufflax: there was a question somewhere in there, the answer
14:02gfredericksthere's nothing in clojure for java's >>>? I have to write it myself?
14:04tbaldrid_,(doc unsigned-bit-shift-right)
14:04clojurebot"([x n]); Bitwise shift right, without sign-extension."
14:04tbaldrid_gfredericks: ^^
14:07gfrederickstbaldridge: oh geez apparently I didn't know what >>> did
14:07gfredericksI thought it was rotate
14:07gfredericks(inc tbaldridge)
14:07lazybot⇒ 20
14:07gfredericksplease tell me it's at least rotate in some other language
14:07alejandrozfhow much Java is a must to learn Clojure if Ihave some Lisp experience?
14:08alejandrozfsorry,hi!
14:08gfredericksalejandrozf: depends on what you're doing
14:08gfredericksprobably the thing you get the most mileage out of is understanding the java/jvm object model and reading javadocs
14:08alejandrozfgfredericks: i want to code mainly in clojure, but using Java libs
14:09agarmanalejandrozf: you really don't need to learn Java, but you will end up learning the JVM
14:09gfredericksyeah the java language proper is almost irrelevant
14:09alejandrozfJVM is hard to learn?
14:10gfredericksprobably not for your purposes
14:10alejandrozfagarman:, gfredericks : it's a relief...
14:10agarmandepends upon what you're trying to do
14:10gfredericks,(type "foo")
14:10clojurebotjava.lang.String
14:10gfredericksalejandrozf: ^ inspecting objects like that will give you familiarity
14:11gfredericksif it's a java class you can read the javadocs for it, via google
14:11gfredericks$google java 8 string javadoc
14:11lazybot[Overview (Java Platform SE 8 ) - Oracle Documentation] http://docs.oracle.com/javase/8/docs/api/
14:11gfredericksbad example :(
14:11gfredericksit's probably the third result or something
14:11agarman,(javadoc java.lang.String)
14:11clojurebot#error{:cause "Unable to resolve symbol: javadoc in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: javadoc in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6535]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: javadoc in this context", :a...
14:12alejandrozfsay ,for instance I want to create a game with a lot of graphic stuff...
14:12agarmanthat function will bring up the javadoc in your browser
14:13alejandrozfagarman: thanks, it's a good point to start...
14:13agarmanalejandrozf: there are a couple folks trying to make game engines for Clojure...http://www.yetanalytics.com/blog/2015/3/18/functional-game-development-and-building-skills-with-exercismio?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+Blog-YetAnalytics+%28Blog+-+Yet+Analytics%29
14:13agarmanwow, what a long URL...my bed :-/
14:13agarmanbad
14:13alejandrozfagarman: :)
14:14agarmanhttps://www.youtube.com/watch?v=0GzzFeS5cMc
14:15agarmanhere's github for that https://github.com/oakes/play-clj
14:15alejandrozfI want to start programming Clojure, comming from CL, Racket, Python,C/C++,...
14:17agarmanhere's another fun resource http://lispgames.org/index.php/Clojurescript
14:18alejandrozf with wish me luck!, ands thanks agarman, gfredericks :), see you soon ;)
14:26gfredericksI feel like the fact that unchecked-{multiply,add} falls back to checked operations is a bug, but it's so clearly intentional
14:26gfredericksit makes me grumpsy
14:26gfredericksI guess I can just make a helper macro
14:28Bronsagfredericks: uh? how does it fall back to checked ops?
14:32Glenjamin,(unchecked-add Integer/MAX_VALUE 10000)
14:33clojurebot2147493647
14:33Glenjamini have no idea if that's right or not :s
14:33Glenjamin,(+ Integer/MAX_VALUE 10000)
14:33clojurebot2147493647
14:34amalloyGlenjamin: unchecked-add is for longs, so that's not much of a surprise
14:35Glenjaminah, i thought that might be it, but also realised i didn't know what i was doing - so unlikely to be helpful
14:35Glenjamin,(unchecked-add Long/MAX_VALUE 10000)
14:35clojurebot-9223372036854765809
14:35Glenjaminthat looks right though
15:19gfredericks&((fn [x] (unchecked-multiply x x)) 999999999999999)
15:19lazybotjava.lang.ArithmeticException: integer overflow
15:19gfredericksBronsa: ^
15:19gfredericksvs
15:19gfredericks&((fn [^long x] (unchecked-multiply x x)) 999999999999999)
15:19lazybot⇒ 5074944270305263617
15:19Bronsauh
15:20Bronsaso the unchecked_add(Object,Object) arity is wrong?
15:20gfredericksit's highly misleading
15:20gfredericksat least
15:21gfredericksthe impl is just add(x, y)
15:21gfrederickswhich makes it look intentional
15:21Bronsa,((fn [^long x y] (unchecked-multiply x y)) 999999999999999)
15:21clojurebot#error{:cause "Wrong number of args (1) passed to: sandbox/eval25/fn--26", :via [{:type clojure.lang.ArityException, :message "Wrong number of args (1) passed to: sandbox/eval25/fn--26", :at [clojure.lang.AFn throwArity "AFn.java" 429]}], :trace [[clojure.lang.AFn throwArity "AFn.java" 429] [clojure.lang.AFn invoke "AFn.java" 32] [sandbox$eval25 invoke "NO_SOURCE_FILE" -1] [clojure.lang.Compiler e...
15:21Bronsa,((fn [^long x y] (unchecked-multiply x y)) 999999999999999 999999999999999)
15:21clojurebot#error{:cause "integer overflow", :via [{:type java.lang.ArithmeticException, :message "integer overflow", :at [clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501]}], :trace [[clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501] [clojure.lang.Numbers multiply "Numbers.java" 1867] [clojure.lang.Numbers$LongOps multiply "Numbers.java" 467] [clojure.lang.Numbers multiply "Numbers.java" 1...
15:21hiredmangfredericks: someone must have pointed you at primitive-math by now, right?
15:22Bronsait looks like the only unchecked_add arity that overflows is actually the (long,long) one
15:22Bronsaweird
15:22gfrederickshiredman: I'm aware of it
15:22gfrederickshiredman: it's hard to imagine any use for the current behavior
15:22hiredmanjust making sure
15:22hiredmansure
15:25gfredericksBronsa: do you think this could be reported as a bug? i.e., do you think there are any reasonable worries about "breaking" changes?
15:27Bronsagfredericks: i would report this as a bug, yeah
15:28gfredericksHypirion: ping
15:29hiredmanI think the first hacking I did on the clojure compiler was to add jop special form so you could (jop + 1 2) and get an iadd
15:31hiredmanhttps://github.com/hiredman/clojure/commit/1732cdbf2d752d35573e2e74ffe642bc7b73eae1
15:37numbertendoes test.check.generators have something for floats?
15:37gfredericksnumberten: I thought there was something
15:38numberteni don't see anything in the docs, but it feels like something big to be missing
15:38clojurebotCool story bro.
15:38gfredericksnumberten: there's also this https://github.com/gfredericks/test.chuck/blob/master/src/com/gfredericks/test/chuck/generators.clj#L207-216
15:39gfredericksnumberten: or (gen/fmap double gen/ratio) maybe? I forget if gen/ratio exists
15:40numbertenthanks
15:42gfredericksnumberten: I think the goal of the test.chuck version is to generate all possible doubles
15:44gfredericksI'm trying to figure out how to build two uberjars with different lein profiles
15:44gfrederickscurrently I get them both to build but the first one gets deleted
15:44gfredericksdoes anybody know how to do this?
15:57gfrederickslooks like it behaves differently depending on whether you use a generic :target-path at the top level or a specific one in each build profile
16:01dmitrig01hey - writing tests with midje. I have a function A which sometimes calls function B. I want to mock out B and verify that, under the right circumstances, B is called. What’s the best way to do this?
16:03tbaldrid_dmitrig01: I always suggest that you don't do that. Instead, measure either the output of A or the side-effect of B.
16:03tbaldrid_Why do you care if B is called or not? You might refactor later and remove, B, then you have to change all your tests
16:04dmitrig01mm, that’s fair
16:04tbaldridgeMost likely there is a contract between A and B, somehow make the code so that contract is either expressed with a protocol, or some other interface, then you can easily swap out the B side of the contract.
16:05tbaldridgeA common mistake I've seen is that people write tests that mock A and test B, and then other tests that mock B and test A. But A and B don't respect the same contract, and then all sorts of fun ensues. .
16:12dmitrig01tbaldridge: that’s a really good point. i guess at this point, I haven’t yet written B, but I still want to ensure A works
16:14DraggorFor doing TDD in clojure, is clojure.test enough or is there a preferred testing framework people tend to use?
16:14tbaldridgedmitrig01: this is one of the really nice features, IMO, of component (https://github.com/stuartsierra/component) it allows you to express your contracts as part of the components.
16:14tbaldridgeDraggor: simpler is better, stick with clojure.test
16:24borkdudeI like clojure.test as well
16:24justin_smith(inc clojure.test)
16:24lazybot⇒ 4
16:25borkdudealso clojure.java.jdbc is cool. what is your favorite clojure.* library or namespace? ;)
16:29arrdemincluding contrib, test.check hands down
16:47arohnerdistinct-by doesn't exist anywhere, right?
16:47arohneri.e. (distinct-by f coll)
16:48Bronsaarohner: what would that do? deduplicate equal (f x) ?
16:48arohnerBronsa: yes
16:49Bronsaarohner: but say you have (f a) == (f b) but a!=b, would (distinct-by f [a b]) return [a] or [b]?
16:49Bronsai guess you wouldn't care?
16:50arohnerBronsa: I don't have that situation in my code, but I'd return [a]
16:59justin_smith(comp (partial map first) vals group-by)
16:59justin_smithwould be one way to do it at least
16:59justin_smiththe reduce version would be faster, dunno how much faster
17:01anti-freezeHey everyone, so I'm trying to set up a csrf token fixture to run tests on ring mock requests. Anyone know how to do that?
17:06arohneranti-freeze: can't you GET the page, store the 'cookie', and then POST?
17:08anti-freezearohner: I'm attempting to post the data to a route. I mean, I could do that, but it seems rather counter-intuitive. Me and another user figured out yesterday that providing the __anti-forgery-token in the parameter map won't help, so setting the token in the header should help. I just have no idea how to do that in ring
17:08arohnerit's just part of the ring request: {:request-method :get :uri "/foo" :headers {"x-csrf-ring" "abcdef"}}
17:09arohner(I don't know if that's the correct name of the header)
17:09arohnerbut your request's token needs to match what ring has in memory, which is the whole point of anti-csrf
17:09arohnerwhich is why I suggested GETing the page first, because that's what the 'real' behavior expects
17:10justin_smithanti-freeze: my advice is same as before, just test the handler directly. But if you really want to mock things, what arohner is saying is the right thing.
17:11arohnertrue, if you dont care about CSRF behavior for your test, just make the handler w/o that middleware
17:11anti-freezeIsn't there a better way to test requests like this?
17:12arohneranti-freeze: depends on your goals. If you want super-fast unit tests, this is the "best" way. If you want an easy test, use clj-http, with cookies enabled
17:12justin_smitheither use the middleware as it was designed (that is, getting the token from a get so you can provide it via a post, and use a cookie to propagate), or directly test the handler
17:13anti-freezeAlright, I'm a real clojure noob, coming from a professional rails background, can someone demonstrate an example. I'm really lost
17:14arohneranti-freeze: oh, you can also fake it by providing the token in the form params, and your cookie
17:14anti-freezearohner: Form params didn't work last time
17:14arohneranti-freeze: which storage are you using for sessions? (cookies, DB, in-memory)?
17:14anti-freezearohner: in-memory at the moment
17:15anti-freezearohner: I have something like this. response (app (request :post "/register" {:__anti-forgery-token *anti-forgery-token* :username "someone" :email "a@a.com"...
17:15anti-freezeDoesn't work
17:16arohnerright, because you're not faking the session CSRF token
17:16anti-freezeHow would I do that?
17:16arohnerant-forgery works by requiring that the form params, and the ring session, share the same secret (the token)
17:16arohnerone sec
17:17arohneranti-freeze: you'd need to munge the session storage, created by ring.middleware.session
17:17anti-freezearohner: munge?
17:18arohnermess with it
17:18arohnermake the token stored in the session match the one you're setting in the form params
17:18arohnerif that doesn't make sense to you, I recommend going with the closer-to-real-world version, which is using cookies
17:18arohnerthe way a real user would
17:19anti-freezearohner: Is that how you would test it?
17:19arohneryeah, use clj-http, and look at using cookies: https://github.com/dakrone/clj-http#cookie-stores
17:20anti-freezearohner: So, I would have to send a request to get the relevant route, extract the cookie for the csrf token somehow and then send the same data in the post request?
17:20justin_smithanti-freeze: yeah, but you should be able to work on the side of things where you are just reading/ writing the :session key not messing with the cookie itself. I think.
17:21arohneranti-freeze: just GET the page, and then post, using the same cookie maanger
17:21arohnerbecause you're using cookies, the session identity gets transferred 'for free'
17:22arohneroh, right you would need to extract the CSRF cookie
17:22justin_smitharohner: is it its own cookie, or is it just part of the session?
17:23anti-freezeAlright, I'll give it a go
17:23anti-freezeI have no idea
17:23arohnerhrm.
17:23arohnerjustin_smith: yeah, it is part of the session
17:24arohnerwhich means if you're using in-memory, you can't extract, because the cookie just holds the session id
17:24arohneranti-freeze: how are you creating the session middleware?
17:24arohnerand how are you enabling anti-csrf? ring-defaults?
17:24justin_smitharohner: right - I think you would have to invoke the anti-forgery wrapped handler, not call into ring
17:25justin_smithor, you could write a dummy handler for get which gives you your anti-forgery token so you can then provide it
17:25justin_smitheg. the way it would normally be embedded into a hidden input
17:25justin_smithbut in this case you would likely just put it in a json
17:25anti-freezeI do a wrap-anti-forgery
17:26arohnerand sessions? if you (wrap-session :store (in-memory...)), then you'd have access to the atom, and you can muck with it
17:26arohneranother option is to disable anti-forgery in tests
17:27anti-freeze(wrap-defaults (assoc-in site-defaults [:session :store] (memory-store session/mem)))
17:27anti-freezesession/mem is just an (atom {})
17:27justin_smitharohner: yeah, that was my first inclination - to just call the handler as a function instead of all this mocking stuff
17:28arohneranti-freeze: right, after GETting the page, that atom should have interesting things in it
17:28anti-freezeHow would I set up a test enviromnent, sort of like in rails
17:28anti-freezeJust disable csrf completely
17:29arohnerwell the handler is created by a function, right?
17:29anti-freezethe production middleware
17:31anti-freezeI don't want to just be commenting and uncommenting the anti-forgery handler for every test, that's just plain stupid
17:31justin_smithanti-freeze: you can either bind the handler function that the anti-forgery middleware wraps such that you can access it directly, or you can make a "maybe-antiforgery" middleware
17:32justin_smith(defn maybe-antiforgery [handler] (if testing handler (wrap-anti-forgery handler)))
17:32anti-freezejustin_smith: Ah, this is why people don't write tests. Writing middleware just to run POST request mocks?
17:33justin_smithanti-freeze: no, I use the first option, making sure my handler is a top level definition that I can call directly
17:33justin_smithand ring uses the middleware wrapped version
17:33justin_smithif I need the middleware while testing, I can add that in the test
17:33anti-freezeYea, but I need the middleware in development/production, just not in a test environment.
17:34justin_smithright, so in your test, you call the handler + relevant middleware to the test
17:34justin_smithin production, you call the handler, wrapped with the production middleware
17:34justin_smithand in development, you call it wrapped in the development middleware
17:34justin_smithetc.
17:34justin_smithperhaps I should be using the term "endpoint"
17:35justin_smithbecause when I am testing, I don't even test the routing part, I just call the function implementing the endpoint that would be routed to
17:35justin_smiththat's where the stuff I need to test is
17:36anti-freezejustin_smith: Alright, so lets say I did test the endpoint, how would I check for a certain response type. For example, a successful login would redirect to /, giving a 302
17:37justin_smithanti-freeze: then you establish that it returns {:code 302 :body "/"}
17:37anti-freezeso a redirect is just a map?
17:37justin_smithanti-freeze: any ring response is just a map
17:37justin_smithjust like the request
17:37justin_smithit's super easy to test ring endpoints for that reason
17:38anti-freezeOh, sweet.
17:38anti-freezeSo I was going the long way round
17:38justin_smithwell technically ring will accept some other things to (a string or a list that becomes a string) but if you use the canonical form, then tests are easy)
17:39justin_smithanti-freeze: yeah, I should have been more explicit about why I was saying "just call the endpoint without the middleware"
17:39justin_smithI guess I assumed everybody knew handlers / endpoints just return maps in ring
17:39anti-freezejustin_smith: No worries, this is a little new to me. The whole bundle stuff together and hope it works mentality
17:40justin_smithanti-freeze: it's pretty sweet actually, because this means handlers can be pure functions - you give them a map, you get another map back
17:40justin_smithmocking looks very complicated in comparison
17:41anti-freezejustin_smith: Why is there no resources on this though? I mean, I googled extensively and got nothing.
17:41justin_smithfrankly I have no idea
17:41Risiko91Hi guys!! I'm getting crazy with a stupid thing... I've a ns named `a_b_c.d` and a protocol and a record defined in it. I need to import these in my repl and I did write (import 'a_b_c.d.Protocol) but I did obtain only errors... how to do it correctly?
17:41arohnerbecause clojure http is so well factored that there's nothing "in one place"
17:41arohnerit's all scattered through ring, compojure, friend, etc
17:41justin_smithanti-freeze: it's a blog post I have no excuse for not having written yet, I guess
17:42anti-freezejustin_smith: It just seems a little hard for compojure noobs to get started, especially if they expect the functionality of a full-stack. Luminus is sort of there, but not really
17:43BronsaRisiko91: protocol/records classes are created dynamically upon namespace load, you can't import them if you haven't loaded (i.e. (require 'a_b_c.d)) it
17:43justin_smithanti-freeze: we worked on caribou for a while, it had some flaws but it could have been the thing. It got its funding discontinued though.
17:44Risiko91lasergoat: I've just typed (use ''a_b_c.d)... isn't enough?
17:44anti-freezejustin_smith: Where do you suggest people go now? I was debating between scala and clojure for a startup. Atleast scala has play2, which I know is against the clojure philosophy, but still...
17:45justin_smithanti-freeze: I'd still suggest clojure, with luminous or liberator most likely. Scala is gratuitously complex in so many ways. Hell, go haskell if you can before using scala.
17:46anti-freezejustin_smith: Scala just seemed like a more functional style ruby that runs on the JVM. I like the JVM. Maybe its just my general unfamiliarity
17:47anti-freezewith clojure that is
17:47Risiko91Bronta: Can I use `use`?
17:47anti-freezeI suffer from a serious case of 'the grass is greener' syndrome
17:47arohnerthe 'default' stack is quite good, it 'just' requires you to understand how the pieces fight together
17:48justin_smithRisiko91: if the file is named a_b_c/d.clj use/require would expect a-b-c.d
17:48anti-freezearohner: Writing the glue between them is still required though. Architecture and what not
17:48anti-freezearohner: Extra startup and setup time
17:48arohneranti-freeze: yes, but that's a good thing IMO
17:49anti-freezearohner: I don't know. I'm having my doubts
17:49arohnerit's longer to get 'hello world', but it's shorter to get to production
17:49arohnerand more understandable, and less need to throw everything out and start over when a new framework comes to town
17:49arohnermore understandable at the upper end. yes, it's harder on noobs
17:49anti-freezePerhaps, I'm just frustrated because I've barely got past login/register and I can't seem to even test it
17:50arohneranti-freeze: understandable!
17:51Risiko91Ohh yes... a nasty neewbie error!! I never remeber it!! Thanks justin_smith
17:51anti-freezearohner: I suppose i'll give the clojure stack another go. I do like lisp more than ML like languages anyway. My patience is wearing thin though, people expect to see results
17:53anti-freezeespecially the non techy, spiky haired boss
17:53anti-freeze:P
17:56anti-freezejustin_smith, arohner: Thanks for your help guys, I really appreciate it.
17:57fredddhey all. if i'm using the clojure 1.7 alpha 5 (and hence, transducers), are there any special exclusions when requiring core.async so that I have one map/filter/reduce, etc. that works everywhere?
17:58arohneranti-freeze: no problem :-)
17:58arohnerfreddd: I don't think so. Just use the newest release core.async and you should be good to go
18:01celwellHi, in a map, how do I get the key whose value returns true for some predicate fn?
18:04fredddarohner: ok, i think i'm actually misremembering. do you know off-hand if core.async ever had its own map/filter, etc.?
18:05arohnercelwell: (filter (fn [[k v]] (f k) the-map)
18:05arohnerfreddd: yes, it did, but they were named like map< or something like that
18:05arohnerthey might still be there, but deprecated
18:05arohnercelwell: I accidentally a )
18:08fredddarohner: ok, thanks.
18:08numbertenis there a function that turns strings into regex?
18:09fredddarohner: regarding celwell: you are returning the key-value there, but he might just want the key. i think it's a little ambiguous, though.
18:09celwellI only want the key. I could use this of course, but if there a more elegant way?
18:10numbertenre-pattern :)
18:13fredddcelwell: i can't think of a pretty way. either that filter that arohner mentioned nested inside a map (as in the higher-order function), or just a map (again, higher-order) with a less-pretty function.
18:13celwellthanks
18:14arohnercelwell: (some (fn [k] (f k)) (keys the-map))
18:14justin_smith(filter p (keys m))
18:14justin_smith(some p (keys m))
18:14celwellbut I have to apply the predicate fn to the vals of the map
18:14justin_smitharohner: (fn [k] (f k)) is a little silly :)
18:15justin_smithcelwell: then vals m instead of keys m
18:15celwellbut i need to get the key
18:15justin_smithahh, if the val matches a pred, give you the key
18:15celwellyeah
18:15justin_smith(first (keep (fn [[k v]] (when (p v) k)) m))
18:16celwelli guess i figured there was a core fn for this use case but i guess not
18:16justin_smith,(some (fn [[k v]] (when (even? v) k)) {:a 0 :b 1 :c 2 :d 3 :e 4})
18:16clojurebot:a
18:17justin_smiththat's my final answer
18:17celwellthanks
18:17justin_smiththough finding "the first" in a map is complicated, since they are not ordered, of course :)
18:18mavbozocelwell: it's possible there are many keys whose values satisfies the predicate right?
18:18arohnercelwell: the core fns are designed to be composable and reusable your precise problem seems a little niche
18:18fredddjustin_smith: bravo
18:19anti-freezeAlso, any ideas as to why the REPL takes ages to run anything?
18:19justin_smithfreddd: thanks
18:20mavbozoanti-freeze: REPL from? terminal? emacs?
18:20oddcullyanti-freeze: ages?
18:21mavbozosometimes I have to restart my emacs
18:21anti-freezeTerminal
18:21justin_smithanti-freeze: are you printing very long lines in emacs?
18:21justin_smithoh
18:21anti-freezeStraight up lein repl|test|ring server
18:21justin_smithmaybe your heap usage is making your machine swap?
18:22anti-freezejustin_smith: I dont know, seems to run fine with other JVM repl's (e.g. scala).
18:23justin_smithanti-freeze: I'd connect a profiler, see what the hell it's trying to do
18:23justin_smithyourkit is free for open source projects, visualvm is free and comes with oracle jdk releases
18:23anti-freezejustin_smith: I'll check it out
18:24anti-freezejustin_smith: Do you think it could be eastwood
18:24anti-freeze?
18:24justin_smitheastwood shouldn't be running by the time your app is running
18:24justin_smithit's a task plugin
18:24fredddjustin_smith: thanks again for the answer to celwell. i always think of some as returning true or false, not truthy or falsey.
18:25anti-freezejustin_smith: So, it could be anything then?
18:25justin_smithfreddd: ahh yeah, that's overloaded, some is being used to get the first truthy result there
18:25justin_smithanti-freeze: well, a profiler should show you what's up pretty quick
18:26justin_smithor you could run jstack on the process while it is slow to just see what all the threads are doing
18:26justin_smithit gives a stack trace for every thread in the vm
18:27anti-freezejustin_smith: Maybe its just because its loading all that compojure/ring/* stuff
18:29justin_smithanti-freeze: are you talking about how slow the startup is, or responsiveness once it is up and running?
18:29anti-freezejustin_smith: Start up. I should have clarified
18:29justin_smithanti-freeze: oh, that's a different question, yeah
18:29anti-freezeI apologise
18:30justin_smithanti-freeze: the main overheads for startup time are lein, nrepl, and the clojure runtime
18:30justin_smithanti-freeze: the leiningen guide to fast startup https://github.com/technomancy/leiningen/wiki/Faster
18:30anti-freezejustin_smith: Ah. Its just annoying because it takes ages to get the tests running
18:30justin_smithright
18:31justin_smithanti-freeze: I will often write my tests such that I can leave a repl open and run them over and over again from the repl
18:31justin_smithbut that wiki article has a bunch of good ways to speed things up
18:31anti-freezejustin_smith: Ah, is there a way I can run clojure.test tests in the repl? It won't be an issue for much longer as I'm planning on switching to midje
18:31justin_smith(clojure.test/run-tests)
18:32arohneralso, (clojure.test/run-tests 'the.namespace)
18:32anti-freezejustin_smith: Nice. I can't thank you enough
18:32justin_smithand midge is weird (though it has some fans, I'll acknowledge).
18:32arohnerand (the.namespace/a-single-test)
18:32justin_smith$karma midje
18:32lazybotmidje has karma 1.
18:32anti-freezejustin_smith: Any other recommendations on a better testing framework?
18:33justin_smithexpectations and clojure.test are the two I would consider
18:33justin_smiththat plus remembering that in clojure you can make a lot of things into pure functions, and pure functions are really easy to test
18:33arohnerI would recommend clojure.test over midje
18:33anti-freeze$karma speclj
18:33lazybotspeclj has karma 0.
18:34justin_smithanti-freeze: one trick is to separate the side effecting code into on function, and have that function use another (pure) function that implements all the logic
18:34anti-freezeI guess I'll have to make up my mind on that one. Anyway, I'm off to bed. Thanks again
18:34justin_smiththen you make a couple simple tests for the side effecting part, and as many tests as you need for the pure one (which is much easier to test, so putting most of your logic there is convenient)
18:39lvhHow does multimethod replacing work again? ISTR that you can't just recompile to replace dispatch-fns, but how about method impls?
18:40justin_smithlvh: method impls should just work with a reload, but you need to assign the defmulti itself to nil before it can be reassigned
18:40justin_smithor destroy it's var
18:40justin_smithdef to nil is easier
18:40lvhaha, okay
18:40lvhI guess I was just screwing uip the recompile then, because I think I just saw both
18:40lvhthanks, justin_smith!
18:40justin_smithlvh: oh, I made an example of that for grimoire recently
18:41justin_smithlvh: http://conj.io/store/v0/org.clojure/clojure/1.7.0-alpha4/clj/clojure.core/defmulti/ if you search for "defonce" you can see a demo of redefining a defmulti
18:41lvhthank you!
18:44coopernursehi folks - tools / workflow question. when you're using a new library, what's your preferred way to explore what functions are available?
18:44coopernurseI'm reading this: http://stackoverflow.com/questions/2747294/how-to-list-the-functions-of-a-namespace - which suggests (ns-publics) - any other tips?
18:44justin_smithcoopernurse: clojure.repl/dir clojure.repl/doc clojure.repl/source
18:45danlentzi like to read the code
18:45danlentzbut “lein cloc” is pretty
18:45justin_smithand then of course just plain reading the code, yeah :)
18:45coopernurseI haven't tried "lein cloc" - that looks promising. thanks
18:45nullptrcoopernurse: git clone + README.md + ag defn
18:46danlentzi really wish the clojuredoc process was more reasonable
18:47justin_smithnullptr: bonus points - if you use ag inside emacs as your arg to M-x rgrep, you get clickable / press-enter-to-follow links to each line number
18:47danlentzsomething that worked just like “codox” but generated the standard Clojure api documentation output
18:47coopernursedo any of those functions work with pure Java libs? or do I need to use reflection?
18:47danlentzie: lein doc <enter> done.
18:47nullptrjustin_smith: yeah, there's an ag frontend in melpa as well
18:47justin_smithcoopernurse: there is the javadoc function for that
18:47justin_smith,(javadoc String)
18:47coopernursejustin_smith: ah, thanks
18:48clojurebot#error{:cause "Unable to resolve symbol: javadoc in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: javadoc in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6535]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: javadoc in this context", :a...
18:48lodinI see a lot of examples that mix Clojure and ClojureScript in the same project when doing ring+frontend. Is this something that should be avoided for larger projects (i.e. not examples)?
18:49justin_smithcoopernurse: warning, clojure.java.javadoc opens a browser window
18:49danlentzits not actually that difficult to just write up api documentation in Markdown as part of the README.md which is what I tend to do for anything I care about sufficiently.
18:49justin_smithlodin: if the frontend and backend form one site, it makes sense to put them in one project
18:49danlentzof my own code, i mean of course
18:53danlentzcodox is useful because it generates static html api doc. clock is useful because it is nicely formatted but starts up a local server.
18:53danlentzbut in a pinch:
18:53danlentz(defn ns-docs
18:54danlentz "Prints docs for all public symbols in given namespace
18:54danlentz http://blog.twonegatives.com/post/42435179639/ns-docs
18:54danlentz https://gist.github.com/timvisher/4728530&quot;
18:54danlentz [ns-symbol]
18:54danlentz (dorun
18:54danlentz (map (comp #'clojure.repl/print-doc meta)
18:54danlentz (->> ns-symbol
18:54danlentz ns-publics
18:54danlentz sort
18:54danlentz vals))))
18:54justin_smithdanlentz: don't do that please
18:54danlentzsorry i thought it would be on one line
18:55jonhlol
18:56danlentzbut it is a useful snippet, at any rate.
18:57danlentzis #clojure hooked into lisppaste the same way #lisp is?
18:58justin_smithno, but refheap is popular
18:58justin_smith~paste
18:58clojurebotpaste is https://refheap.com/
18:59coopernurseclojure.repl/dir is great. can that be used to browse regular Java packages that are imported into the project? e.g I'm playing with this lib: https://github.com/spotify/docker-client - I have it in my project.clj, but I'm resorting to using javap to see what it offers
19:00coopernurseit looks like cloc skips pure Java libs, so I don't see it in that UI
19:03nullptrcoopernurse: http://jd.benow.ca/ ?
19:29{blake}Hmmm. A counter. So easy in a mutable language...
19:30gfrederickswhatcha countin?
19:32{blake}records that I'm processing
19:32{blake}In a for. It's a batch process.
19:33gfrederickswhat're you using the count for?
19:33gfrederickslogging?
19:35{blake}progress indicator
19:35{blake}"n of m records processed"
19:35gfredericks(doseq [[rec i] (map vector recs (range))] ...)
19:35{blake}Only it's always "1 of 160 records processed" :(
19:36{blake}gfredericks: Ooh. Lemme see...
19:36hiredman~for
19:36clojurebotfor is ()
19:37hiredmanclojurebot: jerk
19:37clojurebotyou cut me deep, man.
19:37{blake}~jerk
19:37clojurebotyou cut me deep, man.
19:37{blake}lol
19:38{blake}(inc gfredericks)
19:38lazybot⇒ 123
19:38{blake}Groovy. And a good reminder to go over the clojure cheatsheet again.
20:35doritostainson OSX Emacs 24 cider, when I do C-c C-p the *cider-results* shows up empty. Is there some kind of setting I might be missing?
20:36michaniskin|BNC,(let [{x :foo} '(:foo 100 :bar 200)] x)
20:36clojurebot100
20:37justin_smithhaha, wow
20:37michaniskin|BNC,(let [{x :foo} '[:foo 100 :bar 200]] x)
20:37clojurebotnil
20:37justin_smithI did not expect that would work
20:37justin_smithmichaniskin|BNC: I bet that's because [] is associative
20:37justin_smith,(let [{x :foo} #{:foo}] x)
20:37clojurebot:foo
20:37michaniskin|BNCit's because let expands to an expression there that checks (seq? map_1234) ...
20:38justin_smithmichaniskin|BNC: let, or destructure?
20:38michaniskin|BNCit's doing (clojure.lang.PersistentHashMap/create (seq map_1234))
20:38michaniskin|BNCin the macroexpansion of clojure.core/let
20:38justin_smithoh, interesting
20:39michaniskin|BNC,(macroexpand '(let [{foo :asdf} (doit 100)]))
20:39clojurebot(let* [map__102 (doit 100) map__102 (if (clojure.core/seq? map__102) (clojure.lang.PersistentHashMap/create (clojure.core/seq map__102)) map__102) foo ...])
20:39justin_smithmichaniskin|BNC: yeah, it uses destructure to generate the bindings
20:39michaniskin|BNCi'm curious why it does that
20:41michaniskin|BNCi ran into it in a macro i wrote for cljs
20:41michaniskin|BNChttps://github.com/tailrecursion/hoplon/blob/master/src/tailrecursion/hoplon.clj#L23
20:41justin_smithmichaniskin|BNC: I am looking at where it does that in destructure, but it's a really hard function to read
20:42michaniskin|BNCi'm thinking to just postwalk-replace in the expanded form, replacing clojure.lang.PersistentHashMap/create with '(partial apply hash-map)
20:42michaniskin|BNCit should work the same and be compatible with both clj and cljs
20:42michaniskin|BNCi think?
20:43justin_smithwhy not change destructure so that it uses (partial apply hash-map) ?
20:43Bronsaseqs are treated automagically as hash-maps in destructure to allow for destructuring var-args as maps
20:43justin_smithaha!
20:43Bronsait's an implementation detail afaik
20:43justin_smith(inc Bronsa)
20:43lazybot⇒ 96
20:43michaniskin|BNCwow i see
20:44justin_smithyeah, it makes sense, how else would & {:keys [...]} work
20:44michaniskin|BNCok that makes sense, i remember reading about this, the apply hash-map trick from CL or whatever
20:44Bronsasince a vararg is an arrayseq, & {:keys [foo]} can only work that way
20:44justin_smithyeah
20:45michaniskin|BNCok cool so i can postwalk-replace there safely in my macro
20:48michaniskin|BNC,(let [[x y z & {:keys [foo bar]}] '(1 2 3 :foo 100 :bar 200)] {:x x :y y :z z :foo foo :bar bar})
20:48clojurebot{:x 1, :y 2, :z 3, :foo 100, :bar 200}
20:48michaniskin|BNChaha neato
20:50doritostainsnever mind got the emacs problem fixed
20:50justin_smithdoritostains: what was the issue?
21:45julianlevistonDoes anyone know of anything like David McNeil’s step.async for debugging core.async but in clojurescript?
22:13sridhttp://clojure.org/books is empty?
22:18justin_smith~books
22:18clojurebotbooks is http://clojurebook.com/ http://joyofclojure.com/
22:18justin_smithsrid: it's not empty when I go there
22:19justin_smithsrid: it shows 5 books, all good ones
22:28julianlevistonIt’s blank for me in safari, but not in chrome
22:28justin_smithad block?
22:28julianlevistonoh yeah! haha :)
22:29justin_smithI think the books on the page might show up as ads, kind of makes sense
22:32julianlevistonjustin_smith: yeah, I think adblock stops any image that has a src on a different domain than your site is on or something…
22:32justin_smithjulianleviston: it could also have to do with the fact that they are amazon affiliate links
22:33julianlevistonjustin_smith: I was only mentioning that because I noticed this site’s images don’t load for me either on safari with adblock: http://www.australianflutefestival.com
22:33julianlevistonand they’re not ads.
22:34julianlevistonbut yes :)
22:34julianleviston(inc justin_smith)
22:34lazybot⇒ 217
22:34julianlevistonjustin_smith: thanks for that, because it helped me work out why those images weren’t displaying
22:35justin_smithhah, nice
22:39justin_smithone liner to find all defined unit tests: (->> (all-ns) (mapcat (comp vals ns-interns)) (filter (comp :test meta)))
23:03celwellHi, how could I make doseq execute the body expression before the :while is checked?
23:04celwellWould I have to put my expression in the :let? That would seem complected.
23:04celwellHere's my example:
23:04celwell(doseq [z '(1 2)
23:04celwell :let [o (take-order-from-zone z)]
23:04celwell :while (nil? o)]
23:04celwell (println o))
23:04justin_smiththere's always (doseq [o (map take-order-from-zone '(1 2))] ...)
23:05celwellI want to loop through until we are done ignoring nils and then do the next value and then stop.
23:07celwelljustin_smith: I don't think that will work because my take-order-from-zone function has side-effects. It's modifying an atom with swap!.
23:08justin_smithoh, OK
23:08celwellI think the map would mess up the priority map in my atom
23:08celwellthe (map) i.e.
23:08justin_smithlaziness and side effects aren't a great match most of the time, yeah
23:09celwellsomething liek this maybe:
23:09celwell(doseq [z '(1 2)
23:09celwell :let [o (take-order-from-zone z)
23:09celwell blah (println o)]
23:09celwell :while (nil? o)]
23:09celwell )
23:09justin_smith_ is the canonical name for blah, btw
23:10celwellthx
23:10justin_smiththere's also (doto (take-order-from-zone z) println)
23:10justin_smithwhich prints, then returns the thing it printed
23:11ToxicFrogWhy on earth does re-groups return [match g0 g1 g2...] if there are capture groups, but match (not [match]) if there aren't?
23:11justin_smithToxicFrog: that seems like a bad choice
23:11ToxicFrogIt means (drop 1 (re-groups ...)) gets you all of the capture groups without the whole-match string, unless there are no capture groups
23:11ToxicFrogIn which case instead of getting [], you get a seq of the individual characters of the whole match with the first character missing
23:11ToxicFrogThat was a fun bug to track down
23:11justin_smithhaha
23:13celwelljustin_smith: hmm... maybe I should put a doto in my :while predicate. like:
23:13celwell(doseq [z '(2 1)
23:13celwell :let [o (take-order-from-zone z)]
23:13celwell :while (nil? (doto o println))])
23:13celwellthat might eb the prettiest option but it's still not that good i guess
23:13justin_smithyeah, that totally works
23:14ToxicFrogI realize it's probably too late to change it now, but why?
23:17justin_smith~why
23:17clojurebotwhy is the ram gone is <reply>I blame UTF-16. http://www.tumblr.com/tagged/but-why-is-the-ram-gone
23:18justin_smithclojurebot: that's a mess of a factoid
23:18clojurebotExcuse me?
23:37julianlevistonclojurebot: that’s a mess of a monoid
23:37clojurebotHuh?
23:57arav93I was testing typed clojure annotations. I keep getting the following error
23:57arav93lein test test.core-test Initializing core.typed ... Building core.typed base environments ... Finished building base environments "Elapsed time: 5052.674249 msecs" core.typed initialized. Start collecting test.subset Finished collecting test.subset Collected 1 namespaces in 213.006213 msecs Not checking clojure.core.typed (tagged :collect-only in ns metadata) Not checking test.core (tagged :collect-only in ns metadata) Not checking c
23:57arav93in ns metadata) Start checking test.subset Checked test.subset in 596.988311 msecs WARNING: Type Checker: Definition missing: clojure.set/subset? Hint: Use :no-check metadata with ann if this is an unchecked var Checked 4 namespaces (approx. 2429 lines) in 836.71237 msecs Type Error (test/subset.clj:6:2) Unannotated var clojure.set/subset? Hint: Add the annotation for clojure.set/subset? via check-ns or cf in: set/subset?
23:58arav93^ the second part