#clojure log - Sep 30 2015

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

0:16 sm0ke: ,`memoize

0:16 clojurebot: clojure.core/memoize

0:16 sm0ke: shouldbe in cljs.core

2:12 * akkad fights to get lein to use a bigger minstack size

2:25 amalloy: akkad: (a) why do you need a bigger stack, really; (b) why is it a fight? just set the appropriate jvm option

3:24 Guest21161: i'm looking for a clojure library which i can use to navigate websites: fill in forms, login, download a file etc

3:30 algernon: enlive sounds like something you could use for that.

3:56 nowprovision: enlive works well but won't handle any on page javascript

3:56 personally I prefer phathomjs for this sort of stuff

3:57 or actually even node.js with cheerio over enlive for extraction but for interaction phanthom js, and enlive as an alternative for building web pages (css path substitutions)

5:12 marshzor: if I have a seq that I'm fairly certain will always contain one element, is there a good way to extract that element? Currently I'm using (first myseq)

5:13 I have a list of ui elements, each with an id. I get an event saying element with id=foo was clicked. so I get (filter #(= (:id event) (:id %)) ui-elements)

5:14 hyPiRion: marshzor: you can do (let [[elem] myseq] elem) if you need to bind the result

5:14 marshzor: interesting, let me give that a try

5:14 hyPiRion: er, I mean (let [[elem] myseq] my-code)

5:15 marshzor: mhm I knew what you meant

5:16 definitely seems more sane than what I had, although I'm not sure how this would act if the seq actually did contain more than one element

5:16 ,(let [[elem] '(1)] elem)

5:17 clojurebot: 1

5:17 marshzor: ,(let [[elem] '(1 2)] elem)

5:17 clojurebot: 1

5:17 marshzor: so is it just sugar for first?

5:17 hyPiRion: yeah

5:17 marshzor: ah okay

5:17 hyPiRion: ,(macroexpand '(let [[a] b] a))

5:17 clojurebot: (let* [vec__77 b a (clojure.core/nth vec__77 0 nil)] a)

5:32 fehrenbach: ,(source first)

5:32 clojurebot: Source not found\n

6:00 visof: hi guys

6:01 how can i declare function with two options artgument in defprotocol?

6:02 (defprotocol Hello (foo [a]) (foo [x y])) ? and handle it (defn foo ([x] "Hello") ([x y] "hello hello")) ?

6:02 is this correct?

6:10 bendlas: apparently build.clojure.org is down and this prevents dependency resolution hence startup of projects depending on datomic

7:09 visof: is there any tool which can take file.clj and autoindent it?

7:53 mavbozo: visof, https://github.com/weavejester/cljfmt

8:24 nowprovision: it's not perfect quite perfect, vim clojure plugin disasgrees with a small indent rule (which I think clojure style guidelines agrees with vim clojure)

8:24 but at least it diffs rather than forces the hand like gofmt (and vim-go)

8:33 visof, (defprotocol P (foo [this] [this arg2]))

8:33 visof, (defrecord R [] P (foo [this] this) (foo [this arg2] arg2))

8:52 marshzor: does anyone know a good way to evaluate a seq of bools? I want to know if they are all true

8:53 schmir: ,(doc every?)

8:53 clojurebot: "([pred coll]); Returns true if (pred x) is logical true for every x in coll, else false."

8:54 tdammers: ,(all [true true true true])

8:54 clojurebot: #error {\n :cause "Unable to resolve symbol: all in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: all in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: all in this conte...

8:54 tdammers: pff

8:54 ,(and [true true true true])

8:54 clojurebot: [true true true true]

8:54 tdammers: ,(apply and [true true true true])

8:54 clojurebot: #error {\n :cause "Can't take value of a macro: #'clojure.core/and"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Can't take value of a macro: #'clojure....

8:54 tdammers: that didn't go as expected

8:55 marshzor: yep, that's what I was looking for schmir, ty

9:08 dzhus`: If I update dependencies in my project.clj, can I get CIDER to pick the up in the classpath without killing the REPL buffer and jacking in from scratch?

9:27 schmir: dzhus`: there's vinyasa that may help a bit (at least with new dependencies). upgrading probably doesn't work though (just guessing)

9:37 ionthas: Is there any way to apply a function to each vector inside a vector? (def v3 [[10 [1 2]] [30 [4 5]]]) I would like to apply a custom function to each vector. Using (apply) results on a "Wrong number of args exception".

9:37 dzhus`: ionthas: I believe you might use something from clojure.walk

