#clojure log - Mar 20 2015

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:49 Daniel_: anybody out there?

0:58 how do i get involved with clojure open source?

1:10 justin_smith: Daniel_: do you want to contribute to clojure the language, specifically, or just the clojure community including libraries and tools and such?

1:10 if the latter, leiningen has tickets on github that are tagged as newbie friendly

1:18 lvh: Is there a smarter `every?`for tests that tells me which items didn't match?

1:19 Or do I write (= (filter pred coll) '())

1:20 justin_smith: lvh: 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

1:20 ,(group-by even? (range 10))

1:20 clojurebot: {true [0 2 4 6 8], false [1 3 5 7 9]}

1:21 lvh: justin_smith: and then (nil? (m false))?

1:21 justin_smith: lvh: or empty?

1:21 but if all you want to check is that none were false, group-by may be overdoing it

1:22 but if you also wanted to check other mappings of in to out, group-by can be quite handy

1:22 lvh: whoa, nil is empty? that sounds like more nil punning than I was expecting from clj

1:22 justin_smith: ,(cons :because ())

1:22 clojurebot: (:because)

1:22 justin_smith: err

1:22 ,(cons :because nil)

1:22 clojurebot: (:because)

1:22 justin_smith: that's why

1:23 lvh: for some reason that surprises me less

1:23 justin_smith: well if cons x nil makes a collection, then it makes sense to say nil is empty

1:23 lvh: right, sure

1:24 so, now I'm still confused as to what to write

1:24 * justin_smith 's work here is done.

1:24 lvh: I have a defspec with (every pred coll) in it, and I'm getting false back

1:25 justin_smith: well, that's why group-by can be more informative

1:25 lvh: I wanted "these elements (not (pred elem))" or equivalent

1:25 justin_smith: you can look at the coll of things that were falsey

1:26 or you could do an equality ##(= {false [1 3] true [0 2]} (group-by even? (range 4)))

1:26 lazybot: ⇒ true

1:26 justin_smith: and then the error output will be more informative, right?

1:27 lvh: justin_smith: ok, yeah; I'll do that. Thanks :)

1:27 justin_smith: Is there a way to see values in stack frames when I look at stack traces?

1:28 I'm using cider; maybe I should use another editor for debugging

1:28 justin_smith: lvh: via debug connection, yeah - cursive has good tooling for that

1:28 also, there is a browser based tool, schmetterling, that allows looking at locals

1:28 ane: cider is awesome, it is getting a debugger, but cursive is the only one i think

1:28 justin_smith: it doesn't do stepping though, just looking at locals and evaluating in frame

1:29 Daniel_: 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?

1:29 justin_smith: the cool thing about schmetterling is you don't add it to your project - it connects via a debug connection (like a profiler would)

1:29 Daniel_: did you see my question to you above?

1:30 Daniel_: justin_smith: damn, no i didn't. sorry about that

1:31 justin_smith: np - do you want to contribute to clojure itself, or one of the clojure libraries / tools?

1:31 leinengen has a tag for beginner friendly tickets on github

1:31 Daniel_: justin_smith: i'm looking for something related to compilers?

1:32 justin_smith: as in the clojure compiler, or tools to build compilers using clojure?

1:32 Daniel_: the latter

1:32 justin_smith: Daniel_: you could check out instaparse for starters maybe

1:32 see if there are any contributions you could make

1:33 Daniel_: justin_smith: thanks i'll check that out right now!

1:34 justin_smith: just wondering, how did you get started with clojure?

1:34 justin_smith: Daniel_: I got a job where it was being used, they sought me out because I had experience with other functional languages (scheme and ocaml)

1:35 Daniel_: did you look at any books in particular?

1:36 justin_smith: yeah, 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

1:36 but Programming Clojure is an excellent introduction

1:42 irctc: Hello?

1:43 justin_smith: ola

1:45 irctc: Does anyone have experience compiling clojurescript from clojure?

1:46 Daniel_: justin_smith: thanks man. are you on the mailing list?

1:48 justin_smith: I check it sometimes

1:49 irctc: yeah, I have used the "

1:49 lein cljsbuild" plugin

1:49 but not extensively

1:51 irctc: Hmm okay

1:52 Have you ever encountered this error: SC_MISSING_PROVIDE_ERROR. required "cljs.core" namespace never provided ?

1:52 I'm totally stumped

2:05 justin_smith: no, that's one I have never seen

2:05 sorry

2:18 mmitchell: anyone know if it's possible to configure leiningen to use a different maven directory?

2:22 irctc: Ah that's okay, thanks

5:23 michaelr`: morning

5:23 kind of..

5:24 daniel`: morning

6:03 zot: anybody know if there's a way to stack feature-expression and metadata declaration? specifically, this: (deftype Foo [#+cljs :mutable #+clj :volatile-mutable m])

6:04 oops

6:04 s/:/^:/g

6:04 i can duplicate the 'm' declaration, or just declare both w/o the feature-expr, but wondered if there's a better way

6:05 TEttinger: are feature expressions just metadata? I actually have no idea

6:07 hyPiRion: TEttinger: no

6:07 TEttinger: yay hyPiRion, someone who can answer questions is here!

6:12 hyPiRion: Or well, afaik there has been no decisions yet, but the proposal for reader conditionals is here: http://dev.clojure.org/jira/browse/CLJ-1424

6:14 arav93: Is there anyone familiar with typed clojure?

6:18 zot: hyPiRion: interesting; sounds like i'm sticking w/ the hacks for now

6:24 TEttinger: arav93, you can ask a question and someone may see it later and be able to answer

6:24 ~anyone

6:24 clojurebot: Just 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 ..."

6:29 zot: lol. i don't think i ever start a question without something like "does anybody know …" :)

6:44 kungi: \o/

6:48 clojer: Has anyone tried running Clojurescript on JXCore, the threaded NodeJS alternative? If so, what implications for the number of threads it can service?

7:18 borkdude: what's a good way to add the appropriate content type to a binary file that is served from liberator?

7:18 ordnungswidrig: borkduke: the :available-media-types declaration

7:18 borkdude: for a wide range of possible files: .doc, .pdf, etc without doing anything manual

7:19 it can be any type of upload

7:21 ordnungswidrig: borkdude: 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

7:21 borkdude: I'll probably need this: https://github.com/ring-clojure/ring/blob/1.3.1/ring-core/src/ring/util/mime_type.clj

7:21 ordnungswidrig: :-)

