#clojure log - Apr 06 2013

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

0:04 tieTYT2: i'm trying to save a data type to a file but when I (spit) it it only outputs clojure.lang.LazySeq@2cd9e23b

0:05 how do I output the whoel thing so I can read it back into my repl for debugging

0:06 mthvedt: tieTYT2: stick it into a readable data structure, like a vector

0:07 akhudek: tieTYT: pr-str

0:07 tieTYT2: cool

0:08 thanks

0:08 bbloom: that's no good either

0:08 just call seq on it

0:08 pr-str will realize the full value into a string in memory

0:08 spit will internally print directly to the writer, so the whole data structure doesn't need to be realized

0:09 akhudek: bbloom: but spit won't serialize right?

0:09 bbloom: ,(str (clojure.lang.LazySeq (fn [] ["I" "am" "the" "thunk"]))

0:09 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading>

0:09 bbloom: ,(str (clojure.lang.LazySeq (fn [] ["I" "am" "the" "thunk"])))

0:09 clojurebot: #<ClassCastException java.lang.ClassCastException: java.lang.Class cannot be cast to clojure.lang.IFn>

0:09 bbloom: ,(str (clojure.lang.LazySeq. (fn [] ["I" "am" "the" "thunk"])))

0:09 clojurebot: "clojure.lang.LazySeq@726f771"

0:09 bbloom: ,(str (seq (clojure.lang.LazySeq. (fn [] ["I" "am" "the" "thunk"]))))

0:09 clojurebot: "(\"I\" \"am\" \"the\" \"thunk\")"

0:09 bbloom: akhudek: spit will serialize

0:09 akhudek: but it won't hold on to the head

0:10 akhudek: so if you have a lazy process that you want to stream to a file, you can walk the lazy structure as you print it, so you won't run out of memory if the full structure is too large

0:10 akhudek: which is what will happen if you call vec

0:10 akhudek: but will happen twice as fast if you call pr-str

0:10 tieTYT2: in this situation i won't run out of memory regardless

0:11 bbloom: tieTYT2: well either way, just (spit writer (seq the-lazy-seq))

0:11 tieTYT2: ok

0:11 akhudek: bbloom: interesting, I didn't know that

0:12 I might have to refactor some code to be a bit more memory efficient.

0:12 bbloom: akhudek: oh nevermind

0:12 i'm wrong.

0:12 lol

0:12 sorry

0:12 just looked at the source of spit

0:12 akhudek: oh :-(

0:12 and here I got excited

0:12 bbloom: spit just calls (str)... *sigh*

0:12 tieTYT2: i'm reading it back in like this: (def i (read-string (slurp "out.html")))

0:13 bbloom: spit isn't a very clever function....

0:13 sorry about that, my bad.

0:13 tieTYT2: hrm

0:13 akhudek: tieTYT2: turns out you do need to use pr-string, then that should work for reading it back in

0:13 err pr-str

0:13 tieTYT2: really, the issue I'm having is a debugging issue

0:13 i've written some code that works like a spider that crawls a webpage

0:13 I'm getting an error about IllegalArgumentException No value supplied for key

0:13 and I can't even be sure of which line it's outputting that on

0:14 it shows me the map after that error and it looks fine to me

0:14 if I copy it and paste it back into the repl with a ' in front of it it gives me no error

0:15 akhudek: tieTYT2: hard to help without seeing code :-/

0:15 howdynihao: ((fn [x] (conj [x] 1)) 2) am i understanding this right? first x is setting the argument to x

0:16 second x is creating a vector with x

0:16 seems unfortunate they both appear the same? or are both actually vectors?

0:16 tieTYT2: ok first of all this is the error: IllegalArgumentException No value supplied for key: {:post-link "http://site.com/index.php?topic=1987109.0", :image-links ("http://site.com/index.php?action=dlattach;topic=1987109.0;attach=6181834;image" "http://site.com/index.php?action=dlattach;topic=1987109.0;attach=6181836;image")} clojure.lang.PersistentHashMap.createWithCheck (PersistentHashMap.java:89)

0:17 and my code is like a 100 lines. How do I know which code to show you?

0:17 akhudek: howdynihao: they are both actually vectors, the first is simply used internally for argument bindings

0:19 tieTYT2: oh i get it, it's saying that whole thing is one key?

0:19 that makes it easier to debug

0:19 akhudek: tieTYT2: what is the stack trace?

0:19 yes

0:19 tieTYT2: it doesn't show me one

0:19 unless I do (pst)

0:19 which doens't have useful line numbers

0:19 I'm using Counter Clock Wise

0:19 akhudek: (e) doesn't work?

0:20 tieTYT2: CompilerException java.lang.RuntimeException: Unable to resolve symbol: e in this context, compiling:(NO_SOURCE_PATH:1)

0:20 akhudek: if you aren't getting line numbers, reload the namespace as a file

0:20 not sure what the CC command for this is

0:20 tieTYT2: the stack trace is one line

0:21 anyway, I think I can fix the problem at hand at least

0:21 i didn't know that I was supposed to get better stack traces than I am

0:21 the output is exactly what I pasted earlier including the "full" stack trace it gives me

0:22 akhudek: tieTYT2:if you require [clojure.stacktrace :refer [e]] in you namespace, you should then be able to do (e) right after an error on the repl and get a decent stack trace most of the time.

0:22 Also, always try to reload whole namespaces when possible, I believe that way it gives you line numbers.

0:23 tieTYT2: java.lang.ClassNotFoundException: clojure.stacktrace

0:24 ok i reloaded the namespace

0:24 err, switched to it

0:24 and then that worked

0:24 thanks

0:25 ok that worked

0:25 now I can debug my program

0:25 wtf doesn't CCW automatically include that in the repl?

0:26 akhudek: guess it doesn't want to inject unwanted things into peoples programs, though it is quite a useful library!

0:27 tieTYT2: yeah, it doesn't have (doc) or (source) either. Quite annoying

0:27 thanks

0:29 howdynihao: i have trouble understanding this, ((fn foo [x] (when (> x 0) (conj (foo (dec x)) x))) 5)) if someone could explain it to me? the part that i dont get is...

0:30 is the return, i would think it would keep returning a function ?

0:30 so it seems like it should be ( 5 1) as the result not ( 5 4 3 2 1) ?

0:31 egghead: why do you think it would return a function howdynihao ?

0:32 the only place it can exit is from 'conj'

0:33 howdynihao: well maybe not return a function, but i would think it would keep calling foo until it gets a result

0:33 so i understand how it could return 4 3 2 AND still keep calling foo

0:33 i dont understand i mean

0:33 egghead: so what happens is the other way around, there is some initial call to (conj (something...) onto x)

0:34 and that something travels down further, until eventually the condition is no longer true because x is 0

0:35 so when x is 0 the when doesn't get satisfied, so you get nil back, but what that means is that you haved (conj (conj (something...) x) nil)

0:36 howdynihao: ok so something is actually (4 3 2 1) ? and it isn't conjoining 5 times ?

0:36 well i still dont understand really why the values return

0:37 like in recursive functions in other languages, you get the last calls return and it bubbles up to the initial call

0:37 egghead: if you change 5 to 2 for instance: you might imagine the call stack as (conj (conj nil 1) 2)

0:39 it is doing that tho, it follows down until (foo n) returns a value instead of a new call

0:39 and that percolates back up until the very first call to conj has all it's parameters resolved

0:39 since it's call by value

0:42 howdynihao: ahhhh ok now i get it, maybe its the parenthesis :P tripping me up

0:44 egghead: cheers howdynihao

1:05 tieTYT2: i just had a huge debugging session... does anyone know, if I define something in the repl, and then I compile a file in CCW that refers that definition but doesn't define it anywhere, should it give me a compile error?

1:43 rads: has anyone gotten the clojurescript brepl to work with node-webkit?

1:43 I'm getting this: Uncaught Error: URI file:/robots.txt is invalid for field ppu

1:43 seems like a cross domain security problem

1:45 a|i: any serious clojure based rules engine out there?

2:04 rads: ibdknox: just looked at the source for lighttable and didn't find anything to set up a repl. do you use the browser repl with node-webkit?

2:45 tieTYT2: how can I do something like map, but only on the odd or even elements?

2:45 but I don't want to filter it down

2:47 bbloom: tieTYT2: two main choices

2:47 1) map-indexed where you conditionally transform based on (even? index)

