#clojure log - Oct 09 2015

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

1:28 elg: I'm getting "my.namespace.MyRecord cannot be cast to java.util.concurrent.Future" but only in tests. It seems, maybe, to be because my record methods are using the @ reader macro for the atom state?

1:34 justin_smith: elg: yes, "cannot be cast to future" is almost always because the wrong thing has @ in front of it

1:34 ,@\?

1:34 clojurebot: #error {\n :cause "java.lang.Character cannot be cast to java.util.concurrent.Future"\n :via\n [{:type java.lang.ClassCastException\n :message "java.lang.Character cannot be cast to java.util.concurrent.Future"\n :at [clojure.core$deref_future invokeStatic "core.clj" 2187]}]\n :trace\n [[clojure.core$deref_future invokeStatic "core.clj" 2187]\n [clojure.core$deref invokeStatic "core.clj" 2209...

1:35 elg: hm. well the @ is in the right place - this works as it should when I use the code, it only breaks in this test

1:35 justin_smith: then your test should be providing something that can be dereffed?

1:36 elg: a favorite trick of mine is providing a delay where the code expects a future or atom, because it can be dereffed, but can't do much

1:36 (which reduces confusion)

1:36 this is all in testing contexts, of course

1:39 elg: ah-hah. It's my mock that doesn't have an atom but should

1:39 justin_smith: or a delay!

2:19 skoude: Noob question, clj-http.client get function return ring map.. The problem is that how can I get just for example print what's inside the :body ? I tried like (println (json :body)) and (println (get json :body)) but none of these works..

2:36 justin_smith: skoude: what is "json"

2:37 try (type json)

2:37 if it's a hash-map like you think, check the values of (keys json)

2:40 skoude: justin_smith: it's: clojure.lang.PersistentArrayMap

2:40 justin_smith: OK, so what are the keys?

2:41 skoude: justin_smith: their: (:orig-content-encoding :trace-redirects :request-time :status :headers :body)

2:41 justin_smith: OK, then (:body json), or (json :body) (I prefer the former) will show you exactly what is there

2:42 maybe the body is empty / nil ?

2:42 skoude: justin_smith: no the body is not empty.. I I write the whole Map to file, I see that there is some json data,..

2:43 maybe I ave some sort ot typo.. I will double checkk

2:43 btw.. Have been programming java like 15 years.. and started to lear this yesterday.. Seems like very powerfull language.. It just takes time to learn the syntax :)

2:44 justin_smith: the syntax may be unfamiliar, but it is very simple actually - far less complex than most languages

2:45 skoude: yeap, I noticed that.. just need to get used to it..

2:49 another stupid question.. If I do like: (filecore/write-to-file "jsonoutput.js" json) the whole map is written to file..

2:49 but if I do like: (filecore/write-to-file "jsonoutput.js" (:body json)) the object name is just wirtten to file.. D

2:50 justin_smith: I don't get that at all.

2:50 perhaps you shadow the object?

2:50 skoude: In the first one the whole data in the map is written to file with all the json and all the keys

2:51 but in the second one I get: clojure.lang.LazySeq@b823df75

2:51 that is written to file

2:52 justin_smith: OK, that's because lazy-seqs print oddly, use pr-str

2:52 pr-str is different from the normal toString in that it tries to print the form that can be read again

2:53 ,(str (map inc range))

2:53 clojurebot: #error {\n :cause "Don't know how to create ISeq from: clojure.core$range"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: clojure.core$range"\n :at [clojure.lang.RT seqFrom "RT.java" 535]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 535]\n [clojure.lang.RT seq "RT.java" 516]\n [clojure.core$seq__4116 invokeStatic "core.clj" 137]\n [cl...

2:53 justin_smith: ,(str (map inc (range)))

2:53 clojurebot: #error {\n :cause "Java heap space"\n :via\n [{:type java.lang.OutOfMemoryError\n :message "Java heap space"\n :at [clojure.lang.Iterate next "Iterate.java" 54]}]\n :trace\n [[clojure.lang.Iterate next "Iterate.java" 54]\n [clojure.lang.ASeq more "ASeq.java" 131]\n [clojure.lang.RT more "RT.java" 690]\n [clojure.core$rest__4102 invokeStatic "core.clj" 73]\n [clojure.core$map$fn__4541 invok...

2:53 justin_smith: ergh, never mind, I forget how to make that happen now

2:53 ,(str (map inc (range 10)))