7:21 borkdude: thanks ordnungswidrig :)

7:21 ordnungswidrig: use that in :available-media-types

7:22 beware that you need to return a collection of media types, so you might want to wrap the result in []

7:34 borkdude: ordnungswidrig 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?

7:35 ordnungswidrig I might as well set the Content-Type in :handle-ok

7:38 ordnungswidrig: you 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.

7:41 borkdude: ordnungswidrig so I can return a context map in available-media-types?

7:43 ordnungswidrig I'm not sure where the actual media types go then. like this? {:available-media-types [....], ::file ...}

7:43 ?

7:43 or probably :representation

7:45 ordnungswidrig: Ah, 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?

8:05 jonathanj: hmm, i have :java-source-paths ["resources/css2fopnew1_6_2.jar"] in my project.clj

8:05 but i get this trying to use it: #<CompilerException java.lang.ClassNotFoundException: be.re.css.CSSToFOPNew, compiling:(documint/css2xslfo.clj:1:1)>

8:06 a listing of the jar contents reveals that it is there: 8530 08-23-10 19:53 be/re/css/CSSToFOPNew.class

8:20 TEttinger: ,(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]))

8:20 clojurebot: #'sandbox/stateful-random

8:20 TEttinger: ,(stateful-random 7)

8:20 clojurebot: #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...

8:21 TEttinger: ,(stateful-random [7 8])

8:21 clojurebot: #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...

8:21 TEttinger: sigh

8:22 ,(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]))

8:22 clojurebot: #'sandbox/stateful-random

8:22 TEttinger: ,(stateful-random [7 8])

8:22 clojurebot: 7565168461108830500[-7046029254386353124 7565168461108830500]

8:22 TEttinger: sweet

8:23 (take 5 (iterate stateful-random [23 0]))

8:23 ,(take 5 (iterate stateful-random [23 0]))

8:23 clojurebot: (4763265388078209808[23 0] 7406151029654480375[-7046029254386353108 4763265388078209808] 5903060928641107144[4354685564936845377 7406151029654480375] 4132843093337229763[-2691343689449507754 5903060928641107144] [8709371129873690731 4132843093337229763])

8:23 ordnungswidrig: TEttinger: I hope you're not implementing anything cryptographic ;-)

8:23 TEttinger: nope

8:23 it's an RNG with 64 bits of state

8:24 it keeps its state around with it in a pair

8:24 so it could be used in pure functions

8:29 ordnungswidrig: TEttinger: can you split it?

8:29 TEttinger: heh

8:29 it's derived from the source to java 8'

8:29 it's derived from the source to java 8's splittable RNG

8:29 http://xorshift.di.unimi.it/splitmix64.c

8:30 ordnungswidrig: I see. but can you split it into two "stream", e.g. to be used in different threads.

8:32 TEttinger: I'm reading the docs on splitting the random

8:32 it uh

8:32 doesn't seem to be much different

8:33 it looks like splitting a SplittableRandom just changes the state in some way of a new SRNG

8:43 gfredericks: TEttinger: what's this java 8 thing?

8:44 TEttinger: http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html

8:44 ^ gfredericks

8:47 here's a big run of it https://www.refheap.com/98665

8:48 I'm not sure why they're all positive

8:49 is there an unchecked-xor, gfredericks?

8:51 gfredericks: TEttinger: I don't think that would make sense

8:51 there's nothing to check for with xor

8:51 TEttinger: sign bit?

8:51 clojurebot: excusez-moi

8:51 TEttinger: nearly 6 AM here

8:51 gfredericks: TEttinger: there's no such thing as overflow

8:51 TEttinger: time for beddie bye

8:52 right

8:52 ok

8:52 gfredericks: TEttinger: "all positive" might mean you're representing 32 bit numbers with a long?

9:36 timvisher: how crazy would i be to suggest that the repl should have the current ns on one line and `> ` on the line afterward?

9:36 that's how i do my `PS1` and it really helps when you're deep in a directory structure

9:37 Empperi: (clojure.main/repl :prompt (fn [] "this shall be your prompt >"))

9:38 replace hardcoded string with what you want, eg. current namespace

9:39 and to be fair, at least on my side of things "lein repl" shows the currently active namespace

10:08 Jeffsen: Trying 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:09 When 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:11 I clearly see that clojure.lang.Compiler is in my .jar file. In this jar I am running a java class.

10:11 And inside one of the methods of this class I do a Class.forName("clojure.lang.Compiler"); which fails.

10:27 herrwolfe: is it just me or is cider kind of difficult to get up and running reliably?

10:27 justin_smith: not just you

10:27 ~cider

10:27 clojurebot: cider is rage-inducing

10:28 herrwolfe: yeah - I've followed the directions exactly, and it never seems to work

10:28 thanks for validating my experience!

10:52 stuartsierra: Don't track CIDER master or dev snapshots, pick a stable version and stick with it.

10:54 justin_smith: it's too bad the official cider page doesn't suggest that

10:56 stuartsierra: ~cider

10:56 clojurebot: cider is rage-inducing

10:57 mpenet: well it does suggest to use melpa-stable an a non snapshot release in profiles.clj

10:57 justin_smith: it doesn't help that emacs doesn't make it easy to stick to stable packages.

10:57 mpenet: oh, I didn't see that just now

10:58 "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:58 nullptr: justin_smith: it's pretty easy https://github.com/derekslager/dotfiles/blob/master/emacs.d/derek/package.el#L10

10:58 justin_smith: to quote the Princess Bride "you keep using that word"

10:59 mpenet: I have to say I never had an issue running from vanilla MELPA tho

10:59 justin_smith: good to know

11:00 nullptr: the mix of stable/unstable has worked better than expected -- some of the stuff on melpa-stable is really old

11:08 mpenet: Did anyone try dunaj? seems like an interesting experiment

11:08 Jeffsen: How 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:10 tomjack: wow, multireducers

11:13 hmm, I wonder what the "don't require excluding Clojure from deps" alternatives looked like, and why they were rejected

11:14 Presumably existing Clojure libraries wouldn't behave as desired if they used Clojure instead of Dunaj?

11:15 indent metadata! hah

11:20 herrwolfe: mpenet: 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:21 I'm running vanilla emacs, installed from homebrew, with (doubtful that it matters) leiningen installed from brew