2:48 2) interleave two calls to take-nth, one mapped, and one next-ed

2:48 tieTYT2: hrm, 1) seems easier to me

2:48 i'll do that, thanks

2:50 bbloom: ,(let [v [:a :b :c :d]] (interleave (map name (take-nth 2 v)) (take-nth 2 (next v))))

2:50 clojurebot: ("a" :b "c" :d)

2:50 bbloom: 2 is pretty easy too :-)

2:51 ,(map-indexed (fn [i x] (if (even? i) (name x) x)) [:a :b :c :d])

2:51 clojurebot: ("a" :b "c" :d)

2:53 Raynes: bbloom: It's a party in the USA.

2:53 bbloom: Raynes: ?

2:54 Raynes: bbloom: I was listening to that song (for scientific purposes, I assure you) and needed to tell somebody.

2:55 bbloom: Raynes: i'm glad you can confide in me, but i have no idea what that song is

2:55 Raynes: bbloom: http://www.youtube.com/watch?v=M11SvDtPBhA

2:55 The worst thing ever.

2:56 * bbloom clicks, sees artist name, cmd+w

2:57 Raynes: bbloom: I was toying with a bot that checks my last.fm and gives me a hipster percentage. I am currently 94.69% mainstream. I'm trying to raise this number by listening to more mainstream things.

3:10 I need a trendy place to buy coffee mugs.

3:13 bbloom: Best coffee mug I ever used cost me 4 dollars at a Safeway

3:14 Raynes: I looked at mugs at Target but didn't want to pay $20 for a coffee mug.

3:14 I'm looking on Amazon, but I'm not sure I want a mug that says "COFFEE MAKES ME POOP" and/or looks like a toilet.

3:14 http://www.amazon.com/Big-Mouth-Toys-Toilet-Mug/dp/B002SQG4TU/ref=sr_1_10?ie=UTF8&qid=1365232495&sr=8-10&keywords=coffee+mug

3:14 bbloom: lol

3:15 you a 1 cup am and 1 cup pm sorta guy?

3:15 or you more of a thermos all day long sorta man

3:16 Raynes: I'm a 1 cup AM because I never sleep kind of guy who hates himself because he tries to avoid caffeine.

3:17 bbloom: yeah, you just need a plain old white cup. i prefer vertical sides, since they have a wider base & are steadier

3:22 arcatan: have a smaller cup, so you'll have less coffee and less caffeine

3:31 Raynes: bbloom: http://www.amazon.com/Dr-Who-Disappearing-Tardis-mug/dp/B003Z31K7G/ref=sr_1_9?s=home-garden&ie=UTF8&qid=1365233306&sr=1-9&keywords=mug This is what I need.