2:53 clojurebot: "clojure.lang.LazySeq@c5d38b66"

2:53 justin_smith: ,(pr-str (map inc (range 10)))

2:53 clojurebot: "(1 2 3 4 5 ...)"

2:54 justin_smith: there we go, see the difference

2:54 skoude: justin_smith: Thanks, I will try that one out :)

2:54 justin_smith: pr-str has other advantages too:

2:54 ,((juxt str pr-str) {:a "hello" :b 'hello})

2:54 clojurebot: ["{:a \"hello\", :b hello}" "{:a \"hello\", :b hello}"]

2:55 justin_smith: oops

2:55 ,(map print ((juxt str pr-str) {:a "hello" :b 'hello}))

2:55 clojurebot: ({:a "hello", :b hello}{:a "hello", :b hello}nil nil)

2:55 justin_smith: I swear there's a case where you see a difference

2:55 aha!

2:55 ,(map print ((juxt identity pr-str) {:a "hello" :b 'hello}))

2:55 clojurebot: ({:a hello, :b hello}{:a "hello", :b hello}nil nil)

2:56 justin_smith: there's the difference

2:57 skoude: justin_smith: brilliant, it worked like a charm :) No I will parse the json..

2:58 btw. I noticed that println is taking away the " from json, is there a way to preserve those when printing to console?

2:58 justin_smith: skoude: that's what I was trying to show above

2:58 you can use pr-str to surround the value, or you can use prn instead of println

2:58 skoude: justin_smith: aah, okay I see :)

3:07 Is there a javadoc equivalent for clojure?

3:07 or any same kind of mechanism that would automatically generate the documentation from code?

3:16 TEttinger: skoude: there's a literate programming doc generator that's somewhat popular

3:16 under Documentation Tools at http://www.clojure-toolbox.com/

3:17 several are listed

3:18 skoude: TEttinger: thanks, I will check that out

3:18 TEttinger: the literate programming one I was thinking of was https://github.com/gdeer81/marginalia

3:18 I think Codox is more commonly used

4:00 skoude: hmm.. I really don't get this,. (def jsonbody (str(:body json)))

4:00 it says that: java.lang.String cannot be cast to clojure.lang.IFn

4:01 I try to assing the :body part of the json -map to jsonbody..

4:01 Seylerius: There isn't a clojure equivalent of pelican/octopress, is there?

4:02 mavbozo: Seylerius, cryogen? http://cryogenweb.org/

4:03 Seylerius: mavbozo: That looks suspiciously like just what I asked for. Thank you.

4:04 ianhedoesit: skoude: is that the exact code that gives that exact error?

4:10 kungi: magnars: In your Parens of the Dead videos you narrow the file to only show functions which call the function you are refactoring. How did you do that in emacs?

4:12 magnars: kungi: it's my symbol-focus mode, found here: sed -i "s/return res/module.exit_json(**res)/g" /usr/local/lib/python2.7/dist-packages/ansible/modules/core/packaging/os/yum.py

4:12 ack

4:12 here: https://github.com/magnars/.emacs.d/blob/master/site-lisp/symbol-focus.el

4:16 kungi: magnars: When are you going to release the next video? :-) I want to know more about games and zombies :-)

4:16 magnars: And thank you!

4:16 magnars: :) I got lazy at some point, but planning to get it done this weekend.

4:20 kungi: magnars: Lazy tsts :-)

4:29 Seylerius: Next question: is there an org parser for clojure?

4:30 Hmm... This seems promising.

4:30 https://github.com/gmorpheme/organum

5:34 skoude: ianhedoesit: thanks, I got it working..

5:34 schmir: I've got a byte[] containing an excel sheet that I like to send back via a ring response to the users browser

5:35 I get a "java.lang.RuntimeException: class [B is not understandable" from httpkit

5:35 anyone know how to send back the data?

5:38 skoude: if I decode json string withj parse-string: (def json3 ( parse-string jsonbody));

5:38 the json3 type is string.. Should that be map?

5:38 luma: schmir, create a ByteArrayInputStream from the byte[] and use that as the response body

5:39 (java.io.ByteArrayInputStream. bytes)

5:40 schmir: luma: that works. Many thanks.

9:20 mkr: I want to do a native app project and am considering Reagent. My friend is pushing for pure react-native as we don't have much experience with Reagent.

9:21 I want to know whether Reagent can be used for both android and ios development

9:21 I have seen examples on ios

9:21 but can't find much help on Android

9:21 someone tried android development?

9:25 I guess everyone's busy with their own lives.. thanks :)

9:47 snowell: mkr: You might have more luck over in #clojurescript

9:47 justin_smith: also, not leaving after four minutes

9:47 snowell: Yeah, I have part messages off. That also would have helped

10:57 gfredericks: anybody know the explanation for this off the top of their head?

10:57 ,(-> [-128] byte-array String. .getBytes seq)

10:57 clojurebot: (-17 -65 -67)

10:57 gfredericks: I'm not saying it should do anything different, just don't know what's at play exactly

10:57 in terms of encodings

11:08 dstockton: ,(-> [-128] byte-array (String. "ISO-8859-1") .getBytes seq)

11:08 clojurebot: (-62 -128)

11:08 dstockton: ,(-> [-128] byte-array (String. "ISO-8859-1") (.getBytes "ISO-8859-1") seq)

11:08 clojurebot: (-128)

11:08 dstockton: gfredericks: does that help?

11:10 gfredericks: dstockton: well I'm not trying to achieve a different output

11:11 just trying to explain the one I have

11:11 have been reading some docs and I think it might be undefined behavior, as I think [-128] is not a valid UTF-8 bytesequence?

11:12 dstockton: nope and that's probably the default charset of your system

11:13 gfredericks: right, it is according to (System/getProperty "file.encoding")

11:13 so I think that's a good enough explanation: not all byte sequences are valid UTF-8, and GIGO

12:06 {blake}: Given a list of items, this sums the number of truthy values: (reduce (fn[acc i] (if i (inc acc) acc)) 0 a-list)

12:06 I feel like there might be a more elegant way to do that.

12:06 justin_smith: {blake}: (count (remove nil? a-list))

12:08 (apply + (map #(get {nil 0} % 1) a-list))

12:08 that last one is silly

12:09 {blake}: Heh...I like that first one! Is there a "remove falsey?" or would I need a function?

12:10 justin_smith: (keep identity ...)

12:10 I thought you were just taking out nil

12:10 {blake}: summing truthys

12:10 justin_smith: ,(keep identity [true nil false :a "" ()])

12:10 clojurebot: (true false :a "" ())

12:10 justin_smith: oh, not keep!

12:10 ,(filter identity [true nil false :a "" ()])

12:10 clojurebot: (true :a "" ())

12:11 justin_smith: keep is also nil-specific

12:11 {blake}: Int'resting.

12:12 There is false? though.

12:12 It's a good example of why you should pick one or the other in a given structure.

13:16 nzst: Hi, is http://www.luminusweb.net/ the only game in town for web frameworks?

13:16 justin_smith: ~framework

13:16 clojurebot: framework is a library obsessed with its own abstractions

13:16 justin_smith: nzst: I was hoping for a more helpful factoid from clojurebot, but anyway, in clojure for better or worse, frameworks are not very popular

13:17 that said, pretty much everyone doing web dev with clojure is building on ring (including luminus)

13:17 see also liberator, pedastel, immutant

13:18 nzst: thank you :)

13:50 hoppfull: Hello. I hear calling clojure from java or .net, the preffered way is to use the method where pass a string with the name of the clojure script rather than compiling clojure with (:gen-class). This was a little hard for me to swallow at first but I figure I my instincts might be wrong.

13:50 justin_smith: the string is the argument used to look up a defined var, right?

13:51 hoppfull: Isn't it a little unsafe to call clojure functions with strings? And perhaps not very efficient. Or is my assumption that we need to call clojure from java or c# wrong?

13:51 justin_smith: I think so.

13:51 justin_smith: hoppfull: specifically which method are you supplying a string to?

13:51 hoppfull: justin_smith: give me a sec and I'll get it

13:54 Let's see: in the clr we do IFn myfunc = clojure.clr.api.Clojure.var("myclojurefile", "myfunc")

13:54 justin_smith: right, that's a var lookup

13:54 hoppfull: And then I think we call that function with myfunc.invoke("5"); for example

13:54 justin_smith: hoppfull: that's weird

13:55 unless the function expects a string?

13:55 hoppfull: justin_smith: I originally recoiled at this when I heard this was common practice.

13:55 justin_smith: because clojure functions don't take strings and eval them

13:55 it's not just a bad idea, it isn't even how clojure works

13:55 clojure uses the native data types of its host

13:56 we can explicitly parse strings, but most of our functions are not doing that

13:56 hoppfull: the string arg to var isn't dangerous, it's a lookup in a hash-map, if the wrong string is compiled

13:56 hoppfull: justin_smith: maybe I've got something wrong. Because I insisted on compiling clojure with (:gen-class) and in the REPL (compile 'myclojurefile)

13:56 justin_smith: you don't need to call compile

13:56 hmm...

13:56 hoppfull: But it was so messy that I was sure I was doing it the wrong way.

13:57 justin_smith: so, the Clojure.var call looks up a var in a namespace - it will fail if the namespace is not already loaded

13:57 hoppfull: I've played a lot with clojure for the jvm a while back. And I really liked Clojure. Now I am studying .Net in school and I want to play with Clojure again. Except I am going to stick to .Net.

13:58 justin_smith: usually the first thing you would do is use var to look up require and symbol, and use those to construct and invoke the require call that compiles and loads your code

13:58 var gets string args and looks them up, but otherwise you should be able to use the functions that var returns with the actual data type that function uses

13:58 hoppfull: justin_smith: But this is safe?

13:58 justin_smith: in fact you should be required to do so

13:59 hoppfull: no safer or less safe than using another compiler

13:59 require / compile will both invoke the compiler

14:00 clojure on the jvm or clr does not have a runtime without a built in compiler

14:00 hoppfull: justin_smith: Thanks for the help. I am going to play around a little with this and see if I can get over my anxiety. ; )

14:01 Wait, what do you mean by "built in compiler"?

14:01 justin_smith: hoppfull: clojure supports aot compilation, but the compiler will still be loaded at runtime

14:01 hoppfull: clojure is a compiler

14:01 hoppfull: Right, I've heard this. Doesn't that make it a little slow?

14:01 justin_smith: it's not an interpreter running a script, it's a compiler generating byte-code that can be run by clojure itself or host code

14:02 hoppfull: justin_smith: And doesn't that provide us with the same issues as python? If we don't compile it, how can we protect our source code?

14:02 justin_smith: it's slow in the sense that if you compile at runtime, you have to wait for the compilation - but that shouldn't be your bottleneck

14:02 hoppfull: python compiles?

14:03 hoppfull: justin_smith: No. Not unless you use cython. Which is a problem if you want to distribute your application.

14:03 justin_smith: hoppfull: most clojure folks don't protect their source code, but then again most of us are not shipping client desktop apps

14:03 hoppfull: justin_smith: How could you ever distribute an application in clojure?

14:03 justin_smith: hoppfull: but you can aot compile, and you can ship bytecode without source, it's just not done very often

14:03 hoppfull: I wouldn't

14:03 or at least, I have not yet

14:03 I deploy to servers I control

14:04 and clients connect to that server

14:04 hoppfull: Interesting.

14:04 justin_smith: hoppfull: clojure isn't used much for app dev, but most code being shipped out there is not app code

14:04 most code as in most code in all languages, not just clojure

14:06 hoppfull: I am a little speechless. I didn't know that one wouldn't care about this.

14:06 justin_smith: hoppfull: it hasn't come up because in all my experience coding I have never shipped an "app", only server side or browser based code

14:07 if I were shipping an app that had to be closed source, I would aot-compile and not ship the source

14:08 hoppfull: justin_smith: Alright. Still, aot is a little messy. And it seems unnecessarily slow to me.

14:09 justin_smith: hoppfull: that slowness happens regardless - either at packaging time, or else the same work is done when the app starts up

14:09 there's no free lunch, the stuff is compiled eventually no matter what

14:09 hoppfull: justin_smith: But it's only at startup? I haven't made any large programs with clojure yet.

14:09 justin_smith: Aot is only messy if you have side effects in the top level of your code. You shouldn't be doing that anyway.

14:10 hoppfull: sure, the time is either at build time or start up, but most apps start up multiple times for one build, so build time is the better time to do that job

14:11 hoppfull: justin_smith: This has been interesting. Thanks for your insights!

14:12 justin_smith: np

14:12 in my experience all the changes I need to make for aot to work are fixes of what I would consider bugs in the code (the code was taking some action at compile time that it should not be)

14:13 eg. (def conn (connect db-spec)) - that connects to the db at compile time, which is obviously a bad thing to be doing...

14:34 sobel: justin_smith: heh, i had a similar exp fixinga lot of bugs just to make a nest of spring dependencies work (i was adding spring to a prj that was otherwise pure adhoc spaghetti-OO

14:34 i didn't realize they were all bugs due to order of creation issues

14:35 it was my 'object' lesson on not getting fancy with creation patterns

15:07 justin_smith: hehe, you said "object"

15:09 taylan: justin_smith: compiling code actually executes the top-level?

15:10 justin_smith: taylan: yes, which is why you should not have top level side effects

15:10 taylan: weird, would have expected the top-level to be executed at load time

15:10 justin_smith: taylan: clojure's compiler only has one "mode", there is no separate "no side effects" mode available

15:11 in order to compile (def x (foo)), clojure executes foo

15:11 taylan: well, a compiler should not be running any of the compiled code at all (not counting partial-evaluation optimizations), should it?..

15:11 justin_smith: taylan: that's not true of clojure's compiler at all

15:11 taylan: anyway, guess I'll need to get used to that. it's different from how I'm used to things from e.g. Elisp and Scheme

15:11 justin_smith: clojure's compiler doesn't do any optimization either

15:12 taylan: it's a little weird, but it's actually very simple and consistent - only one set of rules to remember :)

15:12 taylan: in a way it also seems simpler though; in the past I found myself confusing library-compile-time from library-load-time in Scheme

15:12 heh, exactly

15:12 justin_smith: it's just that we are used to other compilers having two behaviors (the compile and load behaviors) and clojure only has the one

15:13 taylan: I didn't know of compilers having a load behavior at all to be honest

15:13 Bronsa: taylan: clojure evaluation strategy during compilation is the same as it would be if you were runnig each form at the repl

15:13 justin_smith: taylan: this is the root of why eg. stuartsierra/component is so popular

15:13 taylan: Bronsa: and then it serializes the resulting process state?

15:13 Bronsa: taylan: I think CL works this way too

15:13 justin_smith: taylan: it offers the sort of deferred behaviors you might want, with very sane defaults and a lot of control

15:14 Bronsa: taylan: no, a top-level is executed both at compile time and at load-time

15:14 taylan: oh...

15:14 Bronsa: taylan: note that doing actual AOT compilation in clojure is not that common

15:15 taylan: I see

15:15 * taylan looks into stuartsierra/component

16:01 sveri: Hi, how can I define a prismatic schema for "def"?

16:16 sdegutis: How do you prefer to write CSS when you're doing a Reagent project? Do you use Garden?

16:18 justin_smith: sdegutis: best practice is to make someone else do all the CSS by pretending you don't understand it at all

16:19 sdegutis: In my case it isn't pretending, my CSS skills are not the best. ;P

16:19 But I'm the only guy, so I have to do it. I was hoping the scene had improved ever since those older days where everything was new?

16:20 I see Mesh now too..

16:25 https://github.com/facjure/mesh

16:26 justin_smith: sdegutis: mesh looks interesting

16:26 sdegutis: I'm not sure I'd use it though because I've heard you should always roll your own responsive stuff.

16:29 justin_smith: sdegutis: is that the "build your own light saber" of the frontend world?

16:29 sdegutis: Oh nice. Sick reference bro. Everyone knows your references are out of control.

16:30 justin_smith: sdegutis: I have some rare pepes too

16:35 sdegutis: Also Gardener https://github.com/facjure/gardener

16:36 noncom|2: so, what's mesh

16:36 sdegutis: responsive grid for clojure

16:36 noncom|2: responsive to what?

16:36 sdegutis: web scale

16:36 justin_smith: noncom|2: if you don't know what "responsive" is, just be happy, and you don't want any more information

16:36 sobel: (view scale)

16:37 (inc justin_smith)

16:37 justin_smith: noncom|2: any more info will just torture your soul

16:37 sdegutis: (inc sobel)

16:37 sobel: ,(inc justin_smith)

16:37 clojurebot: #error {\n :cause "Unable to resolve symbol: justin_smith in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: justin_smith 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:...

16:37 sobel: oh well

16:37 justin_smith: sobel: the bot that does karma is on vacation

16:37 noncom|2: heh, when sdegutis said "web scale" i thought of something running multiple nodes, like distributed responsive system

16:38 sdegutis: yes, I was intentionally *ever so slightly* ambiguous

16:38 just in case.

16:38 justin_smith: noncom|2: if only, that would actually be interesting

16:38 sobel: port your front end to mongodb

16:38 sdegutis: websql

16:38 you mean websql

16:39 sobel: the original web scale joke i knew was around mongodb

16:39 sdegutis: oh yes very good

16:39 justin_smith: help, my web-server is mutating, and is now covered in web-scales, and its attacking innocent ops people in its web-tentacles and devouring them whole

16:39 sdegutis: my memes are out of date, my apologies

16:39 sobel: hehe

16:40 sdegutis: i only recently learned of kid at computer nodding head and giving thumbs up

16:40 emdashcomma: if you get behind enough on memes you will become up to date again

16:40 eventually

16:40 justin_smith: sdegutis: new hotness: http://i.imgur.com/55feAT3.gif

16:40 noncom|2: overflow?

16:41 sdegutis: btw i mean this guy http://www.reactiongifs.us/wp-content/uploads/2014/03/brent_rambo_still_approves.gif

16:42 but younger

16:42 justin_smith: oh wow keeper

16:43 justin_smith: sdegutis: proper usage "i m code monkey af rn <gif>"

16:43 sdegutis: lol

17:09 justin_smith: Do you usually call (d/create-database) at the beginning of every process, even though it usually returns false?

17:09 justin_smith: sdegutis: I haven't done much with datomic - I experimented but the project did not go far

17:09 sdegutis: ok

17:13 sobel: i don't get what datomic offers over relational storage

17:14 sdegutis: sobel: it is relational storage

17:15 sobel: it's a middle-ground between sql and nosql in terms of flexibility

17:15 sobel: is it more than relational storage?

17:15 sdegutis: sobel: it's a layer on top of relational storage

17:15 sobel: an extremely handy convenience layer

17:15 sobel: pgsql alreadp gives some middle ground in that way but i understand i could run datomic on top of pg, among others

17:16 sdegutis: writing datomic queries is really pleasant and easy compared to writing sql queries in my experience

17:16 sobel: i'm already really solid with sql

17:16 sdegutis: sobel: and in datomic, queries run in your app, rather than in the database, and there's no blocking

17:17 sobel: what's the concurrency model?

17:35 nefigcas: Hi!!

17:36 There is anybody here??

17:36 mungojelly: nefigcas: kinda

17:36 nefigcas: :D

17:36 justin_smith: sobel: it keeps a cached db, and until you need a new "state", it simply uses the immutable cached db state

17:38 nefigcas: I'm trying come code but it have an weird behavior, Its using Overtone OSC

17:39 I'm mapping(Using map) some code for handlers (kinda listeners)

17:39 justin_smith: nefigcas: you can go ahead and describe your problem, and if you stay logged in eventually someone is likely to help - if you need to share code or errors, put them on a site like refheap.com and share the link here

17:39 xcv: Have any of you guys been using Pulsar?

17:39 nefigcas: But I'm almost shure the thing is not clojure but my understanding of it

17:40 xcv: Looks like an interesting library.

17:40 nefigcas: OK

17:40 mungojelly: nefigcas: map is lazy so if you need the side effects you might want "run!" justin_smith taught me that recently :)