11:21 mpenet: herrwolfe: I never used stable, I wouldn't know where to start, but try pinging cider's maintainer, he's very friendly and helpful

11:21 herrwolfe: mpenet: gotcha - thanks!

11:49 tomjack: if 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:50 I 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:51 oh, I guess like transducers one would maybe want to support both, which is kind of troublesome :(

11:59 gfredericks: tomjack: you're just asking about the syntax for composing middleware?

11:59 not about implementing middleware?

11:59 maybe I'm confused

11:59 comp is less general isn't it?

11:59 er

12:00 tomjack: the question is whether you write (fn with-foo [foo] (fn [app] (fn [req] ...))) or (fn with-foo [app foo] (fn [req] ...))

12:01 gfredericks: what is app?

12:01 is this not about http servers?

12:01 tomjack: am I confused? it's the ring app

12:02 another (fn [req] ...) which returns a response

12:02 gfredericks: traditional ring middlewares are (fn [handler] (fn [req] ...)) right?

12:02 tomjack: oh, ok, s/app/handler/

12:02 gfredericks: okay gotcha

12:02 and foo is just a way to customize the middleware?

12:02 tomjack: yeah, like say the root domain name of your app or something

12:02 gfredericks: gotcha

12:03 it's funny you have 3 fns and I often think of the alternative of 1 fn

12:03 usually when monkeypatching with alter-var-root though

12:03 e.g. (alter-var-root #'some-func (fn [orig] (fn [& args] ...)))

12:03 tomjack: (my case is not actually about http servers, but asking the question about a from-scratch ring works too)

12:03 gfredericks: compared to robert.hooke (add-hook #'some-func (fn [orig & args] ...))

12:04 tomjack: eh, I just want to do (-> fallback with-foo with-bar) or ((comp with-bar with-foo) fallback) :)

12:05 you could try to write (fn with-foo ([foo] ...) ([handler foo] ...)) but this doesn't always work out so nicely

12:05 so I suspect it's best to just pick one way

12:06 (I sometimes wonder if the reason we don't have a (partition 2 1) transducer is just hil-arity)

12:17 timvisher: does anyone know how midje can creep into your execution path?

12:18 when i load files, it suddenly decides to start running tests on each request

12:18 the test ns is not required anywhere that i can tell

12:18 is it auto-test by default or something?

12:19 i.e. i `C-c C-l` in emacs over cider-nrepl

12:30 maybe 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:31 but loading the file produces the behavior consistently

12:34 i have `[midje "1.6.2"]` in my `:dev :dependencies`, `[lein-midje "3.1.3"]` in my `:dev :plugins`,

12:34 i'm starting the repl via `:nrepl {:start? true}` in `:ring` project.clj config

12:36 if 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:38 Empperi: i didn't know about that. sadly, doesn't look like cider supports configuring that at the moment.

12:42 evaling the ns form didn't do it...

13:30 jcromartie: I feel like it's a bit of a code smell when type names are all over our code

13:30 defrecords or deftypes

13:31 is there a good discussion about API design and protocols/records?

13:32 gfredericks: jcromartie: well for records you don't need to use the type name directly for constructing

13:32 since the constructor fns get defined; but maybe that's not what you meant

13:33 jcromartie: even those

13:33 (map->Whatever ...)

13:33 gfredericks: gotcha

13:33 jcromartie: I just mean, having a lot of code related to dealing with certain specific types seems to defeat the point of polymorphism

13:33 gfredericks: it is still indirection

13:34 map->Whatever doing (Whatever. ...) is technically in impl detail and could change

13:35 but regardless

13:35 jcromartie: 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:35 jcromartie: we've got a fairly detailed data model

13:35 and it's lots and lots of records, nested with in each other

13:36 makes constructing and manipulating a little tricky

13:36 Glenjamin: is there a reason they're not just maps?

13:36 jcromartie: say, you want to represent a polygon

13:36 which is a bunch of records

13:36 (defrecord Polygon [rings]) (defrecord Ring [points]) (defrecord Point [lon lat])

13:36 it gets cumbersome

13:37 but I don't have a better example :)

13:37 I mean I don't have a good alternative to offer to that design

13:44 lvh: Is there a name for constraininga n integer to an interval?

13:44 I know how to write it with #(min (max low %) high), but idk if there's a thing for that somewhere already

13:45 gfredericks: don't think so

13:45 I saw that named "clamp" in a google lib somewhere

13:45 closure probably

13:45 lvh: aaah that's the word I was looking for :)

13:46 gfredericks: oh I thought you were looking for an existing function

13:46 glad I accidentally answered the question anyways

13:46 lvh: gfredericks: I was

13:46 gfredericks: 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:46 gfredericks: okay I retract my misconceived gladness

13:47 (-> % (max low) (min high))

13:56 charlespwd: Can someone explain why (def log (.-log js/console)) (log "hi") throws an Illegal invocation where (def cos (.-cos js/Math)) doesn't?

13:59 ,((.-log js/console) "hi")

13:59 clojurebot: #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:01 crash_ep: because .log is a method, not a property

14:01 charlespwd: .-log is

14:02 no?

14:02 clojurebot: no is tufflax: there was a question somewhere in there, the answer

14:02 gfredericks: there's nothing in clojure for java's >>>? I have to write it myself?

14:04 tbaldrid_: ,(doc unsigned-bit-shift-right)

14:04 clojurebot: "([x n]); Bitwise shift right, without sign-extension."

14:04 tbaldrid_: gfredericks: ^^

14:07 gfredericks: tbaldridge: oh geez apparently I didn't know what >>> did

14:07 I thought it was rotate

14:07 (inc tbaldridge)

14:07 lazybot: ⇒ 20

14:07 gfredericks: please tell me it's at least rotate in some other language

14:07 alejandrozf: how much Java is a must to learn Clojure if Ihave some Lisp experience?

14:08 sorry,hi!

14:08 gfredericks: alejandrozf: depends on what you're doing

14:08 probably the thing you get the most mileage out of is understanding the java/jvm object model and reading javadocs

14:08 alejandrozf: gfredericks: i want to code mainly in clojure, but using Java libs

14:09 agarman: alejandrozf: you really don't need to learn Java, but you will end up learning the JVM

14:09 gfredericks: yeah the java language proper is almost irrelevant

14:09 alejandrozf: JVM is hard to learn?

14:10 gfredericks: probably not for your purposes

14:10 alejandrozf: agarman:, gfredericks : it's a relief...

14:10 agarman: depends upon what you're trying to do

14:10 gfredericks: ,(type "foo")

14:10 clojurebot: java.lang.String

14:10 gfredericks: alejandrozf: ^ inspecting objects like that will give you familiarity

14:11 if it's a java class you can read the javadocs for it, via google

14:11 $google java 8 string javadoc

14:11 lazybot: [Overview (Java Platform SE 8 ) - Oracle Documentation] http://docs.oracle.com/javase/8/docs/api/

14:11 gfredericks: bad example :(

14:11 it's probably the third result or something

14:11 agarman: ,(javadoc java.lang.String)

14:11 clojurebot: #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:12 alejandrozf: say ,for instance I want to create a game with a lot of graphic stuff...

14:12 agarman: that function will bring up the javadoc in your browser

14:13 alejandrozf: agarman: thanks, it's a good point to start...

14:13 agarman: alejandrozf: 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&utm_medium=feed&utm_campaign=Feed%3A+Blog-YetAnalytics+%28Blog+-+Yet+Analytics%29

14:13 wow, what a long URL...my bed :-/

14:13 bad

14:13 alejandrozf: agarman: :)

14:14 agarman: https://www.youtube.com/watch?v=0GzzFeS5cMc

14:15 here's github for that https://github.com/oakes/play-clj

14:15 alejandrozf: I want to start programming Clojure, comming from CL, Racket, Python,C/C++,...

14:17 agarman: here's another fun resource http://lispgames.org/index.php/Clojurescript

14:18 alejandrozf: with wish me luck!, ands thanks agarman, gfredericks :), see you soon ;)

14:26 gfredericks: I feel like the fact that unchecked-{multiply,add} falls back to checked operations is a bug, but it's so clearly intentional

14:26 it makes me grumpsy

14:26 I guess I can just make a helper macro

14:28 Bronsa: gfredericks: uh? how does it fall back to checked ops?

14:32 Glenjamin: ,(unchecked-add Integer/MAX_VALUE 10000)

14:33 clojurebot: 2147493647

14:33 Glenjamin: i have no idea if that's right or not :s

14:33 ,(+ Integer/MAX_VALUE 10000)

14:33 clojurebot: 2147493647

14:34 amalloy: Glenjamin: unchecked-add is for longs, so that's not much of a surprise

14:35 Glenjamin: ah, i thought that might be it, but also realised i didn't know what i was doing - so unlikely to be helpful

14:35 ,(unchecked-add Long/MAX_VALUE 10000)

14:35 clojurebot: -9223372036854765809

14:35 Glenjamin: that looks right though

15:19 gfredericks: &((fn [x] (unchecked-multiply x x)) 999999999999999)

15:19 lazybot: java.lang.ArithmeticException: integer overflow

15:19 gfredericks: Bronsa: ^

15:19 vs

15:19 &((fn [^long x] (unchecked-multiply x x)) 999999999999999)

15:19 lazybot: ⇒ 5074944270305263617

15:19 Bronsa: uh

15:20 so the unchecked_add(Object,Object) arity is wrong?

15:20 gfredericks: it's highly misleading

15:20 at least

15:21 the impl is just add(x, y)

15:21 which makes it look intentional

15:21 Bronsa: ,((fn [^long x y] (unchecked-multiply x y)) 999999999999999)

15:21 clojurebot: #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:21 Bronsa: ,((fn [^long x y] (unchecked-multiply x y)) 999999999999999 999999999999999)

15:21 clojurebot: #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:21 hiredman: gfredericks: someone must have pointed you at primitive-math by now, right?

15:22 Bronsa: it looks like the only unchecked_add arity that overflows is actually the (long,long) one

15:22 weird

15:22 gfredericks: hiredman: I'm aware of it

15:22 hiredman: it's hard to imagine any use for the current behavior

15:22 hiredman: just making sure

15:22 sure

15:25 gfredericks: Bronsa: do you think this could be reported as a bug? i.e., do you think there are any reasonable worries about "breaking" changes?

15:27 Bronsa: gfredericks: i would report this as a bug, yeah

15:28 gfredericks: Hypirion: ping

15:29 hiredman: I 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:31 https://github.com/hiredman/clojure/commit/1732cdbf2d752d35573e2e74ffe642bc7b73eae1

15:37 numberten: does test.check.generators have something for floats?

15:37 gfredericks: numberten: I thought there was something

15:38 numberten: i don't see anything in the docs, but it feels like something big to be missing

15:38 clojurebot: Cool story bro.

15:38 gfredericks: numberten: there's also this https://github.com/gfredericks/test.chuck/blob/master/src/com/gfredericks/test/chuck/generators.clj#L207-216

15:39 numberten: or (gen/fmap double gen/ratio) maybe? I forget if gen/ratio exists

15:40 numberten: thanks

15:42 gfredericks: numberten: I think the goal of the test.chuck version is to generate all possible doubles

15:44 I'm trying to figure out how to build two uberjars with different lein profiles

15:44 currently I get them both to build but the first one gets deleted

15:44 does anybody know how to do this?

15:57 looks 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:01 dmitrig01: hey - 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:03 tbaldrid_: dmitrig01: I always suggest that you don't do that. Instead, measure either the output of A or the side-effect of B.

16:03 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:04 dmitrig01: mm, that’s fair

16:04 tbaldridge: Most 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:05 A 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:12 dmitrig01: tbaldridge: 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:14 Draggor: For doing TDD in clojure, is clojure.test enough or is there a preferred testing framework people tend to use?

16:14 tbaldridge: dmitrig01: 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:14 Draggor: simpler is better, stick with clojure.test

16:24 borkdude: I like clojure.test as well

16:24 justin_smith: (inc clojure.test)

16:24 lazybot: ⇒ 4

16:25 borkdude: also clojure.java.jdbc is cool. what is your favorite clojure.* library or namespace? ;)