4:04 ddellacosta: I can't get ring 1.2.0-beta2 working with lein-ring: ring-server is bringing in 1.1.8 and my exclusions aren't "taking." Anyone have a fix?

4:10 borkdude: is there a way to debug routes in compojure/ring to see which route actually gets fired by a request?

4:28 yogthos I'm trying to add resources from webjars to a luminus project, but somehow now the "/" GET requests responds with a blank page - any ideas?

4:29 yogthos I added this line under ;;add your middlewares here: (resource/wrap-resource "/META-INF/resources/")

4:30 yogthos one solution would be to just copy the resources to the normal resources folder, but I want to find out what's going on

5:15 murtaza52: What does the refer key do ex - (:require [abc.core :refer :all])

5:16 borkdude: murtaza52 it does the same as :use :only

5:16 murtaza52 or in this case :use

5:17 murtaza52: so if I have (:require [abc.core :refer xyz])

5:18 borkdude: does this mean that xyz is a function which is being imported in the current ns, just like :only

5:18 borkdude: (:require [abc.core :refer [fn1 fn2]])

5:18 yes

5:41 murtaza52: borkude: so what is the diff of using :use and :only compared to :require and :refer

5:54 borkdude: murtaza52 no difference

5:54 I think I found out what's going wrong with my routes and webjars:

5:55 https://www.refheap.com/paste/13317

5:56 the jar directory gets recognized as a resource, but not as a file, hence it is returned as (io/input-stream resource) hm

5:58 the protocol = jar

6:09 faust45: hi guys

6:09 just have a problem

6:09 i try create class with (gen-class ...)

6:10 then (compile it in REPL

6:10 and its success

6:10 but how i can load this class to REPL

6:10 please help me

6:20 jemafeller: hello

6:20 what would be the best way to expose a high performance service with RPC to a node.js (or any server side) service?

6:20 jjl`: that depends what you need

6:26 jemafeller: jjl`, well, I'd like the code being executed to be as high performance as possible

6:26 this is because it was supposed to be the same process, and the same codebase but was split into two

6:27 it may also be that the two processes may live on the same machine, so that they could use pipes - but that is not guaranteed

6:28 on paper, zeromq looks to be answering all of these as it is a 'fancy' socket that can transparently switch between TCP/in-proc/etc

6:28 but I'm aware of a lot of gripe with it and JVM based code

6:28 jjl`: well you've got three basic models for services which comes down to two questions: do i need an answer and do i need it now?

6:29 jemafeller: yes to both

6:29 I also looked at Thrift, but there's a lot of criticism about complexity of connection handling and error handling with Thrift

6:29 jjl`: thrift was a nightmare when i worked with it

6:30 zeromq probably isn't going to be your solution if you want an answer immediately

6:31 have you considered XMPP? not the most efficient in terms of size of messages, but can be very low latency

6:32 jemafeller: I haven't actually. I'll throw in another thing though - the messages are big.

6:33 they can go into 100kb in size, since it is a document that's passed between services

6:33 it's online document analysis, part of it is done in service A, and part of it in service B

6:34 so I think XMPP wasn't built to handle big messages..?

6:34 and to be truthful, I don't want to build the RPC server myself (so here Thrift has an advantage - but yes, i do keep reading about Thrift nightmares)

6:36 jjl`: XMPP can be made to handle big messages but it isn't designed for it

6:38 mpenet: Did you consider the java port of 0mq? I am not sure what you were refering to it earlier.

6:38 jemafeller: mpenet, you mean jeromq? no I didn't.. I'm not sure what to think about it

6:39 mpenet: Yes, well it seems young, and I never used it, so I can't really vouch for it, but it seems like an option

6:40 jemafeller: i'm wondering about ProtocolBuffers though.. i'll need to find a way to implement the RPC daemon myself in Clojure

6:40 mpenet: but 0mq should be quite reliable anyway, I think Storm uses it internaly, it could be worth have a look there too.

6:42 alex_baranosky: does anyone know offhand how big the thread pool is for futures is?

6:42 jemafeller: mpenet, yes they do. and that's where I understood they have problems with it when it comes to Java and maintainability

6:43 https://github.com/nathanmarz/storm/issues/372

6:44 Glenjamin: jemafeller: i'd vote json over rabbitMQ

6:44 but it depends on your definition of high performance in this case

6:44 mpenet: interesting

6:44 jemafeller: Glenjamin, the solution would need to be synchronous and immediate. i'd like to be as close to in-proc as possible

6:45 Glenjamin: probably want something binary over http then?

6:45 msgpack / thrift etc

6:45 s/http/tcp

6:45 mpenet: alex_baranosky: I think it's an cachedThreadPool

6:45 jemafeller: Glenjamin, yes. that would be a reasonable solution - since I also don't want to prematurely optimize

6:46 jjl`: also think about whether you're more likely to be network or cpu bound

6:46 Glenjamin: throw together a couple of options and benchmark i guess?

6:46 alex_baranosky: mpenet: googling seems to suggest it is an unbounded thread pool, unless that has changed since these blogs were written

6:46 jemafeller: Glenjamin, but, i'm not so much experienced with Thrift and Java and heard a lot of bad experiences there

6:46 mpenet: alex_baranosky: yes

6:47 jjl`: the packets are large, so maybe it'll be network bound, but then what are the documents? do they have a native format?

6:47 Glenjamin: maybe start with json over tcp and leave the serialisation format malleable?

6:47 jemafeller: jjl`, the process doing the work behind RPC is completely CPU bound, it's a text analysis algorithm suite.

6:47 jjl`: maybe the overhead isn't going to be that large

6:47 mpenet: alex_baranosky: I have future-call and future versions that allow to use your own executors in mpenet/knit

6:47 jjl`: in which case, do minimal cpu processing and make sure the network can handle it

6:47 jemafeller: jjl`, the documents are just text. imagine a Service A -[text]-> Service B

6:47 mpenet: alex_baranosky: but their code is probably a bit outdated compared to 1.5.1, but it could give you an idea on how to proceed if you need to make your own

6:48 jjl`: jemafeller: given the docs are so large, go for a simple protocol that requires minimal cpu to process and throw it onto the network

6:48 jemafeller: jjl`, you're right, I think network bandwidth could be a problem in this case

6:48 jjl`: then your solution is wrong

6:49 parallelise the backend service so cpu isn't a concern

6:49 but if network bandwidth will be a problem sending large documents, then a small protocol won't help - the docs are large

6:49 can't you get a fibre connect in?

6:50 jemafeller: yep.. i'm thinking about that

6:50 mpenet: alex_baranosky: also fyi the threadpool used by futures is the same agents use

6:51 unless you use send-via of course

6:55 jemafeller: hmm i think i'll go by this priority - msgpack-rpc, protobuf-rpc, and then plain HTTP if none of these work

8:28 john2x: can I not require goog.x libraries in the clojurescript repl? if so, how to do?

8:43 chessguy: good mooooorning clojure world!

9:21 kmicu: Ten sam chrome, który był na webkitice tak jak safari?

9:22 * kmicu should change shortcuts in weechat ;]