17:41 nefigcas: That sounds like my problem, checking...

17:41 ;)

17:43 dorun

17:43 ??

17:43 clojurebot: CLABANGO!

17:43 nefigcas: :D

17:43 justin_smith: nefigcas: dorun can wrap map, but run! replaces map directly

17:43 ,(doc run!)

17:44 clojurebot: "([proc coll]); Runs the supplied procedure (via reduce), for purposes of side effects, on successive items in the collection. Returns nil"

17:44 justin_smith: ,(run! println (range 10))

17:44 clojurebot: 0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n

17:46 nefigcas: CompilerException java.lang.RuntimeException: Unable to resolve symbol: run!

17:46 :(

17:47 justin_smith: nefigcas: need clojure 1.7 for that

17:47 nefigcas: Ok, ok

17:47 justin_smith: forgot to mention. But clojure is really good about backward compat, you really don't have much reason not to upgrade.

17:47 or at least try

17:48 nefigcas: Thanks!!

17:49 I was breaking my head with that ;), the code works in the REPL, the REPL is anti-lazy?

17:50 justin_smith: nefigcas: printing forces laziness - rePl

17:51 rhg135: mapv, but the overhead

17:51 justin_smith: ,(do (map println ["hello" "world"]) nil) ; no print, no side effect, thanks to do/nil