16:29 arrdem: including contrib, test.check hands down

16:47 arohner: distinct-by doesn't exist anywhere, right?

16:47 i.e. (distinct-by f coll)

16:48 Bronsa: arohner: what would that do? deduplicate equal (f x) ?

16:48 arohner: Bronsa: yes

16:49 Bronsa: arohner: but say you have (f a) == (f b) but a!=b, would (distinct-by f [a b]) return [a] or [b]?

16:49 i guess you wouldn't care?

16:50 arohner: Bronsa: I don't have that situation in my code, but I'd return [a]

16:59 justin_smith: (comp (partial map first) vals group-by)

16:59 would be one way to do it at least

16:59 the reduce version would be faster, dunno how much faster

17:01 anti-freeze: Hey 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:06 arohner: anti-freeze: can't you GET the page, store the 'cookie', and then POST?

17:08 anti-freeze: arohner: 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:08 arohner: it's just part of the ring request: {:request-method :get :uri "/foo" :headers {"x-csrf-ring" "abcdef"}}

17:09 (I don't know if that's the correct name of the header)

17:09 but your request's token needs to match what ring has in memory, which is the whole point of anti-csrf

17:09 which is why I suggested GETing the page first, because that's what the 'real' behavior expects

17:10 justin_smith: anti-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:11 arohner: true, if you dont care about CSRF behavior for your test, just make the handler w/o that middleware