9:38 borkdude: https://www.refheap.com/paste/13332 <- reproduction of my webjars problem

10:31 juhu_chapa: Hi guys!

10:32 in order to use (javadoc Object) How can I set the default browser?

10:33 this at the REPL

10:34 borkdude: juhu_chapa I don't know, but isn't this just the default system browser?

10:35 juhu_chapa: borkdude: I am on BSD, do you refer to an OS environment variable?

10:36 borkdude: juhu_chapa I have googled it for you: http://forums.freebsd.org/showthread.php?t=19829 - I don't know much about BSD

10:37 juhu_chapa: borkdude: Thank you!

10:38 borkdude: juhu_chapa no problem, googling for other people is what I do

10:38 :P

10:39 juhu_chapa: ;)

10:49 chessguy: how do folks usually handle a tdd cycle in emacs with nrepl? i'm finding myself repeatedly going to a shell and doing 'lein test'

10:52 ucb: chessguy: you can try https://github.com/stuartsierra/lazytest

10:52 chessguy: additionally, if you're using midje for testing there's midje-mode and lazytest via midje too

10:53 chessguy: ucb: i'll probably use midje eventually, but i've never done tdd in clojure before, so i feel like i ought to start from scratch

10:53 ucb: chessguy: surely TDD is not necessarily about the testing lib?

10:54 chessguy: ucb: i'm not learning TDD, i'm learning testing in clojure

10:54 i just want to know the standard library first

10:54 ucb: chessguy: oh, I see.

10:58 chessguy: hmm. what we really need is something like guard for clojure

10:59 headshot: erlang anyone?

10:59 ucb: chessguy: that's what lazytest does (from my brief reading about https://github.com/guard/guard-test)

11:01 chessguy: ucb: maybe i'll try that, thanks

11:01 ucb: chessguy: no worries

11:10 yogthos: dnolen: hello? :)

11:12 is anybody versed in cljs magic?

11:16 dnolen: yogthos: what's up?

11:17 yogthos: dnolen: oh I ran into advanced optimizations problem, but I think I know what's happened

11:17 dnolen: ok

11:17 yogthos: dnolen: stuff was using this https://github.com/chengyin/albumcolors

11:18 and it works fine without optimizations, but when I turn advanced on it gets errors that it can't find a method on the object

11:18 so from what I gathered is names get munged?

11:19 so I have to protect them explicitly with externs?

11:20 dnolen: does that sound right?

11:20 the errors I get look like Uncaught TypeError: Object [object Object] has no method 'Le'

11:21 and the code in question is

11:21 (defn set-colors [div]

11:21 (.getColors (js/AlbumColors. (img-url div))

11:21 (fn [[background _ foreground]]

11:21 (set-color (.-style div) foreground background))))

11:21 calling (.getColors is what's causing it

11:25 chessguy: looks like lazytest is pretty old. seems to be insisting on an outdated convention for file locations

11:26 lfranchi: hey guys! i'm trying to migrate my clojure usage to emacs+nrepl (and am a relative newcomer to clojure) but am running into some weird behaviour that I don't understand w/ lamina and aleph.tcp. I have this very simple code that connects to a tcp server and prints out when the connection is established: https://gist.github.com/lfranchi/5326476 (in `lein repl`). I have the exact same code in emacs+nrepl started by `nrepl-jack-in`, and my on-realized

11:26 callback is not printing out / being called: https://gist.github.com/lfranchi/5326479.

11:26 i must be missing something really fundamental, but i'm not sure what

11:27 any tips would be really appreciated :)

11:27 juhu_chapa: How to list all global vars?

11:30 yogthos: dnolen: is there an example on how to use externs with cljsbuild?

11:32 dnolen: when I specify :externs ["externs.js"] is externs.js loaded in the browser at runtime or referenced during compilation?

11:33 dnolen: yogthos: no idea about cljsbuild extern support but I'm sure it does.

11:33 yogthos: and yes your issue sounds like an externs one