9:38 ionthas: I will take a look, thanks!

9:51 oddcully: ionthas: sounds like map

9:53 ionthas: oddcully: I have done a loop/recur through all my vector and I apply the function to each vector. I supose there's a more idiomatic way to do it. :/

9:55 oddcully: ,(map (fn [[_ v]] (apply + v)) [[10 [1 2]] [30 [4 5]]])

9:55 nowprovision: yes clojure.walk if they are at unpredicable depths

9:55 clojurebot: (3 9)

9:55 oddcully: i don't know, what you are after

10:16 devn: ,(require '[clojure.walk :as walk])

10:16 clojurebot: nil

10:20 devn: was going to drop an example, but yeah, might make more sense to hear what you're looking for

10:20 since oddcully's example will do what you first described

10:21 justin_smith: ionthas: (for [subcoll coll] (apply f subcoll)) might do what you want?

10:24 ionthas: nvm folks I already solved the problem with a solution similar to the one provided for justin_smit. Thank your for your ideas.

10:24 devn: ,(for [subcolls :)

10:24 clojurebot: #<RuntimeException java.lang.RuntimeException: Invalid token: :>

10:24 devn: derp

10:30 dzhus`: I believe that using components library implies that I need to have a "main" function in my app that will actually start the components?

10:31 But I do `lein ring uberjar` to build my app which only requires ring routes to be defined, can I somehow tweak the main function it generates for me to include components startup?

10:33 justin_smith: dzhus`: do component startup in the function that returns your handler

10:39 dzhus`: justin_smith: I don't think that I have one. I have a defintion of my routes and handlers but no function that "returns" them

10:45 justin_smith: dzhus`: I forget if lein ring has a mechanism for this directly... but if nothing else you should be able to define the handler in terms of a delay (so that it only runs when the handler is to be used, and only runs on first usage)

10:46 (def initialized (delay (startup-system))) (def handler (fn [request] @initialized (real-handler request))

10:47 the only problem with this is it makes the very first request to the newly started server wait for system init

10:48 dzhus`: LOL ignore the above hack - just look at the README here - use :init https://github.com/weavejester/lein-ring#general-options

10:48 dzhus`: duh, should have looked there

10:48 thanks

10:49 justin_smith: heh, np, but the delay trick is generally useful if you need to hack in init in something that doesn't provide the option :)

12:21 hlolli: who's would know of cleaver way to make a function that finds the avarage of two numbers in a list and put into new list, so I could get: [0.5 1.5 2.5 3.5] from [1 3] and [0 1 2 3] from [0 2]

12:23 jeremyheiler: hlolli: use something like (map avg (partition ...))

12:23 and then flatten it

12:24 justin_smith: jeremyheiler: or you could just use mapcat instead of map

12:24 flatten is pretty terrible

12:24 hlolli: so far I have (vec (flatten (for [[x y] (partition 2 1 on-s)]

12:24 (list (- y (/ (+ y x) 2)) (+ y (/ (+ y x) 2))))))

12:25 jeremyheiler: justin_smith: i meant the general idea of flatten

12:25 justin_smith: trying not give the whole answer away ;-)

12:25 justin_smith: jeremyheiler: OK, well mapcat does that all in one go with your mapping

12:25 jeremyheiler: yes, that' better

12:25 hlolli: well, I use flatten shamelessly, damn.

12:25 blake_: I guess you'd have to.

12:26 I mean, if you had any shame...

12:26 justin_smith: hlolli: flatten has a few issues - it breaks things that could otherwise work with collections as arguments, and it can do unexpected things for some inputs

12:27 blake_: And speaking of shame, I have a realized LazySeq that refuses to be iterated over. What's up with that?

12:27 hlolli: ok, never ran into any problems so far. Its just that some functions always return extra parenthesis. For example everyting after the & sign

12:28 I know its for good reason, but I tend to flatten it or unqote splice it.

12:28 blake_: like, (map #(println %) my-lazy-seq) produces nothing.

12:28 hlolli: tried doall ?

12:28 blake_: Yep.

12:28 hlolli: and take?

12:28 blake_: take?

12:29 hlolli: (take n coll)

12:29 blake_: huh, no...

12:29 I didn't know that was a thing. I'm still trying to figure out how this can happen.

12:30 Nope, (take n coll) doesn't work either.

12:30 Count returns the right number of items.

12:31 First returns the first item. Last returns the last item. Map produces nothing. For produces nothing.

12:31 hlolli: ,(take 5 (map #(conj "hoho" %) (cycle "1")))

12:31 clojurebot: #<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IPersistentCollection>

12:32 hlolli: ,(take 5 (map #(conj "hoho" %) [(cycle "1")]))

12:32 clojurebot: #<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IPersistentCollection>

12:33 hlolli: ,(take 5 (map #(conj "hoho" %) (cycle ["1"])]))

12:33 clojurebot: #<RuntimeException java.lang.RuntimeException: Unmatched delimiter: ]>

12:33 hlolli: last time :)

12:33 blake_: heh

12:33 hlolli: ,(take 5 (map #(conj "hoho" %) (cycle ["1"])))

12:33 clojurebot: #<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IPersistentCollection>

12:33 hlolli: damn, fukkit, I should do it in my own repl first.

12:34 ,(take 5 (map #(conj [1] %) (cycle [2 3])))

12:34 clojurebot: ([1 2] [1 3] [1 2] [1 3] [1 2])

12:35 hlolli: ,(type (take 10 (cycle "a")))

12:35 clojurebot: clojure.lang.LazySeq

12:35 hlolli: cycle is a lazy seq....

12:36 are you using the lazy-seq function?

12:36 blake_: Nope. I got this LazySeq out of a map.

12:37 It responds to no iterative requests from what I can tell.

12:37 If I say (into #{} my-lazy-seq) I get nothing back.

12:38 wait..

12:39 hlolli: well, you may need to map/apply/reduce it.

12:39 blake_: It does response to (into #{}).

12:39 er respond to

12:39 I'm trying to map it and it acts as though it's empty

12:39 While claiming to have 2 items, showing me the first, last...

12:40 hlolli: yes, it doednt calcualte the lazy sequence. Is it infinite?

12:40 blake_: Nope, it's very finite. One or two items. I mean, eventually, it could be several dozen. But well short of infinity. =P

12:41 hlolli: how about (into #{} (doall my-lazy-seq)) or (map #(into #{} %) my-lazy-seq)

12:42 blake_: Newp.

12:42 Into [] and #{} do make "copies" but they won't iterate either.

12:42 This has to be something burningly stupid.

12:43 If first, last and rest work on it, how can map possibly not?

12:46 hlolli: Im very surprised, there is something you are overseeing, is I would see this I could maybe help better.

12:47 blake_: https://www.refheap.com/110118

12:47 Lotsa printlns in there.

12:47 hlolli: have you tried simply (apply hash-map lazy-seq)

12:50 blake_: That seems to wrap things up in another layer. Still doesn't iterate, though.

12:50 xeqi: blake_: for and map are lazy, those printlns never get realized and thus never print

12:51 blake_: xeqi: Hmm. OK. I have to think about that because they weren't originally printlns.

12:55 OK. So...I was using map for side-effects. That's gotta be the problem.

12:56 justin_smith: blake_: didn't someone ask about doall?

12:56 blake_: justin_smith: Yeah, and I had doall.

12:56 justin_smith: in the wrong place then?

12:57 blake_: in 1.7 you can use run! instead of map (if you don't need the return value) - same arg usage

12:57 blake_: justin_smith: Yeah. And I was testing with (map (println... which I shouldn't do. And then following it up with a map to produce side-effects.

12:57 justin_smith: blake_: ahh, OK

12:58 blake_: justin_smith: The issue (mentally) is that I'm thinking in pure functions--but underneath I've got a Java object.

12:58 When I transition between them, I have...issues.

14:08 sven42: Hi - is there any way to call elisp functions from the clojure cider repl? I want to (read-string "prompt:")

14:14 mgaare: sven42: eval-last-sexp

14:23 triss: so how would you chaps go about parsing blobs of EDN out of a Markdown file?

14:23 specificly keywords and maps

14:24 I really want to associate the blobs of EDN with the most recent header in the markdown some how too.

14:39 TimMc: triss: Arbitrary EDN would be hard to spot, yeah.

14:39 For example, this sentence contains 9 valid EDN blobs.

14:40 triss: yup. but I'm just after keywords and maps

14:41 so this sentance only :contains only {2 "EDN blobs"}

14:41 or is that 5 I guess....

14:41 think I'm gonna just reg-ex for them and then parse

14:42 TimMc: I'd look for #"(^|\s)[:{]" a pushback reader try feeding those into read.

14:42 *in a

14:42 triss: do any of the clojure based markdown libs give you nice structured output?

14:42 TimMc: precisley what i'm thinking!

14:43 numberten: will throwing an exception short circuit a let binding in clojure?

14:43 TimMc: Are you going to be running your documentation through tests? :-D

14:44 numberten: Like in (let [a (/ 1 0) b (println "b")] ...), you're wondering if b's value is computed?

14:44 numberten: (let [a 1 b (throw (Exception. "bad")) (c (foo b))] (etc))

14:44 seems dangerous, if the entire function doesn't propagate the exception

14:45 TimMc: yeah that

14:45 TimMc: Well, the exception stops execution of the entire let expression, so yeah, further bindings are not evaluated -- nor the body.

14:51 numberten: thanks

15:25 amalloy: so guys, i realized the other day that `(~x ~@xs) is fewer characters than (cons x xs). alert the press, we don't need cons anymore!

15:26 oddcully: fetch me my codecolf putter

15:29 fuuduCoder: smetimes verbosity matters :-P

15:49 ghadishayban: oh man I miss clojure.

15:49 been doing python and Spark lately

15:49 Languages Matter.

15:50 aaelony: ghadishayban: are you doing Spark from Clojure?

15:51 ghadishayban: also, is it reasonable to try to do python via pixie-lang with clojure syntax ?

16:03 neoncontrails: aaelony: your suggestion kind of reminds me of a project I've been mulling over. How hard do you think would it be to implement a Python interpreter in Clojure?

16:05 aaelony: neoncontrails: wouldn't it be great to use libs like scikit-learn from a clojure syntax?

16:05 neoncontrails: It seems like one of those projects which would be easy to set up, but possibly hard to get right. Lots of edge cases

16:05 aaelony: certainly

16:09 ghadishayban: aaelony: not from clojure. Team isn't really Lisp / FP oriented

16:09 neoncont_: Sorry, battery died. Can you think of any technical hurdles that would make interpreting scipy from Clojure painfully difficult?

16:10 If I'm not mistaken, part of the magic of scikit comes from a C-based implementation

16:37 xemdetia: neoncont_, it seems faster just to get jython and clojure to talk :)

17:03 aaelony: ghadishayban: I think both https://github.com/gorillalabs/sparkling and https://github.com/yieldbot/flambo offer Spark use from Clojure

17:06 neoncont_: not sure, but this talk on pixie got me thinking these crazy-like ideas about using python libs from clojure syntax... https://www.youtube.com/watch?v=1AjhFZVfB9c

17:23 TEttinger: aaelony: ghadishayban left, I wanted to mention that I encountered some pitfalls trying to get some spark concepts to carry over to clojure

17:24 aaelony: it is neat how clojure seems to be revitalizing lisp dev a bit, that and racket

17:24 people seem to be more willing to make new languages that are unashamed to use parentheses

17:27 aaelony: TEttinger: I agree. Speaking for myself, I find that it is easier to come back to a project and figure out what is going on just by looking at each function involved. In other languages, it's unclear what an object is doing under the hood and what is being changed inadvertently or mysteriously. Just my 2 cents.

17:28 justin_smith: TEttinger: you can't really use python libs from pixie though.

17:28 TEttinger: it uses rpython to compile a vm that does not contain the python runtime - the python runtime would be a separate (and I think incompatible) target for rpython. Pixie doesn't load python libs.

17:29 TEttinger: TEttinger is not who you mean

17:29 aaelony: aaelony: I plead ignorance here. But it would be cool if it were so.

17:29 justin_smith: TEttinger: oh, sorry

17:29 TEttinger: hehe

17:30 justin_smith: aaelony: my above directed at TEttinger was actually responding to what you said

17:30 aaelony: justin_smith: I realize that

17:30 :)

17:33 mcescher: iosjdf

17:33 sorry

17:33 justin_smith: today's contestants in "tech acronym or keyboard noise" are...

17:34 ane: i once sneezed and wrote tanstaafl when i meant to write that is

18:00 blake_: Hey, all: Trying to use wrap-anti-forgery and ALL my POST pages are returning Invalid Anti-Forgery Token. I can see the token inside the page. I used the (anti-forgery-field) function. I put csrf/wrap-anti-forgery just above session.

18:00 And yet...

Logging service provided by n01se.net