17:11 anti-freeze: Isn't there a better way to test requests like this?

17:12 arohner: anti-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:12 justin_smith: either 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:13 anti-freeze: Alright, I'm a real clojure noob, coming from a professional rails background, can someone demonstrate an example. I'm really lost

17:14 arohner: anti-freeze: oh, you can also fake it by providing the token in the form params, and your cookie

17:14 anti-freeze: arohner: Form params didn't work last time

17:14 arohner: anti-freeze: which storage are you using for sessions? (cookies, DB, in-memory)?

17:14 anti-freeze: arohner: in-memory at the moment

17:15 arohner: I have something like this. response (app (request :post "/register" {:__anti-forgery-token *anti-forgery-token* :username "someone" :email "a@a.com"...

17:15 Doesn't work

17:16 arohner: right, because you're not faking the session CSRF token

17:16 anti-freeze: How would I do that?

17:16 arohner: ant-forgery works by requiring that the form params, and the ring session, share the same secret (the token)

17:16 one sec

17:17 anti-freeze: you'd need to munge the session storage, created by ring.middleware.session

17:17 anti-freeze: arohner: munge?

17:18 arohner: mess with it

17:18 make the token stored in the session match the one you're setting in the form params

17:18 if that doesn't make sense to you, I recommend going with the closer-to-real-world version, which is using cookies

17:18 the way a real user would

17:19 anti-freeze: arohner: Is that how you would test it?

17:19 arohner: yeah, use clj-http, and look at using cookies: https://github.com/dakrone/clj-http#cookie-stores

17:20 anti-freeze: arohner: 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:20 justin_smith: anti-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:21 arohner: anti-freeze: just GET the page, and then post, using the same cookie maanger

17:21 because you're using cookies, the session identity gets transferred 'for free'

17:22 oh, right you would need to extract the CSRF cookie

17:22 justin_smith: arohner: is it its own cookie, or is it just part of the session?

17:23 anti-freeze: Alright, I'll give it a go

17:23 I have no idea

17:23 arohner: hrm.

17:23 justin_smith: yeah, it is part of the session

17:24 which means if you're using in-memory, you can't extract, because the cookie just holds the session id

17:24 anti-freeze: how are you creating the session middleware?

17:24 and how are you enabling anti-csrf? ring-defaults?

17:24 justin_smith: arohner: right - I think you would have to invoke the anti-forgery wrapped handler, not call into ring

17:25 or, you could write a dummy handler for get which gives you your anti-forgery token so you can then provide it

17:25 eg. the way it would normally be embedded into a hidden input

17:25 but in this case you would likely just put it in a json

17:25 anti-freeze: I do a wrap-anti-forgery

17:26 arohner: and sessions? if you (wrap-session :store (in-memory...)), then you'd have access to the atom, and you can muck with it

17:26 another option is to disable anti-forgery in tests

17:27 anti-freeze: (wrap-defaults (assoc-in site-defaults [:session :store] (memory-store session/mem)))

17:27 session/mem is just an (atom {})

17:27 justin_smith: arohner: yeah, that was my first inclination - to just call the handler as a function instead of all this mocking stuff

17:28 arohner: anti-freeze: right, after GETting the page, that atom should have interesting things in it

17:28 anti-freeze: How would I set up a test enviromnent, sort of like in rails

17:28 Just disable csrf completely

17:29 arohner: well the handler is created by a function, right?

17:29 anti-freeze: the production middleware

17:31 I don't want to just be commenting and uncommenting the anti-forgery handler for every test, that's just plain stupid

17:31 justin_smith: anti-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:32 (defn maybe-antiforgery [handler] (if testing handler (wrap-anti-forgery handler)))

17:32 anti-freeze: justin_smith: Ah, this is why people don't write tests. Writing middleware just to run POST request mocks?

17:33 justin_smith: anti-freeze: no, I use the first option, making sure my handler is a top level definition that I can call directly

17:33 and ring uses the middleware wrapped version

17:33 if I need the middleware while testing, I can add that in the test

17:33 anti-freeze: Yea, but I need the middleware in development/production, just not in a test environment.

17:34 justin_smith: right, so in your test, you call the handler + relevant middleware to the test

17:34 in production, you call the handler, wrapped with the production middleware

17:34 and in development, you call it wrapped in the development middleware

17:34 etc.

17:34 perhaps I should be using the term "endpoint"

17:35 because 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:35 that's where the stuff I need to test is

17:36 anti-freeze: justin_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:37 justin_smith: anti-freeze: then you establish that it returns {:code 302 :body "/"}

17:37 anti-freeze: so a redirect is just a map?

17:37 justin_smith: anti-freeze: any ring response is just a map

17:37 just like the request

17:37 it's super easy to test ring endpoints for that reason

17:38 anti-freeze: Oh, sweet.

17:38 So I was going the long way round

17:38 justin_smith: well 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:39 anti-freeze: yeah, I should have been more explicit about why I was saying "just call the endpoint without the middleware"

17:39 I guess I assumed everybody knew handlers / endpoints just return maps in ring

17:39 anti-freeze: justin_smith: No worries, this is a little new to me. The whole bundle stuff together and hope it works mentality

17:40 justin_smith: anti-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:40 mocking looks very complicated in comparison

17:41 anti-freeze: justin_smith: Why is there no resources on this though? I mean, I googled extensively and got nothing.

17:41 justin_smith: frankly I have no idea

17:41 Risiko91: Hi 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:41 arohner: because clojure http is so well factored that there's nothing "in one place"

17:41 it's all scattered through ring, compojure, friend, etc

17:41 justin_smith: anti-freeze: it's a blog post I have no excuse for not having written yet, I guess

17:42 anti-freeze: justin_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:43 Bronsa: Risiko91: 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:43 justin_smith: anti-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:44 Risiko91: lasergoat: I've just typed (use ''a_b_c.d)... isn't enough?

17:44 anti-freeze: justin_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:45 justin_smith: anti-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:46 anti-freeze: justin_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:47 with clojure that is

17:47 Risiko91: Bronta: Can I use `use`?

17:47 anti-freeze: I suffer from a serious case of 'the grass is greener' syndrome

17:47 arohner: the 'default' stack is quite good, it 'just' requires you to understand how the pieces fight together

17:48 justin_smith: Risiko91: if the file is named a_b_c/d.clj use/require would expect a-b-c.d

17:48 anti-freeze: arohner: Writing the glue between them is still required though. Architecture and what not

17:48 arohner: Extra startup and setup time

17:48 arohner: anti-freeze: yes, but that's a good thing IMO

17:49 anti-freeze: arohner: I don't know. I'm having my doubts

17:49 arohner: it's longer to get 'hello world', but it's shorter to get to production

17:49 and more understandable, and less need to throw everything out and start over when a new framework comes to town

17:49 more understandable at the upper end. yes, it's harder on noobs

17:49 anti-freeze: Perhaps, I'm just frustrated because I've barely got past login/register and I can't seem to even test it

17:50 arohner: anti-freeze: understandable!

17:51 Risiko91: Ohh yes... a nasty neewbie error!! I never remeber it!! Thanks justin_smith

17:51 anti-freeze: arohner: 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:53 especially the non techy, spiky haired boss

17:53 :P

17:56 justin_smith, arohner: Thanks for your help guys, I really appreciate it.

17:57 freddd: hey 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:58 arohner: anti-freeze: no problem :-)

17:58 freddd: I don't think so. Just use the newest release core.async and you should be good to go

18:01 celwell: Hi, in a map, how do I get the key whose value returns true for some predicate fn?

18:04 freddd: arohner: ok, i think i'm actually misremembering. do you know off-hand if core.async ever had its own map/filter, etc.?

18:05 arohner: celwell: (filter (fn [[k v]] (f k) the-map)

18:05 freddd: yes, it did, but they were named like map< or something like that

18:05 they might still be there, but deprecated

18:05 celwell: I accidentally a )

18:08 freddd: arohner: ok, thanks.

18:08 numberten: is there a function that turns strings into regex?

18:09 freddd: arohner: 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:09 celwell: I only want the key. I could use this of course, but if there a more elegant way?

18:10 numberten: re-pattern :)

18:13 freddd: celwell: 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:13 celwell: thanks

18:14 arohner: celwell: (some (fn [k] (f k)) (keys the-map))

18:14 justin_smith: (filter p (keys m))

18:14 (some p (keys m))

18:14 celwell: but I have to apply the predicate fn to the vals of the map

18:14 justin_smith: arohner: (fn [k] (f k)) is a little silly :)