11:34 yogthos: dnolen: yeah looks like I'm making progress, I'm up to Uncaught TypeError: object is not a function when I reference externs.js in the page :)

11:34 dnolen: and I assume it's because I'm passing an anonymous function as an argument to a js function?

11:34 dnolen: yogthos: you might want to look at jayq, I believe jayq uses an externs and works via lein-cljsbuild

11:34 yogthos: dnolen: ah good idea

11:35 dnolen: it's all about finding that one example :) after that it's usually obvious in retrospect

11:37 murtaza52: I have a vector of fns and i want to get a subvector such that-> (subvec-fn [fn1 fn2 fn3] fn2) => [fn1] ; Is there such an inbuilt fn ?

11:41 chessguy: hm. i get an error when i M-x package-install clojure-test-mode

11:41 technomancy: you around, by any chance?

11:41 yogthos: dnolen: yup was the externs, thanks for pointing me to jayq works like a charm now :)

11:41 dnolen: murtaza52: why not just use take-while?

11:41 yogthos: sweet!

11:43 lfranchi: Hm, seems like my aleph connection is never even calling my on-realized callback, as throwing an exception in the fn is never hit :-/

11:43 chessguy: dnolen: i didn't know you hung out here. seen a couple of your talks on pattern-matching. awesome stuff, keep it up!

11:48 dnolen: chessguy: thx!

12:04 lfranchi: Hmm, can someone with a better idea of clojure/java logging explain why when I use (clojure.tools.logging/info "foo") in emacs+nrepl.el, nothing gets printed out, but when I do the same in `lein repl`, I get the proper info debug message?

12:05 this is after calling (org.apache.log4j.BasicConfigurator/configure)

12:39 clojure-new: Hello, i have a list of #inst dates, how can i sort it?

