#clojure logs

2013-04-06

00:04tieTYT2i'm trying to save a data type to a file but when I (spit) it it only outputs clojure.lang.LazySeq@2cd9e23b
00:05tieTYT2how do I output the whoel thing so I can read it back into my repl for debugging
00:06mthvedttieTYT2: stick it into a readable data structure, like a vector
00:07akhudektieTYT: pr-str
00:07tieTYT2cool
00:08tieTYT2thanks
00:08bbloomthat's no good either
00:08bbloomjust call seq on it
00:08bbloompr-str will realize the full value into a string in memory
00:08bbloomspit will internally print directly to the writer, so the whole data structure doesn't need to be realized
00:09akhudekbbloom: but spit won't serialize right?
00:09bbloom,(str (clojure.lang.LazySeq (fn [] ["I" "am" "the" "thunk"]))
00:09clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
00:09bbloom,(str (clojure.lang.LazySeq (fn [] ["I" "am" "the" "thunk"])))
00:09clojurebot#<ClassCastException java.lang.ClassCastException: java.lang.Class cannot be cast to clojure.lang.IFn>
00:09bbloom,(str (clojure.lang.LazySeq. (fn [] ["I" "am" "the" "thunk"])))
00:09clojurebot"clojure.lang.LazySeq@726f771"
00:09bbloom,(str (seq (clojure.lang.LazySeq. (fn [] ["I" "am" "the" "thunk"]))))
00:09clojurebot"(\"I\" \"am\" \"the\" \"thunk\")"
00:09bbloomakhudek: spit will serialize
00:09bbloomakhudek: but it won't hold on to the head
00:10bbloomakhudek: 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
00:10bbloomakhudek: which is what will happen if you call vec
00:10bbloomakhudek: but will happen twice as fast if you call pr-str
00:10tieTYT2in this situation i won't run out of memory regardless
00:11bbloomtieTYT2: well either way, just (spit writer (seq the-lazy-seq))
00:11tieTYT2ok
00:11akhudekbbloom: interesting, I didn't know that
00:12akhudekI might have to refactor some code to be a bit more memory efficient.
00:12bbloomakhudek: oh nevermind
00:12bbloomi'm wrong.
00:12bbloomlol
00:12bbloomsorry
00:12bbloomjust looked at the source of spit
00:12akhudekoh :-(
00:12akhudekand here I got excited
00:12bbloomspit just calls (str)... *sigh*
00:12tieTYT2i'm reading it back in like this: (def i (read-string (slurp "out.html")))
00:13bbloomspit isn't a very clever function....
00:13bbloomsorry about that, my bad.
00:13tieTYT2hrm
00:13akhudektieTYT2: turns out you do need to use pr-string, then that should work for reading it back in
00:13akhudekerr pr-str
00:13tieTYT2really, the issue I'm having is a debugging issue
00:13tieTYT2i've written some code that works like a spider that crawls a webpage
00:13tieTYT2I'm getting an error about IllegalArgumentException No value supplied for key
00:13tieTYT2and I can't even be sure of which line it's outputting that on
00:14tieTYT2it shows me the map after that error and it looks fine to me
00:14tieTYT2if I copy it and paste it back into the repl with a ' in front of it it gives me no error
00:15akhudektieTYT2: hard to help without seeing code :-/
00:15howdynihao((fn [x] (conj [x] 1)) 2) am i understanding this right? first x is setting the argument to x
00:16howdynihaosecond x is creating a vector with x
00:16howdynihaoseems unfortunate they both appear the same? or are both actually vectors?
00:16tieTYT2ok first of all this is the error: IllegalArgumentException No value supplied for key: {:post-link "http://site.com/index.php?topic=1987109.0&quot;, :image-links ("http://site.com/index.php?action=dlattach;topic=1987109.0;attach=6181834;image&quot; "http://site.com/index.php?action=dlattach;topic=1987109.0;attach=6181836;image&quot;)} clojure.lang.PersistentHashMap.createWithCheck (PersistentHashMap.java:89)
00:17tieTYT2and my code is like a 100 lines. How do I know which code to show you?
00:17akhudekhowdynihao: they are both actually vectors, the first is simply used internally for argument bindings
00:19tieTYT2oh i get it, it's saying that whole thing is one key?
00:19tieTYT2that makes it easier to debug
00:19akhudektieTYT2: what is the stack trace?
00:19akhudekyes
00:19tieTYT2it doesn't show me one
00:19tieTYT2unless I do (pst)
00:19tieTYT2which doens't have useful line numbers
00:19tieTYT2I'm using Counter Clock Wise
00:19akhudek(e) doesn't work?
00:20tieTYT2CompilerException java.lang.RuntimeException: Unable to resolve symbol: e in this context, compiling:(NO_SOURCE_PATH:1)
00:20akhudekif you aren't getting line numbers, reload the namespace as a file
00:20akhudeknot sure what the CC command for this is
00:20tieTYT2the stack trace is one line
00:21tieTYT2anyway, I think I can fix the problem at hand at least
00:21tieTYT2i didn't know that I was supposed to get better stack traces than I am
00:21tieTYT2the output is exactly what I pasted earlier including the "full" stack trace it gives me
00:22akhudektieTYT2: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.
00:22akhudekAlso, always try to reload whole namespaces when possible, I believe that way it gives you line numbers.
00:23tieTYT2java.lang.ClassNotFoundException: clojure.stacktrace
00:24tieTYT2ok i reloaded the namespace
00:24tieTYT2err, switched to it
00:24tieTYT2and then that worked
00:24tieTYT2thanks
00:25tieTYT2ok that worked
00:25tieTYT2now I can debug my program
00:25tieTYT2wtf doesn't CCW automatically include that in the repl?
00:26akhudekguess it doesn't want to inject unwanted things into peoples programs, though it is quite a useful library!
00:27tieTYT2yeah, it doesn't have (doc) or (source) either. Quite annoying
00:27tieTYT2thanks
00:29howdynihaoi 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...
00:30howdynihaois the return, i would think it would keep returning a function ?
00:30howdynihaoso it seems like it should be ( 5 1) as the result not ( 5 4 3 2 1) ?
00:31eggheadwhy do you think it would return a function howdynihao ?
00:32eggheadthe only place it can exit is from 'conj'
00:33howdynihaowell maybe not return a function, but i would think it would keep calling foo until it gets a result
00:33howdynihaoso i understand how it could return 4 3 2 AND still keep calling foo
00:33howdynihaoi dont understand i mean
00:33eggheadso what happens is the other way around, there is some initial call to (conj (something...) onto x)
00:34eggheadand that something travels down further, until eventually the condition is no longer true because x is 0
00:35eggheadso 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)
00:36howdynihaook so something is actually (4 3 2 1) ? and it isn't conjoining 5 times ?
00:36howdynihaowell i still dont understand really why the values return
00:37howdynihaolike in recursive functions in other languages, you get the last calls return and it bubbles up to the initial call
00:37eggheadif you change 5 to 2 for instance: you might imagine the call stack as (conj (conj nil 1) 2)
00:39eggheadit is doing that tho, it follows down until (foo n) returns a value instead of a new call
00:39eggheadand that percolates back up until the very first call to conj has all it's parameters resolved
00:39eggheadsince it's call by value
00:42howdynihaoahhhh ok now i get it, maybe its the parenthesis :P tripping me up
00:44eggheadcheers howdynihao
01:05tieTYT2i 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?
01:43radshas anyone gotten the clojurescript brepl to work with node-webkit?
01:43radsI'm getting this: Uncaught Error: URI file:/robots.txt is invalid for field ppu
01:43radsseems like a cross domain security problem
01:45a|iany serious clojure based rules engine out there?
02:04radsibdknox: 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?
02:45tieTYT2how can I do something like map, but only on the odd or even elements?
02:45tieTYT2but I don't want to filter it down
02:47bbloomtieTYT2: two main choices
02:47bbloom1) map-indexed where you conditionally transform based on (even? index)
02:48bbloom2) interleave two calls to take-nth, one mapped, and one next-ed
02:48tieTYT2hrm, 1) seems easier to me
02:48tieTYT2i'll do that, thanks
02:50bbloom,(let [v [:a :b :c :d]] (interleave (map name (take-nth 2 v)) (take-nth 2 (next v))))
02:50clojurebot("a" :b "c" :d)
02:50bbloom2 is pretty easy too :-)
02:51bbloom,(map-indexed (fn [i x] (if (even? i) (name x) x)) [:a :b :c :d])
02:51clojurebot("a" :b "c" :d)
02:53Raynesbbloom: It's a party in the USA.
02:53bbloomRaynes: ?
02:54Raynesbbloom: I was listening to that song (for scientific purposes, I assure you) and needed to tell somebody.
02:55bbloomRaynes: i'm glad you can confide in me, but i have no idea what that song is
02:55Raynesbbloom: http://www.youtube.com/watch?v=M11SvDtPBhA
02:55RaynesThe worst thing ever.
02:57Raynesbbloom: 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.
03:10RaynesI need a trendy place to buy coffee mugs.
03:13bbloomBest coffee mug I ever used cost me 4 dollars at a Safeway
03:14RaynesI looked at mugs at Target but didn't want to pay $20 for a coffee mug.
03:14RaynesI'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.
03:14Rayneshttp://www.amazon.com/Big-Mouth-Toys-Toilet-Mug/dp/B002SQG4TU/ref=sr_1_10?ie=UTF8&amp;qid=1365232495&amp;sr=8-10&amp;keywords=coffee+mug
03:14bbloomlol
03:15bbloomyou a 1 cup am and 1 cup pm sorta guy?
03:15bbloomor you more of a thermos all day long sorta man
03:16RaynesI'm a 1 cup AM because I never sleep kind of guy who hates himself because he tries to avoid caffeine.
03:17bbloomyeah, you just need a plain old white cup. i prefer vertical sides, since they have a wider base & are steadier
03:22arcatanhave a smaller cup, so you'll have less coffee and less caffeine
03:31Raynesbbloom: http://www.amazon.com/Dr-Who-Disappearing-Tardis-mug/dp/B003Z31K7G/ref=sr_1_9?s=home-garden&amp;ie=UTF8&amp;qid=1365233306&amp;sr=1-9&amp;keywords=mug This is what I need.
04:04ddellacostaI 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?
04:10borkdudeis there a way to debug routes in compojure/ring to see which route actually gets fired by a request?
04:28borkdudeyogthos 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?
04:29borkdudeyogthos I added this line under ;;add your middlewares here: (resource/wrap-resource "/META-INF/resources/")
04:30borkdudeyogthos one solution would be to just copy the resources to the normal resources folder, but I want to find out what's going on
05:15murtaza52What does the refer key do ex - (:require [abc.core :refer :all])
05:16borkdudemurtaza52 it does the same as :use :only
05:16borkdudemurtaza52 or in this case :use
05:17murtaza52so if I have (:require [abc.core :refer xyz])
05:18murtaza52borkdude: does this mean that xyz is a function which is being imported in the current ns, just like :only
05:18borkdude(:require [abc.core :refer [fn1 fn2]])
05:18borkdudeyes
05:41murtaza52borkude: so what is the diff of using :use and :only compared to :require and :refer
05:54borkdudemurtaza52 no difference
05:54borkdudeI think I found out what's going wrong with my routes and webjars:
05:55borkdudehttps://www.refheap.com/paste/13317
05:56borkdudethe jar directory gets recognized as a resource, but not as a file, hence it is returned as (io/input-stream resource) hm
05:58borkdudethe protocol = jar
06:09faust45hi guys
06:09faust45just have a problem
06:09faust45i try create class with (gen-class ...)
06:10faust45then (compile it in REPL
06:10faust45and its success
06:10faust45but how i can load this class to REPL
06:10faust45please help me
06:20jemafellerhello
06:20jemafellerwhat would be the best way to expose a high performance service with RPC to a node.js (or any server side) service?
06:20jjl`that depends what you need
06:26jemafellerjjl`, well, I'd like the code being executed to be as high performance as possible
06:26jemafellerthis is because it was supposed to be the same process, and the same codebase but was split into two
06:27jemafellerit may also be that the two processes may live on the same machine, so that they could use pipes - but that is not guaranteed
06:28jemafelleron paper, zeromq looks to be answering all of these as it is a 'fancy' socket that can transparently switch between TCP/in-proc/etc
06:28jemafellerbut I'm aware of a lot of gripe with it and JVM based code
06:28jjl`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?
06:29jemafelleryes to both
06:29jemafellerI also looked at Thrift, but there's a lot of criticism about complexity of connection handling and error handling with Thrift
06:29jjl`thrift was a nightmare when i worked with it
06:30jjl`zeromq probably isn't going to be your solution if you want an answer immediately
06:31jjl`have you considered XMPP? not the most efficient in terms of size of messages, but can be very low latency
06:32jemafellerI haven't actually. I'll throw in another thing though - the messages are big.
06:33jemafellerthey can go into 100kb in size, since it is a document that's passed between services
06:33jemafellerit's online document analysis, part of it is done in service A, and part of it in service B
06:34jemafellerso I think XMPP wasn't built to handle big messages..?
06:34jemafellerand 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)
06:36jjl`XMPP can be made to handle big messages but it isn't designed for it
06:38mpenetDid you consider the java port of 0mq? I am not sure what you were refering to it earlier.
06:38jemafellermpenet, you mean jeromq? no I didn't.. I'm not sure what to think about it
06:39mpenetYes, well it seems young, and I never used it, so I can't really vouch for it, but it seems like an option
06:40jemafelleri'm wondering about ProtocolBuffers though.. i'll need to find a way to implement the RPC daemon myself in Clojure
06:40mpenetbut 0mq should be quite reliable anyway, I think Storm uses it internaly, it could be worth have a look there too.
06:42alex_baranoskydoes anyone know offhand how big the thread pool is for futures is?
06:42jemafellermpenet, yes they do. and that's where I understood they have problems with it when it comes to Java and maintainability
06:43jemafellerhttps://github.com/nathanmarz/storm/issues/372
06:44Glenjaminjemafeller: i'd vote json over rabbitMQ
06:44Glenjaminbut it depends on your definition of high performance in this case
06:44mpenetinteresting
06:44jemafellerGlenjamin, the solution would need to be synchronous and immediate. i'd like to be as close to in-proc as possible
06:45Glenjaminprobably want something binary over http then?
06:45Glenjaminmsgpack / thrift etc
06:45Glenjamins/http/tcp
06:45mpenetalex_baranosky: I think it's an cachedThreadPool
06:45jemafellerGlenjamin, yes. that would be a reasonable solution - since I also don't want to prematurely optimize
06:46jjl`also think about whether you're more likely to be network or cpu bound
06:46Glenjaminthrow together a couple of options and benchmark i guess?
06:46alex_baranoskympenet: googling seems to suggest it is an unbounded thread pool, unless that has changed since these blogs were written
06:46jemafellerGlenjamin, but, i'm not so much experienced with Thrift and Java and heard a lot of bad experiences there
06:46mpenetalex_baranosky: yes
06:47jjl`the packets are large, so maybe it'll be network bound, but then what are the documents? do they have a native format?
06:47Glenjaminmaybe start with json over tcp and leave the serialisation format malleable?
06:47jemafellerjjl`, the process doing the work behind RPC is completely CPU bound, it's a text analysis algorithm suite.
06:47jjl`maybe the overhead isn't going to be that large
06:47mpenetalex_baranosky: I have future-call and future versions that allow to use your own executors in mpenet/knit
06:47jjl`in which case, do minimal cpu processing and make sure the network can handle it
06:47jemafellerjjl`, the documents are just text. imagine a Service A -[text]-> Service B
06:47mpenetalex_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
06:48jjl`jemafeller: given the docs are so large, go for a simple protocol that requires minimal cpu to process and throw it onto the network
06:48jemafellerjjl`, you're right, I think network bandwidth could be a problem in this case
06:48jjl`then your solution is wrong
06:49jjl`parallelise the backend service so cpu isn't a concern
06:49jjl`but if network bandwidth will be a problem sending large documents, then a small protocol won't help - the docs are large
06:49jjl`can't you get a fibre connect in?
06:50jemafelleryep.. i'm thinking about that
06:50mpenetalex_baranosky: also fyi the threadpool used by futures is the same agents use
06:51mpenetunless you use send-via of course
06:55jemafellerhmm i think i'll go by this priority - msgpack-rpc, protobuf-rpc, and then plain HTTP if none of these work
08:28john2xcan I not require goog.x libraries in the clojurescript repl? if so, how to do?
08:43chessguygood mooooorning clojure world!
09:21kmicuTen sam chrome, który był na webkitice tak jak safari?
09:38borkdudehttps://www.refheap.com/paste/13332 <- reproduction of my webjars problem
10:31juhu_chapaHi guys!
10:32juhu_chapain order to use (javadoc Object) How can I set the default browser?
10:33juhu_chapathis at the REPL
10:34borkdudejuhu_chapa I don't know, but isn't this just the default system browser?
10:35juhu_chapaborkdude: I am on BSD, do you refer to an OS environment variable?
10:36borkdudejuhu_chapa I have googled it for you: http://forums.freebsd.org/showthread.php?t=19829 - I don't know much about BSD
10:37juhu_chapaborkdude: Thank you!
10:38borkdudejuhu_chapa no problem, googling for other people is what I do
10:38borkdude:P
10:39juhu_chapa;)
10:49chessguyhow 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:52ucbchessguy: you can try https://github.com/stuartsierra/lazytest
10:52ucbchessguy: additionally, if you're using midje for testing there's midje-mode and lazytest via midje too
10:53chessguyucb: 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:53ucbchessguy: surely TDD is not necessarily about the testing lib?
10:54chessguyucb: i'm not learning TDD, i'm learning testing in clojure
10:54chessguyi just want to know the standard library first
10:54ucbchessguy: oh, I see.
10:58chessguyhmm. what we really need is something like guard for clojure
10:59headshoterlang anyone?
10:59ucbchessguy: that's what lazytest does (from my brief reading about https://github.com/guard/guard-test)
11:01chessguyucb: maybe i'll try that, thanks
11:01ucbchessguy: no worries
11:10yogthosdnolen: hello? :)
11:12yogthosis anybody versed in cljs magic?
11:16dnolenyogthos: what's up?
11:17yogthosdnolen: oh I ran into advanced optimizations problem, but I think I know what's happened
11:17dnolenok
11:17yogthosdnolen: stuff was using this https://github.com/chengyin/albumcolors
11:18yogthosand 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:18yogthosso from what I gathered is names get munged?
11:19yogthosso I have to protect them explicitly with externs?
11:20yogthosdnolen: does that sound right?
11:20yogthosthe errors I get look like Uncaught TypeError: Object [object Object] has no method 'Le'
11:21yogthosand the code in question is
11:21yogthos(defn set-colors [div]
11:21yogthos (.getColors (js/AlbumColors. (img-url div))
11:21yogthos (fn [[background _ foreground]]
11:21yogthos (set-color (.-style div) foreground background))))
11:21yogthoscalling (.getColors is what's causing it
11:25chessguylooks like lazytest is pretty old. seems to be insisting on an outdated convention for file locations
11:26lfranchihey 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:26lfranchicallback is not printing out / being called: https://gist.github.com/lfranchi/5326479.
11:26lfranchii must be missing something really fundamental, but i'm not sure what
11:27lfranchiany tips would be really appreciated :)
11:27juhu_chapaHow to list all global vars?
11:30yogthosdnolen: is there an example on how to use externs with cljsbuild?
11:32yogthosdnolen: when I specify :externs ["externs.js"] is externs.js loaded in the browser at runtime or referenced during compilation?
11:33dnolenyogthos: no idea about cljsbuild extern support but I'm sure it does.
11:33dnolenyogthos: and yes your issue sounds like an externs one
11:34yogthosdnolen: 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:34yogthosdnolen: and I assume it's because I'm passing an anonymous function as an argument to a js function?
11:34dnolenyogthos: you might want to look at jayq, I believe jayq uses an externs and works via lein-cljsbuild
11:34yogthosdnolen: ah good idea
11:35yogthosdnolen: it's all about finding that one example :) after that it's usually obvious in retrospect
11:37murtaza52I 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:41chessguyhm. i get an error when i M-x package-install clojure-test-mode
11:41chessguytechnomancy: you around, by any chance?
11:41yogthosdnolen: yup was the externs, thanks for pointing me to jayq works like a charm now :)
11:41dnolenmurtaza52: why not just use take-while?
11:41dnolenyogthos: sweet!
11:43lfranchiHm, seems like my aleph connection is never even calling my on-realized callback, as throwing an exception in the fn is never hit :-/
11:43chessguydnolen: i didn't know you hung out here. seen a couple of your talks on pattern-matching. awesome stuff, keep it up!
11:48dnolenchessguy: thx!
12:04lfranchiHmm, 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:05lfranchithis is after calling (org.apache.log4j.BasicConfigurator/configure)
12:39clojure-newHello, i have a list of #inst dates, how can i sort it?
12:43jonasenclojure-new: (sort [#inst "2000" #inst "2013" #inst "1984"])
12:44Okasu, (sort [#inst "2000" #inst "2013" #inst "1984"])
12:44clojurebot#<SecurityException java.lang.SecurityException: denied>
12:45clojure-newIt works, thanks!
14:01jameshasselmanGetting 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:03bbloomjameshasselman: you're not destructuring the vector in your dispatch function
14:03bbloom[[unit _]]
14:04bbloomjameshasselman: oh sorry, misread
14:04bbloom(value) isn't what you want
14:04bbloomyou jsut want value by itself
14:05bbloomotherwise that's (10) or whatever
14:05bbloomand numbers aren't callable
14:05bbloombeyond that, you're probably expecting defmulti to redefine the dispatch fn, which, annoyingly, it won't do
14:06bbloomso (ns-unmap *ns* 'unit-to-minutes)
14:06bbloomthen try again
14:10jameshasselmanthat worked, but I don't understand why
14:10jameshasselmanThanks though, would not have figured that out.
14:37SirLalalahi! I solved this problem from project euler in clojure http://projecteuler.net/problem=11 . But I'm trying to minimize the code
14:44SirLalalahow can I convert a vector like this [ [[1 2] [2 3]] [[3 4] [4 5]]] to [ [1 2] [2 3] [3 4] etc.
14:45Okasu,(flatten [[2][3]])
14:45clojurebot(2 3)
14:52eckroth,(apply concat [[[1 2] [2 3]] [[3 4] [4 5]]])
14:52clojurebot([1 2] [2 3] [3 4] [4 5])
14:55SirLalalaeckroth: awesome thanks!
14:57danneunice
15:08chessguy,(apply 'and '((3)))
15:08clojurebotnil
15:08chessguycan someone help me understand that?
15:08chessguyi would expect that to evaluate to '(3)
15:09eckroth,(apply 'foo '((3)))
15:09clojurebotnil
15:09eckroth,(apply and '((3)))
15:09clojurebot#<CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compiling:(NO_SOURCE_PATH:0:0)>
15:10eckrothand is a macro, so it acts differently than you might expect
15:10chessguy(macroexpand '(apply and '((3))))
15:10chessguy,(macroexpand '(apply and '((3))))
15:10clojurebot(apply and (quote ((3))))
15:10chessguybah
15:11eckroth,(macroexpand '(and true false false true))
15:11clojurebot(let* [and__3965__auto__ true] (if and__3965__auto__ (clojure.core/and false false true) and__3965__auto__))
15:11eckrothkind of cool: does (if [first value] (and [2nd value] [3rd value] [4th value]) [first value])
15:12eckrothlike it's currying
15:12chessguyeckroth: right, but the first value here is '(3), no?
15:12eckroth,(and '((3))
15:12clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
15:12eckroth,(and '((3)))
15:12clojurebot((3))
15:12eckrothapply does not work here because it's a macro
15:13chessguyam i going about this wrong? i have a sequence and i want to know if every element is truthy...
15:13chessguyi could (every? 'id xs)
15:13chessguybut that seems verbose
15:13eckrothwas just going to suggest that
15:14eckrothyou can make a helper func that does (every? identity xs) but otherwise I don't know of a built-in
15:14chessguyreally? wow
15:14eckrothmabye someone can tell use otherwise
15:15chessguyi suppose it's not really less verbose than apply all
15:15eckrothright and usually I find myself doing: (every? some-func original-xs)
15:15eckrothwhere some-func is an interesting operation
15:15eckrothso it's not a big loss
15:15chessguysure
15:16n_bSo I'm considering switching to emacs from vim, what's the easiest way to get started with that+clojure?
15:16eckrothusing identity is a total code smell; I've used it but I feel weird
15:16eckrothn_b: clojurebox maybe?
15:16Okasun_b: Nrepl is a good thing.
15:17chessguyn_b: i used this gist just the other week to get started: https://gist.github.com/rkneufeld/5126926
15:19n_bchessguy: That looks great. I was a little unclear in my phrasing; I know Clojure, just not familiar with the emacs ecosystem at all
15:20chessguyn_b: ah, in that case, this is one of the few cases where i recommend starting by reading the documentation
15:22n_bchessguy: just `man emacs`?
15:22chessguythat is, open emacs and hit ctrl+h, then t
15:23danneun_b: i switched to emacs from vim a few weeks ago.
15:25chessguydanneu: i'm curious how that went
15:27danneuchessguy: it was awesome.
15:28chessguydanneu: nice. i've tried a couple of times to add vim to my toolbelt, and struggled every time
15:28danneunote that i'm using Evil-mode
15:28chessguydanneu: is that like viper-mode?
15:28danneuyeah but much better apparently. they nailed it
15:28n_bI'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:29chessguydanneu: nice
15:29n_bevil even has support for reading.vimrc IIRC
15:29chessguyn_b: what's that?
15:29jameshasselmandoes anyone use counterclockwise?
15:29danneuthe .emacs of vim
15:30danneujameshasselman: i did for a week before trying emacs. it wasnt bad and it was my first experience with an ide
15:30chessguyoh, sorry, the lack of space made my brain's parser fail
15:30jameshasselmanI want to use it, but my breakpoints don't work. I need a debugger.
15:30chessguyjameshasselman: a debugger for clojure?
15:31chessguyisn't that what the repl is for?
15:31danneuvim->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:31danneui imagine
15:31chessguydanneu: yeah, getting used to remembering what mode you're in requires building up muscle memory
15:31jameshasselmanwell 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:32chessguyjameshasselman: yeah, that's true
15:32danneuis there a way to reverse stack traces? i'm tired of scrolling up..
15:32chessguyjameshasselman: i see that a lot in both the repl and lighttable
15:34n_bchessguy: the problem is when that memory carries over to other areas. I've submitted more than one form with :wq at the end >>
15:34danneuwell, you should be using :x anyways
15:34chessguyn_b: haha
15:36chessguyi've been switching back and forth between emacs and lighttable. neither one really scratches my itch
15:36n_bI didn't like LT at all
15:37danneuLT is good for getting started with Clojure imo. i think it's a good middleground between emacs+nrepl and a crappy embedded repl.
15:38danneuthe former requiring an investment to set up and the latter just sucking.
15:43n_brlwarp works with the default clj repl doesn't it?
15:46chessguyrlwarp? is that like rlwrap, but at faster-than-light speed?
15:47chessguysorry, i couldn't resist
15:48andyfingerhutn_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:49andyfingerhutn_b: But more often "lein repo" is what I want.
15:49andyfingerhutn_b: Grrr auto-correct. "lein repl"
15:49chessguyandyfingerhut: you mostly want that to get the project's dependencies?
15:50andyfingerhutchessguy: Yes, and it has a few other enhancements from reply like access to ClojureDocs examples.
15:50n_bDoesn't `rlwrap lein repl` work?
15:50n_bIt should be transparent
15:51andyfingerhutn_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:51andyfingerhutMust… figure… out… how… to … disable. auto-correct.
15:52jameshasselmanwell, 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:52n_b,(doc int)
15:52clojurebot"([x]); Coerce to int"
15:53jameshasselmanI 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:54chessguy(int 3.0)
15:54chessguy,(int 3.0)
15:54clojurebot3
15:54chessguy,(int 3.9)
15:54clojurebot3
15:55andyfingerhutn_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:56n_bandyfingerhut: 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:58gfredericksjameshasselman: yeah I think the thing that int is doing is a special jvm thing related to primitives
15:59jameshasselmanOh, so the bot will evaluate expressions. That's pretty cool.
15:59n_bannnnd 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:59number36hi all i have very simple problem
15:59number36if someone would be so kind to help me
16:00number36i am trying to solve one problem on 4clojure.com in different way
16:00number36but i dont know how can i put two IF-s in one function
16:00n_bjameshasselman: Yup. clojurebot responds to , and lazybot does inline stuff with ##(print 1)
16:00lazybot⇒ 1nil
16:00gfredericksdoes nrepl and/or reply associate each clojure-mode buffer with anamespace
16:00gfredericksi.e., a value of *ns*?
16:01n_bnumber36: Which problem?
16:01number36https://www.refheap.com/paste/359b51eb1d9470da44a255881
16:01number36and this is problem
16:01number36http://www.4clojure.com/problem/73
16:01jameshasselmann_b: is it number 36
16:01number36:)
16:01xeqigfredericks: I know nrepl.el did at one point. I would expect it still did
16:02gfredericksxeqi: I'm just new to nrepl and am trying to explain the phenomena I observe
16:04n_bnumber36: 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:05n_bi.e (cond (won? board :x) :x (won? board :o) :o)
16:06number36ok ok
16:06number36i know solution with cond
16:06number36but howcome i cannot use two IF-s in one function
16:06number36or how could i use them
16:06number36that is interesting for me
16:06number36there has to be a way how function can have two IF-s
16:06number36or clojure cannot do that ?
16:07gfredericksyou can certainly have two ifs
16:08n_btwo ifs works fine, but the final value in the body is what gets returned
16:08gfredericksthe question is how you want them to relate to each other
16:08n_bso in your function, regardless of the result of the first if, you're not doing anything with the result
16:08gfredericksyou 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:09number36hmm
16:09number36i have corrected values
16:09number36i had a mistake there
16:10number36https://www.refheap.com/paste/8e3979a547943fbfc07ecc635
16:10number36but now although i have everything written correctly
16:10number36it doesnt pass the second test although
16:10number36(= a d g :x)
16:10number36is there
16:10number36and thats exactly second test
16:11number36[22:09] <n_b> two ifs works fine, but the final value in the body is what gets returned
16:11number36hmm
16:11gfredericksnumber36: your first if effectively does nothing
16:11n_b(inc gfredericks)
16:11lazybot⇒ 17
16:12gfredericksnumber36: I guess you're hoping the :x on line 9 is equivalent to "return :x" in java?
16:12number36yes
16:12n_bYou could wrap it in a (comment) and effectively have the same function - the result of the first if is not returned
16:12number36gfredericks: please correct me if you would be so kind
16:12gfredericksnumber36: you have to learn to think in terms of expressions; clojure doesn't have a "return" concept like that
16:13gfredericksso you want one expression that encapsulates the logic you're going for
16:13number36n_b: thanks for suggestion i will check out the comment thing
16:13gfredericksin this case, your second if should be in the else position of the first if
16:13gfredericks(if a b (if c d nil))
16:13number36aha
16:13number36interesting
16:13gfredericks^ that sort of structure
16:13number36this is very interesting
16:13dpathakjnumber36: 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:13gfrederickscond gives you the same sort of thing, but the nested ifs might be easier to understand at first
16:14gfredericks(inc dpathakj)
16:14lazybot⇒ 1
16:14dpathakj(that restriction is a real thing that is done in some places)
16:14andyfingerhutnumber36: 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:14andyfingerhutnumber36: and adding the final ) that I left off.
16:17number36:)
16:17number36managed to get to 4th test its 5th one that fails with this code
16:17number36mmnt
16:18number36https://www.refheap.com/paste/c530e68e483f1a8f250cef238
16:18number36fails on
16:18number36diagonal
16:18number36mmnt maybe i have something wrong :)
16:19Glenjaminhi guys, i'm sure i'm missing something obvious - but how do I convert a numeric string into an integer?
16:19jasonjcknInteger/parseInt
16:19gfredericks,(Integer/valueOf "15")
16:19clojurebot15
16:19gfredericks,(Integer/parseInt "15")
16:19clojurebot15
16:20Glenjaminaha, thanks
16:20number36oh exactly what i needed now
16:20number36:)
16:20number36thanks everybody for input
16:21gfredericks(inc everybody)
16:21lazybot⇒ 2
16:21Glenjamini guess if it's not obvious in clojure core docs, the solution is java core
16:21Bronsawell
16:21Bronsathere's also read-string
16:21gfredericksGlenjamin: clojure.edn/read-string would do it
16:21technomancy_~guards
16:21clojurebotSEIZE HIM!
16:21Bronsa,(read-string "14")
16:21clojurebot14
16:21Glenjaminread-string sounds a bit.. flexible
16:21gfredericksand probably much slower
16:21gfredericksor at least somewhat
16:22gfredericksyeah there are a number of different things that are trivial with interop that presumably for that reason are not baked into core
16:22jasonjcknGlenjamin: clojure core is a supplement to java core
16:22jasonjcknor vice versa
16:23Glenjaminit seems like "int" could do this
16:23gfredericks,(int "15")
16:23clojurebot#<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character>
16:23Glenjamin,(int 1.0)
16:23clojurebot1
16:23gfredericks,(int \7)
16:23clojurebot55
16:24Glenjaminint = (. clojure.lang.RT (intCast x))
16:24Glenjaminwhatever that means
16:25Bronsait means https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L1079
16:25gfredericksGlenjamin: it's just deferring to a method defined in RT
16:25Glenjaminah, i see
16:26Glenjamini assume when that was written, x instanceof String was discounted from the use cases
16:26gfredericksit's only fiddling with numeric types
16:26gfredericksit's not intended for parsing or anything else
16:26Glenjamincharacter is considered numeric?
16:26gfredericksin particular I believe it returns a primitive
16:35Glenjamindoes anyone have some examples of using xml/parse and xml-seq and getting readable code?
16:35Glenjamini just seem to have chains like (-> :content first :content second), which aren't great
16:39akhudekGlenjamin: you could always use something like enlive
16:39akhudekalso, zippers can be useful
16:40akhudekthough zippers will still look something like the chains you don't like
16:40devnGlenjamin: also, get-in
16:40Glenjaminit's not so much the chains i dislike
16:40devn,(get-in {:x [{:a [1 2 3]}]} [:x 0 :a 1])
16:40clojurebot2
16:41Glenjaminits that reading the chains gives you no information about what's going on
16:41devnGlenjamin: So make them small named functions
16:42Glenjaminthats a good idea
16:49radsI need to save a hashmap to a file
16:49radsthe simplest solution to me seems to just use EDN, but I'm a little fuzzy on the border between clojure code and edn
16:49radsdo I just write the results of (prn my-hashmap) to a file?
16:49radsand then read it back in with clojure.edn/read
16:50akhudekrads: that sounds right
16:50akhudekthough if it's data generated by your app, you don't need to worry about edn
16:51akhudekedn matters if you are reading user supplied data
16:51radsI see
16:52radsI just want to make sure the data I'm reading in is safe, as a habit
16:52radsand that I'm not writing out any runtime-dependent junk
16:52radsof course I could use JSON but I <3 clojure :)
17:05Glenjaminfound clojure.data.zip.xml, seems to work pretty well even though it hasn't been touched in a year
17:15akhudekGlenjamin: enlive provides an xml-zip too
18:07frozenlockCould 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:00frozenlockdrewr: Halp!
19:00frozenlockAny idea how I can attach a pdf using postal, but without writing the file to disk?
19:52`arrdemhas 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:55frozenlock`arrdem: I've done it. Are you planning to use lib-noir?
19:56frozenlock`arrdem: Also iirc Raynes did it with refheap.
19:56`arrdemfrozenlock: I'm neutral on this. I liked noir and there's some useful stuff in lib-noir.
19:57`arrdemfrozenlock: also my blog was definitely my Clojure second system effect so it's a rats nest to begin with
19:58`arrdemmy main question is where can I read up on how the argument semantics change.
19:58frozenlockWas the same for me. Moving to compojure gave me an opportunity to tidy up a little.
19:59`arrdemthe Noir sample projects were pretty good about illustrating the argument structure but the compojure code I've found so far not as much
20:00frozenlockI found https://github.com/weavejester/compojure/wiki/Destructuring-Syntax to be really useful.
20:03`arrdemfrozenlock: awesome, thanks!
20:03`arrdem(inc frozenlock) ;; am I the only one who votes around here?
20:03lazybot⇒ 3
20:04frozenlockNo... I heard a story about an old men that saw someone vote once :P
20:10frozenlockAny bitcoin project in clojure?
20:10`arrdemnone that I know of...
20:11`arrdemhum is there a clean way to pull a library down from clojars to play with it in the repl?
20:11`arrdembesides throwing it in :deps and popping up a new one.
20:12frozenlockI assume you mean without restarting the repl.
20:12frozenlockAh yeah... take a look at pomegranate
20:12frozenlockhttps://github.com/cemerick/pomegranate
20:12`arrdem oh cute
21:50robertcurtisHi 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:52murtaza52I 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:53murtaza52I mean is it possible to create such a fn (without going the multimethod way) ?
22:59chessguymurtaza52: you keep using this word arity. i do not think it means what you think it means
23:02murtaza52chessguy: 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:02chessguymurtaza52: that's what multimethods are for
23:03chessguy(but it's got nothing to do with arity)
23:04murtaza52yes 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:05chessguyyes, that's what arity is
23:10chessguymurtaza52: so why not use a multimethod?
23:11murtaza52wanted something more terse, as the fn themselves are one liners, so just using cond right now in the same fn.