18:15 celwell: then vals m instead of keys m

18:15 celwell: but i need to get the key

18:15 justin_smith: ahh, if the val matches a pred, give you the key

18:15 celwell: yeah

18:15 justin_smith: (first (keep (fn [[k v]] (when (p v) k)) m))

18:16 celwell: i guess i figured there was a core fn for this use case but i guess not

18:16 justin_smith: ,(some (fn [[k v]] (when (even? v) k)) {:a 0 :b 1 :c 2 :d 3 :e 4})

18:16 clojurebot: :a

18:17 justin_smith: that's my final answer

18:17 celwell: thanks

18:17 justin_smith: though finding "the first" in a map is complicated, since they are not ordered, of course :)

18:18 mavbozo: celwell: it's possible there are many keys whose values satisfies the predicate right?

18:18 arohner: celwell: the core fns are designed to be composable and reusable your precise problem seems a little niche

18:18 freddd: justin_smith: bravo

18:19 anti-freeze: Also, any ideas as to why the REPL takes ages to run anything?

18:19 justin_smith: freddd: thanks

18:20 mavbozo: anti-freeze: REPL from? terminal? emacs?

18:20 oddcully: anti-freeze: ages?

18:21 mavbozo: sometimes I have to restart my emacs

18:21 anti-freeze: Terminal

18:21 justin_smith: anti-freeze: are you printing very long lines in emacs?

18:21 oh

18:21 anti-freeze: Straight up lein repl|test|ring server

18:21 justin_smith: maybe your heap usage is making your machine swap?

18:22 anti-freeze: justin_smith: I dont know, seems to run fine with other JVM repl's (e.g. scala).

18:23 justin_smith: anti-freeze: I'd connect a profiler, see what the hell it's trying to do

18:23 yourkit is free for open source projects, visualvm is free and comes with oracle jdk releases

18:23 anti-freeze: justin_smith: I'll check it out

18:24 justin_smith: Do you think it could be eastwood

18:24 ?

18:24 justin_smith: eastwood shouldn't be running by the time your app is running

18:24 it's a task plugin

18:24 freddd: justin_smith: thanks again for the answer to celwell. i always think of some as returning true or false, not truthy or falsey.

18:25 anti-freeze: justin_smith: So, it could be anything then?

18:25 justin_smith: freddd: ahh yeah, that's overloaded, some is being used to get the first truthy result there

18:25 anti-freeze: well, a profiler should show you what's up pretty quick

18:26 or you could run jstack on the process while it is slow to just see what all the threads are doing

18:26 it gives a stack trace for every thread in the vm