17:51 clojurebot: nil

17:51 justin_smith: rhg135: which is why run! is great

17:52 rhg135: yeah, I mean on archaic versions

17:55 usere refusing to upgrade has led to far too many sleepless nights

17:55 users*

17:59 or, (reduce #(do (f %2) %1) nil teh-coll)

17:59 justin_smith: ,(source run!)

17:59 clojurebot: Source not found\n

17:59 justin_smith: rhg135: anyway, that's pretty much what run! is

18:00 rhg135: yup

18:00 justin_smith: (reduce #(proc %2) nil coll)

18:02 rhg135: run! always returns nil though

18:02 justin_smith: ,(run! inc (range 10))

18:02 clojurebot: nil

18:03 justin_smith: rhg135: oh weird, in my older clojure 1.7, (where the source is as I pasted above), it returns the last item

18:04 rhg135: ah

18:17 gfredericks: isn't there a build tool (lein plugin?) for copying dependencies into your project & renaming its namespaces?

18:17 not very easy to google

18:18 justin_smith: gfredericks: sounds like something you could hack together with slamhound...

18:18 rhg135: Sounds buggy

18:18 gfredericks: I've seen bizarre namespaces from such a tool in my deps before

18:18 so it *must* exist

18:19 I guess it's not a whole lot harder to fork and manually rename the namespaces myself, since it's a one-off

18:22 justin_smith: gfredericks: anyway, slamhound would probably make it easier to engulf, appropriate, and extend a victim project

18:23 numberten: is there a core function that applies a function to each top level value in a map?

18:24 rhg135: is this not the packet managers job? but lein does package the project.clj

18:24 map

18:24 justin_smith: numberten: map

18:24 numberten: map turns each key-value to a pair right?

18:24 and applies the function to the pair?

18:24 rhg135: yeah

18:24 justin_smith: numberten: entries in maps are pairs

18:25 it doesn't "turn them into" anything

18:25 numberten: I want something like: (my-map inc {:a 1 :b 2}) => {:a 2 :b 3}

18:25 justin_smith: specifically they are two element vectors

18:25 rhg135: plumbing has map-val

18:26 uses reduce

18:26 numberten: yeah just seemed like it would be commonly used, so was curious if there was a core impl

18:26 justin_smith: yeah, there's also reduce-kv - laziness and hash-maps are like toothpaste and orange juice

18:26 numberten: w/o me writing it with a reduce

18:28 rhg135: why does reduce-kv even excist?

18:28 numberten: (defn my-map [f m] (reduce-kv #(assoc %1 %2 (f %3)) {} m))

18:29 that's actually not bad at all

18:29 rhg135: destructuring

18:29 justin_smith: destructuring?

18:29 clojurebot: destructuring is http://clojure.org/special_forms#binding-forms

18:30 justin_smith: destructuring???

18:30 rhg135: performance perhaps?

18:30 amalloy: reduce-kv exists because you can avoid allocating a bunch of [k v] pairs, compared to (reduce (fn [acc [k v]] ...) ...)

18:30 rhg135: thought so

18:33 That sounds like a good optimiztion for t.a

18:39 gfredericks: you could open the jar of a dep that does so and check if it is using a plugin

19:21 sdegutis: justin_smith: huh, seems like I don't need component after all, considering all my components except one (web server) dont have start/stop because they're idempotent

19:22 justin_smith: well, that's super nifty

19:22 not even db connection?

19:22 sdegutis: right, datomic is idempotent

19:22 justin_smith: and no bugs from it trying to connect while building your uberjar?

19:22 sdegutis: it doesnt try to connect until you first access the database

19:22 at which point it opens up a long running connection

19:23 justin_smith: sweet

19:23 sdegutis: yeah this rocks

19:23 totally psyched

19:26 bbl

19:45 justin_smith: ,(clojure.string/split "Wat" #"[ -_]")

19:45 clojurebot: ["" "at"]

19:45 justin_smith: ^^^

19:47 ,(clojure.string/split "Wat" #"[ \-_]")

19:47 clojurebot: ["Wat"]

19:48 emdashcomma: (let [u m8] (what? u))

20:04 puta: In Hiccup how can I add a title option to a generated list of options? This doesn't work: (defn menu [title start end] (do [:option {:value ""} title] (for [i (range start end)] [:option i])))

20:05 More specifically, in function context. It's simple declaratively.

20:12 nogden: If I implement a protocol in (defrecord) should I be able to call other methods of the same protocol from within my implementation?

20:13 rhg135: yesish

20:14 nogden: I keep getting an unresolved symbol error for the protocol function that I want to call.

20:15 rhg135: weird, since it's defined by (defprotocol ...)

20:15 nogden: Yeah, I figured I could just call it and pass on 'this' and I'd be golden.

20:17 Ah, bingo. You still have to require the individual methods rather than just the protocol.

20:18 Thanks, talking things through always helps ;-)

20:18 rhg135: oh, I assumed same ns

20:19 nogden: Fair assumption, I wasn't clear.

20:44 WickedShell: I'm experiencing a problem with lein that I can't seem to track down. lein repl and lein run both work but lein uberjar stalls and never seems to finish

20:45 Anyone ever experienced this before?

21:05 mmitchell: Thinking about building a JS client lib for an API using cljs. Then I thought, maybe I could use the same code to build a js, cljs, clj, js AND java client with the same core. Would this be possible?

21:06 I'd imagine clj and java would use the same "http adapter", while the cljs and JS would use a JS version?

21:16 amalloy: WickedShell: you probably have some side effects at the top level of your namespace, like starting up a server, which never completes

21:17 WickedShell: amalloy, is there a technique for chasing those down? There's some go's etc that get spawned off, but that's always been happening, so I'm having trouble finding the change

21:17 amalloy: those shouldn't happen either

21:17 nothing should happen that isn't triggered by -main

21:19 WickedShell: Hm... Well that raises the question of how I've been completing uberjar's in the past, but nicely puts to rest my suspicion that I should move where I spin up some of these go's etc

21:21 amalloy: well it's often harmless, but it's never good

21:26 WickedShell: well that's why I had ignored it, but somehow breaking the jar building is awful :)

21:32 rritoch: Does clojurescript have it's own channel?

21:36 sobel: at least one

21:36 WickedShell: Is the ^:const metadata supported/worthwhile (for constants used in math functions)? I have a fairly tight inner loop that is extremely perfromance bound on my lower end target device

21:37 sobel: rritoch: but it's often a good start to try questions here

21:40 rritoch: sobel: Ok, well I'm looking at cljs-bootstrap, but basically I'd like to bootstrap clojure scripts via AJAX. In a tomcat environment updating scripts/resources typically requires restarting the instance (souch as touching web.xml) which is a less than ideal development environment. Using AJAX I could create a web service which delivers the most up to date code.

21:41 souch=such

21:41 amalloy: WickedShell: (def ^:const x (+ 1 1)) will evaluate (+ 1 1), getting 2, and then replace x with 2 every time x is used, as if you had typed 2 to begin with

21:42 WickedShell: (def ^:const x 256) (+ x foo) where foo is something passed in at runtime wont see any benefit then? (just to confirm)

21:42 rritoch: I noted that cljs-bootstrap hasn't been updated in 2 months, and doesn't support macros. Is there some other project which is more capable?

21:50 If not, is clojurescript modular, such as being able to deliver namespaces as seperate javascripts (main.cljs.js , draganddrop.cljs.js, etc). If that's possible than it seems I could compile server-side in real time to achieve a comparable effect.

21:51 amalloy: no

22:05 heow: any starving students need a place to crash at the philly conj, ping me

22:12 rritoch: Would it be fair to say clojurescript is best suited for single page applications, since it isn't modular?

23:03 WickedShell: Has anyone here experimented with the skummet compilier at all? I tried swapping my project to it, but seem to be encountering compilation problems that I don't know how to solve at all. (they are occuring outside my code, and in a library somewhere) http://pastebin.com/etqa9u93 (this is with lein-skummet targeting the JVM with Java 8)

23:05 amalloy: you don't have a namespace named pushback-stream?

23:05 no, i guess not

23:07 WickedShell: No I don't, its somewher in a library or core

23:08 The exact same code was launching with lein repl before swapping to skummet

23:08 Seylerius: Weird. I can't seem to get clj-barcode to load properly in the Gorilla REPL.

23:09 https://github.com/nmquirk/clj-barcode

23:10 https://clojars.org/clj-barcode

23:12 amalloy: skummet certainly doesn't promise to work with all valid clojure code. there is certainly some it can't handle. i don't know if that's the case you're running into

23:13 WickedShell: amalloy, I suspect that's the case, but thought I'd enquire if anyone had encountered it before. I just have one target device that performance is a real problem on. (Not really clojure's fault, its just weak hardware)

23:17 Seylerius: amalloy: D'you have a minute to take a look at https://clojars.org/clj-barcode and see if you can get it to load into a REPL? I can't manage to make it go.

23:18 I don't know why.

23:18 Ah, nevermind.

23:19 Found it.

23:19 Needed clj-barcode.core, rather than clj-barcode.

Logging service provided by n01se.net