12:43 jonasen: clojure-new: (sort [#inst "2000" #inst "2013" #inst "1984"])

12:44 Okasu: , (sort [#inst "2000" #inst "2013" #inst "1984"])

12:44 clojurebot: #<SecurityException java.lang.SecurityException: denied>

12:45 clojure-new: It works, thanks!

14:01 jameshasselman: Getting this exception when calling my multi-method ArityException Wrong number of args (2) passed to: problemC$eval7100$fn clojure.lang.AFn.throwArity (AFn.java:437) What am I doing wrong here http://pastebin.com/ACgCaHFv ?

14:03 bbloom: jameshasselman: you're not destructuring the vector in your dispatch function

14:03 [[unit _]]

14:04 jameshasselman: oh sorry, misread

14:04 (value) isn't what you want

14:04 you jsut want value by itself

14:05 otherwise that's (10) or whatever

14:05 and numbers aren't callable

14:05 beyond that, you're probably expecting defmulti to redefine the dispatch fn, which, annoyingly, it won't do

14:06 so (ns-unmap *ns* 'unit-to-minutes)

14:06 then try again

14:10 jameshasselman: that worked, but I don't understand why

14:10 Thanks though, would not have figured that out.

14:37 SirLalala: hi! I solved this problem from project euler in clojure http://projecteuler.net/problem=11 . But I'm trying to minimize the code

14:44 how can I convert a vector like this [ [[1 2] [2 3]] [[3 4] [4 5]]] to [ [1 2] [2 3] [3 4] etc.

14:45 Okasu: ,(flatten [[2][3]])

14:45 clojurebot: (2 3)

14:52 eckroth: ,(apply concat [[[1 2] [2 3]] [[3 4] [4 5]]])

14:52 clojurebot: ([1 2] [2 3] [3 4] [4 5])

14:55 SirLalala: eckroth: awesome thanks!

14:57 danneu: nice

15:08 chessguy: ,(apply 'and '((3)))

15:08 clojurebot: nil

15:08 chessguy: can someone help me understand that?

15:08 i would expect that to evaluate to '(3)

15:09 eckroth: ,(apply 'foo '((3)))

15:09 clojurebot: nil

15:09 eckroth: ,(apply and '((3)))

15:09 clojurebot: #<CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compiling:(NO_SOURCE_PATH:0:0)>

15:10 eckroth: and is a macro, so it acts differently than you might expect

15:10 chessguy: (macroexpand '(apply and '((3))))

15:10 ,(macroexpand '(apply and '((3))))

15:10 clojurebot: (apply and (quote ((3))))

15:10 chessguy: bah

15:11 eckroth: ,(macroexpand '(and true false false true))

15:11 clojurebot: (let* [and__3965__auto__ true] (if and__3965__auto__ (clojure.core/and false false true) and__3965__auto__))

15:11 eckroth: kind of cool: does (if [first value] (and [2nd value] [3rd value] [4th value]) [first value])

15:12 like it's currying

15:12 chessguy: eckroth: right, but the first value here is '(3), no?

15:12 eckroth: ,(and '((3))

15:12 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading>

15:12 eckroth: ,(and '((3)))

15:12 clojurebot: ((3))

15:12 eckroth: apply does not work here because it's a macro

15:13 chessguy: am i going about this wrong? i have a sequence and i want to know if every element is truthy...

15:13 i could (every? 'id xs)

15:13 but that seems verbose

15:13 eckroth: was just going to suggest that

15:14 you can make a helper func that does (every? identity xs) but otherwise I don't know of a built-in

15:14 chessguy: really? wow

15:14 eckroth: mabye someone can tell use otherwise

15:15 chessguy: i suppose it's not really less verbose than apply all

15:15 eckroth: right and usually I find myself doing: (every? some-func original-xs)

15:15 where some-func is an interesting operation

15:15 so it's not a big loss

15:15 chessguy: sure

15:16 n_b: So I'm considering switching to emacs from vim, what's the easiest way to get started with that+clojure?

15:16 eckroth: using identity is a total code smell; I've used it but I feel weird

15:16 n_b: clojurebox maybe?

15:16 Okasu: n_b: Nrepl is a good thing.

15:17 chessguy: n_b: i used this gist just the other week to get started: https://gist.github.com/rkneufeld/5126926

15:19 n_b: chessguy: That looks great. I was a little unclear in my phrasing; I know Clojure, just not familiar with the emacs ecosystem at all

15:20 chessguy: n_b: ah, in that case, this is one of the few cases where i recommend starting by reading the documentation

15:22 n_b: chessguy: just `man emacs`?

15:22 chessguy: that is, open emacs and hit ctrl+h, then t

15:23 danneu: n_b: i switched to emacs from vim a few weeks ago.

15:25 chessguy: danneu: i'm curious how that went

15:27 danneu: chessguy: it was awesome.

15:28 chessguy: danneu: nice. i've tried a couple of times to add vim to my toolbelt, and struggled every time

15:28 danneu: note that i'm using Evil-mode

15:28 chessguy: danneu: is that like viper-mode?

15:28 danneu: yeah but much better apparently. they nailed it

15:28 n_b: I'm torn between having the conveniences of org-mode and non-hacky REPL integration and sticking with what I know and have fairly extensively customised

15:29 chessguy: danneu: nice

15:29 n_b: evil even has support for reading.vimrc IIRC

15:29 chessguy: n_b: what's that?

15:29 jameshasselman: does anyone use counterclockwise?

15:29 danneu: the .emacs of vim

15:30 jameshasselman: i did for a week before trying emacs. it wasnt bad and it was my first experience with an ide

15:30 chessguy: oh, sorry, the lack of space made my brain's parser fail

15:30 jameshasselman: I want to use it, but my breakpoints don't work. I need a debugger.

15:30 chessguy: jameshasselman: a debugger for clojure?

15:31 isn't that what the repl is for?

15:31 danneu: vim->emacs is really natural. you get to use vim (evil-mode) and really just learn some emacs platform specifics like how to navigate to files. but once you're in a file, you're back in vim. but emacs->vim is much different.

15:31 i imagine

15:31 chessguy: danneu: yeah, getting used to remembering what mode you're in requires building up muscle memory

15:31 jameshasselman: well yeah, but the stack traces I get (at least in counterclockwise) don't trace the problem back to my code. It's always some Java library.

15:32 chessguy: jameshasselman: yeah, that's true

15:32 danneu: is there a way to reverse stack traces? i'm tired of scrolling up..

15:32 chessguy: jameshasselman: i see that a lot in both the repl and lighttable

15:34 n_b: chessguy: the problem is when that memory carries over to other areas. I've submitted more than one form with :wq at the end >>

15:34 danneu: well, you should be using :x anyways

15:34 chessguy: n_b: haha

15:36 i've been switching back and forth between emacs and lighttable. neither one really scratches my itch

15:36 n_b: I didn't like LT at all

15:37 danneu: LT is good for getting started with Clojure imo. i think it's a good middleground between emacs+nrepl and a crappy embedded repl.

15:38 the former requiring an investment to set up and the latter just sucking.

15:43 n_b: rlwarp works with the default clj repl doesn't it?

15:46 chessguy: rlwarp? is that like rlwrap, but at faster-than-light speed?

15:47 sorry, i couldn't resist

15:48 andyfingerhut: n_b: I often use it on Mac OS X and Linux as "rlwrap java -cp clojure.jar clojure.main". I haven't had any problems.

15:49 n_b: But more often "lein repo" is what I want.

15:49 n_b: Grrr auto-correct. "lein repl"

15:49 chessguy: andyfingerhut: you mostly want that to get the project's dependencies?

15:50 andyfingerhut: chessguy: Yes, and it has a few other enhancements from reply like access to ClojureDocs examples.

15:50 n_b: Doesn't `rlwrap lein repl` work?

15:50 It should be transparent

15:51 andyfingerhut: n_b: I think it would be redundant. There is a kind of line-editing built into 'leon repl' already. Not sure if it is equivalent to or different from what rlwrap provides.

15:51 Must… figure… out… how… to … disable. auto-correct.

15:52 jameshasselman: well, found my problem. I just entered my function line by line into the repl and found the source of my problem. Turns out int does not do what I thought it did.

15:52 n_b: ,(doc int)

15:52 clojurebot: "([x]); Coerce to int"

15:53 jameshasselman: I did read the doc for it, but I stupidly thought it would work on a string like "3" and it doesn't. I wanted Integer/parseInt

15:54 chessguy: (int 3.0)

15:54 ,(int 3.0)

15:54 clojurebot: 3

15:54 chessguy: ,(int 3.9)

15:54 clojurebot: 3

15:55 andyfingerhut: n_b: One difference between rlwrap and reply: Ctrl-C aborts REPL with rlwrap. reply catches it, interrupts current processing, and gives you fresh REPL prompt. That is a win on reply's side in my book.

15:56 n_b: andyfingerhut: ahh, wasn't aware of that. I use VimClojure's REPL for 95% of my work and only ever really bust out into lein when I just want to test a few things or do some math

15:58 gfredericks: jameshasselman: yeah I think the thing that int is doing is a special jvm thing related to primitives

15:59 jameshasselman: Oh, so the bot will evaluate expressions. That's pretty cool.

15:59 n_b: annnnd learning emacs is getting pushed off to another time. I got stuck in M-x-ctrl-meta-bucky-shift-meta-colon-smiling-cat-face-add-random-bugs-every-time-you-type mode

15:59 number36: hi all i have very simple problem

15:59 if someone would be so kind to help me

16:00 i am trying to solve one problem on 4clojure.com in different way

16:00 but i dont know how can i put two IF-s in one function

16:00 n_b: jameshasselman: Yup. clojurebot responds to , and lazybot does inline stuff with ##(print 1)

16:00 lazybot: ⇒ 1nil

16:00 gfredericks: does nrepl and/or reply associate each clojure-mode buffer with anamespace

16:00 i.e., a value of *ns*?

16:01 n_b: number36: Which problem?

16:01 number36: https://www.refheap.com/paste/359b51eb1d9470da44a255881

16:01 and this is problem

16:01 http://www.4clojure.com/problem/73

16:01 jameshasselman: n_b: is it number 36

16:01 number36: :)

16:01 xeqi: gfredericks: I know nrepl.el did at one point. I would expect it still did

16:02 gfredericks: xeqi: I'm just new to nrepl and am trying to explain the phenomena I observe

16:04 n_b: number36: Try to programatically generate all the winning positions and define a function that checks whether a given symbol has won, then put it in a cond

16:05 i.e (cond (won? board :x) :x (won? board :o) :o)

16:06 number36: ok ok

16:06 i know solution with cond

16:06 but howcome i cannot use two IF-s in one function

16:06 or how could i use them

16:06 that is interesting for me

16:06 there has to be a way how function can have two IF-s

16:06 or clojure cannot do that ?

16:07 gfredericks: you can certainly have two ifs

16:08 n_b: two ifs works fine, but the final value in the body is what gets returned

16:08 gfredericks: the question is how you want them to relate to each other

16:08 n_b: so in your function, regardless of the result of the first if, you're not doing anything with the result

16:08 gfredericks: you can have one follow the other, where the first is presumably for side effects. Or you can have one in any of the three positions (condition, true-case, false-case) of the other

16:09 number36: hmm

16:09 i have corrected values

16:09 i had a mistake there

16:10 https://www.refheap.com/paste/8e3979a547943fbfc07ecc635

16:10 but now although i have everything written correctly

16:10 it doesnt pass the second test although

16:10 (= a d g :x)

16:10 is there

16:10 and thats exactly second test

16:11 [22:09] <n_b> two ifs works fine, but the final value in the body is what gets returned

16:11 hmm

16:11 gfredericks: number36: your first if effectively does nothing

16:11 n_b: (inc gfredericks)

16:11 lazybot: ⇒ 17

16:12 gfredericks: number36: I guess you're hoping the :x on line 9 is equivalent to "return :x" in java?

16:12 number36: yes

16:12 n_b: You could wrap it in a (comment) and effectively have the same function - the result of the first if is not returned

16:12 number36: gfredericks: please correct me if you would be so kind

16:12 gfredericks: number36: you have to learn to think in terms of expressions; clojure doesn't have a "return" concept like that

16:13 so you want one expression that encapsulates the logic you're going for

16:13 number36: n_b: thanks for suggestion i will check out the comment thing

16:13 gfredericks: in this case, your second if should be in the else position of the first if

16:13 (if a b (if c d nil))

16:13 number36: aha

16:13 interesting

16:13 gfredericks: ^ that sort of structure

16:13 number36: this is very interesting

16:13 dpathakj: number36: it may help to imagine what you would do in a C-like language if you were only allowed to 'return' once, at the end of the function.

16:13 gfredericks: cond gives you the same sort of thing, but the nested ifs might be easier to understand at first

16:14 (inc dpathakj)

16:14 lazybot: ⇒ 1

16:14 dpathakj: (that restriction is a real thing that is done in some places)

16:14 andyfingerhut: number36: I'm not sure what you want, but it is probably something like (if (or ...) :x (if (or ...) :o nil), replace the first ... with your conditions checking for win by x, and the second ... with your conditions checking for win by o.

16:14 number36: and adding the final ) that I left off.

16:17 number36: :)

16:17 managed to get to 4th test its 5th one that fails with this code

16:17 mmnt

16:18 https://www.refheap.com/paste/c530e68e483f1a8f250cef238

16:18 fails on

16:18 diagonal

16:18 mmnt maybe i have something wrong :)

16:19 Glenjamin: hi guys, i'm sure i'm missing something obvious - but how do I convert a numeric string into an integer?

16:19 jasonjckn: Integer/parseInt

16:19 gfredericks: ,(Integer/valueOf "15")

16:19 clojurebot: 15

16:19 gfredericks: ,(Integer/parseInt "15")

16:19 clojurebot: 15

16:20 Glenjamin: aha, thanks

16:20 number36: oh exactly what i needed now

16:20 :)

16:20 thanks everybody for input

16:21 gfredericks: (inc everybody)

16:21 lazybot: ⇒ 2

16:21 Glenjamin: i guess if it's not obvious in clojure core docs, the solution is java core

16:21 Bronsa: well

16:21 there's also read-string

16:21 gfredericks: Glenjamin: clojure.edn/read-string would do it

16:21 technomancy_: ~guards

16:21 clojurebot: SEIZE HIM!

16:21 Bronsa: ,(read-string "14")

16:21 clojurebot: 14

16:21 Glenjamin: read-string sounds a bit.. flexible

16:21 gfredericks: and probably much slower

16:21 or at least somewhat

16:22 yeah there are a number of different things that are trivial with interop that presumably for that reason are not baked into core

16:22 jasonjckn: Glenjamin: clojure core is a supplement to java core

16:22 or vice versa

16:23 Glenjamin: it seems like "int" could do this

16:23 gfredericks: ,(int "15")

16:23 clojurebot: #<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character>

16:23 Glenjamin: ,(int 1.0)

16:23 clojurebot: 1

16:23 gfredericks: ,(int \7)

16:23 clojurebot: 55

16:24 Glenjamin: int = (. clojure.lang.RT (intCast x))

16:24 whatever that means

16:25 Bronsa: it means https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L1079

16:25 gfredericks: Glenjamin: it's just deferring to a method defined in RT

16:25 Glenjamin: ah, i see

16:26 i assume when that was written, x instanceof String was discounted from the use cases

16:26 gfredericks: it's only fiddling with numeric types

16:26 it's not intended for parsing or anything else

16:26 Glenjamin: character is considered numeric?

16:26 gfredericks: in particular I believe it returns a primitive

16:35 Glenjamin: does anyone have some examples of using xml/parse and xml-seq and getting readable code?

16:35 i just seem to have chains like (-> :content first :content second), which aren't great

16:39 akhudek: Glenjamin: you could always use something like enlive

16:39 also, zippers can be useful

16:40 though zippers will still look something like the chains you don't like

16:40 devn: Glenjamin: also, get-in

16:40 Glenjamin: it's not so much the chains i dislike

16:40 devn: ,(get-in {:x [{:a [1 2 3]}]} [:x 0 :a 1])

16:40 clojurebot: 2

16:41 Glenjamin: its that reading the chains gives you no information about what's going on

16:41 devn: Glenjamin: So make them small named functions

16:42 Glenjamin: thats a good idea

16:49 rads: I need to save a hashmap to a file

16:49 the simplest solution to me seems to just use EDN, but I'm a little fuzzy on the border between clojure code and edn

16:49 do I just write the results of (prn my-hashmap) to a file?

16:49 and then read it back in with clojure.edn/read

16:50 akhudek: rads: that sounds right

16:50 though if it's data generated by your app, you don't need to worry about edn

16:51 edn matters if you are reading user supplied data

16:51 rads: I see

16:52 I just want to make sure the data I'm reading in is safe, as a habit

16:52 and that I'm not writing out any runtime-dependent junk

16:52 of course I could use JSON but I <3 clojure :)

17:05 Glenjamin: found clojure.data.zip.xml, seems to work pretty well even though it hasn't been touched in a year

17:15 akhudek: Glenjamin: enlive provides an xml-zip too

18:07 frozenlock: Could someone point me to an example use of streams? I want to make a pdf using https://github.com/yogthos/clj-pdf and then send it by email.

19:00 drewr: Halp!

19:00 Any idea how I can attach a pdf using postal, but without writing the file to disk?

19:52 `arrdem: has anyone here ported a site from noir down to compojure? I'm looking at transitioning my blog off of noir but it looks like I'm gonna have to rewrite about half the UI code to do so.

19:55 frozenlock: `arrdem: I've done it. Are you planning to use lib-noir?

19:56 `arrdem: Also iirc Raynes did it with refheap.

19:56 `arrdem: frozenlock: I'm neutral on this. I liked noir and there's some useful stuff in lib-noir.

19:57 frozenlock: also my blog was definitely my Clojure second system effect so it's a rats nest to begin with

19:58 my main question is where can I read up on how the argument semantics change.

19:58 frozenlock: Was the same for me. Moving to compojure gave me an opportunity to tidy up a little.

19:59 `arrdem: the Noir sample projects were pretty good about illustrating the argument structure but the compojure code I've found so far not as much

20:00 frozenlock: I found https://github.com/weavejester/compojure/wiki/Destructuring-Syntax to be really useful.

20:03 `arrdem: frozenlock: awesome, thanks!

20:03 (inc frozenlock) ;; am I the only one who votes around here?

20:03 lazybot: ⇒ 3

20:04 frozenlock: No... I heard a story about an old men that saw someone vote once :P

20:10 Any bitcoin project in clojure?

20:10 `arrdem: none that I know of...

20:11 hum is there a clean way to pull a library down from clojars to play with it in the repl?

20:11 besides throwing it in :deps and popping up a new one.

20:12 frozenlock: I assume you mean without restarting the repl.

20:12 Ah yeah... take a look at pomegranate

20:12 https://github.com/cemerick/pomegranate

20:12 `arrdem: oh cute

21:50 robertcurtis: Hi guys, I'm a student interested in Clojure for this summer's Google Summer of Code. Do any of you guys have experience with this program from last year?

22:52 murtaza52: I have a multi arity fn, where the arity is chosen based on the type of the arg, either a keyword or string, is this possible ?

22:53 I mean is it possible to create such a fn (without going the multimethod way) ?

22:59 chessguy: murtaza52: you keep using this word arity. i do not think it means what you think it means

23:02 murtaza52: chessguy: So what I want to do is basically have 2 forms and dispatch based on the type of arg - (fn (([a] "keyword") ([b] "string")). Like pattern matching on the type in haskell.

23:02 chessguy: murtaza52: that's what multimethods are for

23:03 (but it's got nothing to do with arity)

23:04 murtaza52: yes u r correct used the arity in the wrong sense, if I am correct is abt number of args, rather than type of args

23:05 chessguy: yes, that's what arity is

23:10 murtaza52: so why not use a multimethod?

23:11 murtaza52: wanted something more terse, as the fn themselves are one liners, so just using cond right now in the same fn.

Logging service provided by n01se.net