18:27 anti-freeze: justin_smith: Maybe its just because its loading all that compojure/ring/* stuff

18:29 justin_smith: anti-freeze: are you talking about how slow the startup is, or responsiveness once it is up and running?

18:29 anti-freeze: justin_smith: Start up. I should have clarified

18:29 justin_smith: anti-freeze: oh, that's a different question, yeah

18:29 anti-freeze: I apologise

18:30 justin_smith: anti-freeze: the main overheads for startup time are lein, nrepl, and the clojure runtime

18:30 anti-freeze: the leiningen guide to fast startup https://github.com/technomancy/leiningen/wiki/Faster

18:30 anti-freeze: justin_smith: Ah. Its just annoying because it takes ages to get the tests running

18:30 justin_smith: right

18:31 anti-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:31 but that wiki article has a bunch of good ways to speed things up

18:31 anti-freeze: justin_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:31 justin_smith: (clojure.test/run-tests)

18:32 arohner: also, (clojure.test/run-tests 'the.namespace)

18:32 anti-freeze: justin_smith: Nice. I can't thank you enough

18:32 justin_smith: and midge is weird (though it has some fans, I'll acknowledge).

18:32 arohner: and (the.namespace/a-single-test)

18:32 justin_smith: $karma midje

18:32 lazybot: midje has karma 1.

18:32 anti-freeze: justin_smith: Any other recommendations on a better testing framework?

18:33 justin_smith: expectations and clojure.test are the two I would consider

18:33 that plus remembering that in clojure you can make a lot of things into pure functions, and pure functions are really easy to test

18:33 arohner: I would recommend clojure.test over midje

18:33 anti-freeze: $karma speclj

18:33 lazybot: speclj has karma 0.

18:34 justin_smith: anti-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:34 anti-freeze: I guess I'll have to make up my mind on that one. Anyway, I'm off to bed. Thanks again

18:34 justin_smith: then 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:39 lvh: How does multimethod replacing work again? ISTR that you can't just recompile to replace dispatch-fns, but how about method impls?

18:40 justin_smith: lvh: method impls should just work with a reload, but you need to assign the defmulti itself to nil before it can be reassigned

18:40 or destroy it's var

18:40 def to nil is easier

18:40 lvh: aha, okay

18:40 I guess I was just screwing uip the recompile then, because I think I just saw both

18:40 thanks, justin_smith!

18:40 justin_smith: lvh: oh, I made an example of that for grimoire recently

18:41 lvh: 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:41 lvh: thank you!

18:44 coopernurse: hi folks - tools / workflow question. when you're using a new library, what's your preferred way to explore what functions are available?

18:44 I'm reading this: http://stackoverflow.com/questions/2747294/how-to-list-the-functions-of-a-namespace - which suggests (ns-publics) - any other tips?

18:44 justin_smith: coopernurse: clojure.repl/dir clojure.repl/doc clojure.repl/source

18:45 danlentz: i like to read the code

18:45 but “lein cloc” is pretty

18:45 justin_smith: and then of course just plain reading the code, yeah :)

18:45 coopernurse: I haven't tried "lein cloc" - that looks promising. thanks

18:45 nullptr: coopernurse: git clone + README.md + ag defn

18:46 danlentz: i really wish the clojuredoc process was more reasonable

18:47 justin_smith: nullptr: 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:47 danlentz: something that worked just like “codox” but generated the standard Clojure api documentation output

18:47 coopernurse: do any of those functions work with pure Java libs? or do I need to use reflection?

18:47 danlentz: ie: lein doc <enter> done.

18:47 nullptr: justin_smith: yeah, there's an ag frontend in melpa as well

18:47 justin_smith: coopernurse: there is the javadoc function for that

18:47 ,(javadoc String)

18:47 coopernurse: justin_smith: ah, thanks

18:48 clojurebot: #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:48 lodin: I 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:49 justin_smith: coopernurse: warning, clojure.java.javadoc opens a browser window

18:49 danlentz: its 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:49 justin_smith: lodin: if the frontend and backend form one site, it makes sense to put them in one project

18:49 danlentz: of my own code, i mean of course

18:53 codox is useful because it generates static html api doc. clock is useful because it is nicely formatted but starts up a local server.

18:53 but in a pinch:

18:53 (defn ns-docs

18:54 "Prints docs for all public symbols in given namespace

18:54 http://blog.twonegatives.com/post/42435179639/ns-docs

18:54 https://gist.github.com/timvisher/4728530"

18:54 [ns-symbol]

18:54 (dorun

18:54 (map (comp #'clojure.repl/print-doc meta)

18:54 (->> ns-symbol

18:54 ns-publics

18:54 sort

18:54 vals))))

18:54 justin_smith: danlentz: don't do that please

18:54 danlentz: sorry i thought it would be on one line

18:55 jonh: lol

18:56 danlentz: but it is a useful snippet, at any rate.

18:57 is #clojure hooked into lisppaste the same way #lisp is?

18:58 justin_smith: no, but refheap is popular

18:58 ~paste

18:58 clojurebot: paste is https://refheap.com/

18:59 coopernurse: clojure.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:00 it looks like cloc skips pure Java libs, so I don't see it in that UI

19:03 nullptr: coopernurse: http://jd.benow.ca/ ?

19:29 {blake}: Hmmm. A counter. So easy in a mutable language...

19:30 gfredericks: whatcha countin?

19:32 {blake}: records that I'm processing

19:32 In a for. It's a batch process.

19:33 gfredericks: what're you using the count for?

19:33 logging?

19:35 {blake}: progress indicator

19:35 "n of m records processed"

19:35 gfredericks: (doseq [[rec i] (map vector recs (range))] ...)

19:35 {blake}: Only it's always "1 of 160 records processed" :(

19:36 gfredericks: Ooh. Lemme see...

19:36 hiredman: ~for

19:36 clojurebot: for is ()

19:37 hiredman: clojurebot: jerk

19:37 clojurebot: you cut me deep, man.

19:37 {blake}: ~jerk

19:37 clojurebot: you cut me deep, man.

19:37 {blake}: lol

19:38 (inc gfredericks)

19:38 lazybot: ⇒ 123

19:38 {blake}: Groovy. And a good reminder to go over the clojure cheatsheet again.

20:35 doritostains: on 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:36 michaniskin|BNC: ,(let [{x :foo} '(:foo 100 :bar 200)] x)

20:36 clojurebot: 100

20:37 justin_smith: haha, wow

20:37 michaniskin|BNC: ,(let [{x :foo} '[:foo 100 :bar 200]] x)

20:37 clojurebot: nil

20:37 justin_smith: I did not expect that would work

20:37 michaniskin|BNC: I bet that's because [] is associative

20:37 ,(let [{x :foo} #{:foo}] x)

20:37 clojurebot: :foo

20:37 michaniskin|BNC: it's because let expands to an expression there that checks (seq? map_1234) ...

20:38 justin_smith: michaniskin|BNC: let, or destructure?

20:38 michaniskin|BNC: it's doing (clojure.lang.PersistentHashMap/create (seq map_1234))

20:38 in the macroexpansion of clojure.core/let

20:38 justin_smith: oh, interesting

20:39 michaniskin|BNC: ,(macroexpand '(let [{foo :asdf} (doit 100)]))

20:39 clojurebot: (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:39 justin_smith: michaniskin|BNC: yeah, it uses destructure to generate the bindings

20:39 michaniskin|BNC: i'm curious why it does that

20:41 i ran into it in a macro i wrote for cljs

20:41 https://github.com/tailrecursion/hoplon/blob/master/src/tailrecursion/hoplon.clj#L23

20:41 justin_smith: michaniskin|BNC: I am looking at where it does that in destructure, but it's a really hard function to read

20:42 michaniskin|BNC: i'm thinking to just postwalk-replace in the expanded form, replacing clojure.lang.PersistentHashMap/create with '(partial apply hash-map)

20:42 it should work the same and be compatible with both clj and cljs

20:42 i think?

20:43 justin_smith: why not change destructure so that it uses (partial apply hash-map) ?

20:43 Bronsa: seqs are treated automagically as hash-maps in destructure to allow for destructuring var-args as maps

20:43 justin_smith: aha!

20:43 Bronsa: it's an implementation detail afaik

20:43 justin_smith: (inc Bronsa)

20:43 lazybot: ⇒ 96

20:43 michaniskin|BNC: wow i see

20:44 justin_smith: yeah, it makes sense, how else would & {:keys [...]} work

20:44 michaniskin|BNC: ok that makes sense, i remember reading about this, the apply hash-map trick from CL or whatever

20:44 Bronsa: since a vararg is an arrayseq, & {:keys [foo]} can only work that way

20:44 justin_smith: yeah

20:45 michaniskin|BNC: ok cool so i can postwalk-replace there safely in my macro

20:48 ,(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:48 clojurebot: {:x 1, :y 2, :z 3, :foo 100, :bar 200}

20:48 michaniskin|BNC: haha neato

20:50 doritostains: never mind got the emacs problem fixed

20:50 justin_smith: doritostains: what was the issue?

21:45 julianleviston: Does anyone know of anything like David McNeil’s step.async for debugging core.async but in clojurescript?

22:13 srid: http://clojure.org/books is empty?

22:18 justin_smith: ~books

22:18 clojurebot: books is http://clojurebook.com/ http://joyofclojure.com/

22:18 justin_smith: srid: it's not empty when I go there

22:19 srid: it shows 5 books, all good ones

22:28 julianleviston: It’s blank for me in safari, but not in chrome

22:28 justin_smith: ad block?

22:28 julianleviston: oh yeah! haha :)

22:29 justin_smith: I think the books on the page might show up as ads, kind of makes sense

22:32 julianleviston: justin_smith: yeah, I think adblock stops any image that has a src on a different domain than your site is on or something…

22:32 justin_smith: julianleviston: it could also have to do with the fact that they are amazon affiliate links

22:33 julianleviston: justin_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:33 and they’re not ads.

22:34 but yes :)

22:34 (inc justin_smith)

22:34 lazybot: ⇒ 217

22:34 julianleviston: justin_smith: thanks for that, because it helped me work out why those images weren’t displaying

22:35 justin_smith: hah, nice

22:39 one liner to find all defined unit tests: (->> (all-ns) (mapcat (comp vals ns-interns)) (filter (comp :test meta)))

23:03 celwell: Hi, how could I make doseq execute the body expression before the :while is checked?

23:04 Would I have to put my expression in the :let? That would seem complected.

23:04 Here's my example:

23:04 (doseq [z '(1 2)

23:04 :let [o (take-order-from-zone z)]

23:04 :while (nil? o)]

23:04 (println o))

23:04 justin_smith: there's always (doseq [o (map take-order-from-zone '(1 2))] ...)

23:05 celwell: I want to loop through until we are done ignoring nils and then do the next value and then stop.

23:07 justin_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:08 justin_smith: oh, OK

23:08 celwell: I think the map would mess up the priority map in my atom

23:08 the (map) i.e.

23:08 justin_smith: laziness and side effects aren't a great match most of the time, yeah

23:09 celwell: something liek this maybe:

23:09 (doseq [z '(1 2)

23:09 :let [o (take-order-from-zone z)

23:09 blah (println o)]

23:09 :while (nil? o)]

23:09 )

23:09 justin_smith: _ is the canonical name for blah, btw

23:10 celwell: thx

23:10 justin_smith: there's also (doto (take-order-from-zone z) println)

23:10 which prints, then returns the thing it printed

23:11 ToxicFrog: Why on earth does re-groups return [match g0 g1 g2...] if there are capture groups, but match (not [match]) if there aren't?

23:11 justin_smith: ToxicFrog: that seems like a bad choice

23:11 ToxicFrog: It means (drop 1 (re-groups ...)) gets you all of the capture groups without the whole-match string, unless there are no capture groups

23:11 In which case instead of getting [], you get a seq of the individual characters of the whole match with the first character missing

23:11 That was a fun bug to track down

23:11 justin_smith: haha

23:13 celwell: justin_smith: hmm... maybe I should put a doto in my :while predicate. like:

23:13 (doseq [z '(2 1)

23:13 :let [o (take-order-from-zone z)]

23:13 :while (nil? (doto o println))])

23:13 that might eb the prettiest option but it's still not that good i guess

23:13 justin_smith: yeah, that totally works

23:14 ToxicFrog: I realize it's probably too late to change it now, but why?

23:17 justin_smith: ~why

23:17 clojurebot: why is the ram gone is <reply>I blame UTF-16. http://www.tumblr.com/tagged/but-why-is-the-ram-gone

23:18 justin_smith: clojurebot: that's a mess of a factoid

23:18 clojurebot: Excuse me?

23:37 julianleviston: clojurebot: that’s a mess of a monoid

23:37 clojurebot: Huh?

23:57 arav93: I was testing typed clojure annotations. I keep getting the following error

23:57 lein 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:57 in 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:58 ^ the second part

Logging service provided by n01se.net