#clojure logs

2013-06-23

01:24clizzinnavgeet: pretty sure friend doesn't actually handle oauth2 provider logic, it only provides a framework into which you can plug in different authentication/authorization logic
01:27tomjackhas oauth2 changed in the last 10mo?
01:27tomjackmaybe clauth is OK? :)
01:27clizzinmaybe it is!
01:27clizzini'll try it out, seeing as how there doesn't seem to be much else. the readme claims to have implemented everything but refresh tokens.
01:29dyresharkhow can i turn a string into a list of unresolved symbols (i.e. (= '(foo bar baz) (??? "(foo bar baz)")))
01:31tomjackread-string or clojure.edn/read-string
01:31tomjackif you trust or don't trust, respectively, the string
01:32dyresharkthanks!
01:41ak5hey guys, I am doing 4clojure and when doing this: (I figured it out, but I do NOT understand the syntax of the problem) http://www.4clojure.com/problem/71 aren't (= (count (sort (rest (reverse [2 5 4 1 3 6])))) and (-> [2 5 4 1 3 6] reverse rest sort count) the same?
01:43tomjacksounds like you understand it to me
01:43ak5tomjack: the page is broken then I guess
01:44ak5normally there would be 2 unit test "lights"
01:44ak5?
01:44tomjackit's one big equality
01:44ak5oh
01:44ak5lol
01:44tomjackwhat you type goes in both blanks
01:44ak5haha ok I missed that
01:44ak5thanks sorry for wasting your time
01:44tomjack= can take multiple args
01:45ak5got it
01:45tomjackno need to apologize :)
01:46ak5tomjack: BTW, this all seems fairly academic, where do I start learning about clojure for the web?
01:47dyresharkak5: if you can grab an ebook version of the joy of clojure, that was my first resource
01:47dyresharkit's a great read imo
01:48ak5dyreshark: cool, thanks
01:55tomjackClojure Programming has two chapters about the web
01:57tomjackI think I'd start here though https://github.com/ring-clojure/ring/wiki
02:07ripplebitguys is clojure better than racket?
02:08FoxboronI'd say nothing is "better"
02:08krig_racket is a better racket than clojure, but clojure is a better clojure than racket
02:08Foxborondifferent tools, different job.
02:10dyresharkhttps://www.google.com/search?q=racket+vs+clojure <
02:18tomjackanyone have good indentation in *nrepl*
02:18tomjack(and more)
02:26derek_cin terms of style, when you want to declare a number of variables built on top of one another, what are you guys' take on nesting a bunch of `let` versus using `do` with a series of `def`?
02:28tomjackare you talking about inside a fn/defn?
02:29derek_cyeah
02:29tomjackdon't use def inside a fn/defn
02:29derek_ctomjack: why not?
02:29tomjackit is for defining top-level variables
02:30tomjackaka "vars"
02:30tomjacklet is not about vars
02:30derek_clet defines an immutable binding, right?
02:30tomjackright
02:31derek_cI just realize that in a let, you can refer to a binding in another binding
02:32derek_cso you don't really have to nest let
02:32derek_c(let [a 1 b (+ a 1)] b)
02:32scottjtomjack: briefly sampling nrepl.el fork network I didn't see any commits fixing indentation in *nrepl* fwiw
02:32derek_ctomjack: thanks!
02:32scottjI wish there were a way to search all commit messages of all forks of a repo
02:33tomjackah, I didn't think to check the fork network, good idea, thanks
02:33tomjackscottj: good project idea
02:33tomjack"a way to search.."
02:33scottjtomjack: yeah, the other feature I want is a way to view them w/o hovering the mouse of tiny dots :)
02:33tomjackyeah god it's horrible
02:34derek_cso is it idiomatic to use vectors as tuples?
02:35tomjackyes
02:35derek_cis it more efficient to pattern match against vectors than other collection types?
02:37tomjacknrepl just told me "you're bound to be unhappy if you optimize everything -- Knuth" :)
02:38tomjackthe cost of destructuring rarely enters my consideration - but perhaps your load is different
02:38derek_ctomjack: yeah I guess you are right :P
02:38SegFaultAXscottj: You can.
02:39SegFaultAXscottj: But why do you want to?
02:40scottjSegFaultAX: which feature are you responding to, the searching or the viewing?
02:41SegFaultAXderek_c: When you say pattern match do you mean destructuring or core.match?
02:41SegFaultAXscottj: Searching.
02:41scottjSegFaultAX: I see a way to search code for all of github or a repo. I don't see how to search commit messages for all forks of a repo. Can you point me where to look?
02:41derek_cSegFaultAX: I meant destructuring
02:41SegFaultAXscottj: Oh for all forks.
02:42SegFaultAXscottj: I misread, sorry.
02:43derek_cthat said, I just checked out core.match; looks pretty cool. reminds of of OCaml
02:43derek_c*reminds me of
03:07SegFaultAXderek_c: To answer your previous question, yes destructuring vectors is quite fast.
03:18tomjackconsider a function which takes a destination channel as an arg and puts messages asynchronously, returning a channel which indicates that it's done putting
03:19tomjackis there no easy way for this function to indicate that it's done if the destination channel is closed?
03:20tomjacki.e. the function will either be responsible for closing the dest itself, or its 'done' channel will potentially block forever
03:21tomjack(or the dest will never be closed)
04:16derek_cI'm doing some Java interop and just ran into a problem: so I'm trying to do this:
04:16derek_c(apply .register dir watcher types)
04:16derek_c.register is a method of dir
04:16derek_cbut the compiler says it's unable to resolve .register
04:17derek_cI could do (.register dir) with no problem
04:17derek_cbut apparently I can't use apply with .register
04:18derek_canyone knows how I would use apply in this case?
04:33amalloyyou can't apply java methods: they are not functions
04:34amalloyyou just have to figure out what args to call with, and manually unpack the seq yourself
04:39derek_camalloy: is that the only way? I don't think in my case it's possible to manually unpack the sequence, since it could be of any size
04:39amalloyderek_c: but there are only a limited number of overloads of the java method
04:40derek_camalloy: hmm you are right
04:41mthvedtderek_c: you can do a non-varargs call with into-array
04:41derek_cmthvedt: what do you mean?
04:41mthvedt(.register dir watcher (into-array types))
04:42mthvedtvarargs methods have non-varargs overloads that take arrays
04:42mthvedtit's been a while since i last used java though, don't quote me on anything
04:44derek_cmthvedt: into-array doesn't seem to do what I want
04:44derek_c(+ (into-array [1 2 3]))
04:44derek_cI thought this would return 6
04:45mthvedtclojure varargs are not the same as java varargs
04:46derek_cwow man it actually worked
04:47derek_cI still don't understand what's going on though
04:47derek_chow come the java method would accept an array?
04:49mthvedtderek_c: varargs in java is just syntax sugar
04:49mthvedtthe underlying method takes an array
04:50tomjackwhenever the javadocs say ...
05:23calvinxhey guys, I am trying out a super simple new clojure project created via "lein new app learnclojure" and I am not sure why my compiled jar fails to work - http://pastebin.com/dyUMadEJ
05:25calvinxwhat am I missing here?
05:28Foxboroncalvinx: try "lein uberjar"
05:28Foxboroncompile Compile Clojure source into .class files.
05:28Foxboronuberjar Package up the project files and all dependencies into a jar file.
05:28calvinxok. so what's the difference? between "lein compile; lein jar" and "lein uberjar" ?
05:29calvinxlein compile - ok, understood.
05:29calvinxlein jar?
05:29Foxboronuberjar also adds the clojure dependency
05:29Foxboronlein jar&compile dosnt
05:29Foxboroni think, i am not sure.
05:29calvinxok
05:31calvinxso what's the point of compile and getting .class files? (sorry, I am new to java)
05:31Foxboroni got no clue of java either :3 sorry
05:32FoxboronAFAIK, .class files only contains the actuall compiled code, but the code relies on the clojure api/lib.
05:32calvinx;D
05:32Foxboronso if you dont run the compiled code with the clojure dependency, clojure wont run.
05:32Foxboronagain, i am not sure ^^
05:32calvinxso you always do "lein uberjar" to test your project?
05:32Foxboronor use lein run
05:33Foxboronor write tests!
05:37calvinxok
05:37calvinxanother question
05:37calvinxis there an auto documentation tool in clojure land?
05:37Foxborongood question.
05:37calvinxin python land (where I come from), we use sphinx to extract docstring
05:38calvinxand make any modifications to the documentation source as restructured text
05:38calvinxwhich can be compiled into html as needed.
05:38Foxboronwell, java got javadoc
05:38Foxboronbut i am not sure if there is something for clojure
05:38Foxboron(also python guy btw)
05:38calvinxoo. nice. :)
05:38calvinxI see that when I start a new project with lein,
05:38calvinxa "doc" directory is created.
05:38calvinxand inside it is one single markdown file.
05:39calvinxso my question is, what is a systematic way of extending more documentation files
05:39calvinxand whether there's an "docstring" extractor.
05:39Foxboronwell, i don't know. So i am googling atm
05:39calvinxhttp://stackoverflow.com/questions/5334525/state-of-the-art-for-clojure-documentation-tools
05:39Foxboronhttp://tomfaulhaber.github.io/autodoc/
05:40Foxboronoh, nice. Gotta save that tool for later
05:55schmirhow do I catch any exception? does (try ... (catch Exception err ....)) do that? or are there other classes of exceptions that could be thrown?
05:57tomjackhttp://docs.oracle.com/javase/6/docs/api/java/lang/Throwable.html
05:57tomjackgenerally you should not catch all throwables
06:04schmirtomjack: thanks.
06:47fikuszI'm working on a huge messy parsed html structure right now and it's really hard to explore in the repl (because even the subtrees are very large and are full of junk)
06:48fikuszIt would help if I could explore it like I would with firebug
06:48fikuszanything like that for clojure objects?
08:25sandbagsI'm doing the clojure koans and come to the first map example and hit a snag -- https://gist.github.com/anonymous/ee47d4ef24f9c2a04c9b -- i'm sure i've just done something stupid but i can't see it, can anyone help me?
08:34hyPiRionsandbags: It's actually very easy
08:34hyPiRion,(hash-map :a 1 :b :2)
08:34clojurebot{:a 1, :b :2}
08:34hyPiRionnote the colon before the 2?
08:34sandbagsyes
08:34sandbagsah goddamnitall
08:34hyPiRionheheh
08:34sandbagsthank you
08:35hyPiRionthose darn small mistakes, egh
08:35hyPiRion*eh
08:35sandbagsthe eye does not see what the brain does not want to see :)
08:35hyPiRionyeah
08:35sandbagsthanks again
08:35sandbagsthe worst part is that i typed it that way at least once more
08:36sandbagswhen i tried to verify it in LightTable
08:36sandbagsstupid brain
08:36sandbagsi shall kill you with beer
09:05jballanchmm...what do people usually do when they have config that applies only to "test" mode?
09:07callenjballanc: config of what?
09:08callenjballanc: typically you're talking env vars.
09:13jballancyeah, currently I have a configs.clj that switches on a env var
09:13jballancjust seems slightly inellegant
09:14jballanchmm...I wonder if I could use lein profiles to load only one version of config.clj depending on the profiles used?
09:27jballancah, this seems like it might do the trick: https://github.com/weavejester/environ
09:28mpenetyup, environ is perfect for that
10:00Okasu,(resolve 'call-cc)
10:00clojurebotnil
10:00Okasu&(resolve 'call-cc)
10:00lazybotjava.lang.SecurityException: You tripped the alarm! resolve is bad!
10:02Okasu&(eval 1)
10:02lazybotjava.lang.SecurityException: You tripped the alarm! eval is bad!
10:08Okasu&clojure.core$resolve
10:08lazybotjava.lang.SecurityException: You tripped the alarm! resolve is bad!
10:32Okasu&((defmacro meh [] `(~(symbol (str "res" "olve")))) '() '())
10:32lazybotjava.lang.SecurityException: You tripped the alarm! def is bad!
12:11jjttjjI'm trying to use lein-beanstalk and am pretty clueless. I have template .html files in my src directory that don't seem to be getting included in the WAR. How do I include them?
12:13llasramjjttjj: Usually those sorts of files would go into a `resources` directory. That may not be the problem though, as generally everything in `src` would also end up in your JAR/variant
12:14jjttjjllasram: yeah I guess I was just wondering if that sounded like it might be the problem. Thanks for the input I'll mess around some more
12:29jjttjjis there any obvious reason I might be getting a FileNotFound exception on a file in my src directory when deployed with lein-beanstalk, when things work fine locally?
12:29n_bProbably something funky with relative v. absolute paths?
12:30n_bOr file case sensitive FS on dev but not prod, or the opposite
12:30xpewhat is the recommended way to rename something from clojure core in your namespace?
12:30xpeI see `(:refer-clojure :exclude [ancestors printf])` that's not quite it
12:30n_bThose are the first two things I check jjttjj
12:30xpeI also see `refer` + :rename
12:30jjttjjn_b: thanks!
12:31n_bxpe: http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/refer
12:33xpen_b: thanks. I think I like (ns my.core (:refer-clojure :rename {inc core-inc}))
12:36n_bif you only need to change stuff in core, it's the way to go
12:37n_bThough I think it runs the risk of others having to check the docs to figure it out, I'm always of two minds about using shortcuts like that
12:38jjttjjsorry for the stream of noob questions, but what IS the ideal way to refer to files in a project-relative way?
12:39jjttjjI was just using relative path to the project which works locally
12:39n_bjjttjj: I honestly don't know, I was hoping someone would chime in, since I have a similar problem!
12:42tmcivern_b, jjttjj: I believe you use resource: http://richhickey.github.io/clojure/clojure.java.io-api.html#clojure.java.io/resource
12:43tmciverI believe it searches for the given resource on the classpath and you can give it a path relative to one of the paths on the classpath.
12:49noncomanyone is familiar with Quil?
12:53llasramnoncom: A tiny bit
12:55noncomllasram: the trouble is when i call like quil/rect from another thread, it gives an NPE coz, i guess, *applet* is null
12:56noncomi think it's more about dynamic vars but still..
12:57noncomcalling it from the same thread/namespace is fine
12:58llasramYep. The API isn't designed to support calling sideffecting functions from multiple threads
12:58llasramYou might be able to cheat by passing the *applet* around and `binding` it in your other thread, but I don't know if the underlying Processing calls are thread-safe
12:59llasramWhy do you want to draw from multiple threads though?
13:00noncomllasram: I am using processing to display some info on my application, but it is not the main screen, the main screen is a different opengl engine. I use processing because of it's simplicity here. all is fine except for this issue.
13:01llasramCould you just deliver what needs to be drawn to the Processing thread, and let that thread handle it?
13:03noncomllasram: if i know how to do it. actually the drawing functions themselves must be made in another thread. i mean, i do not know what drawing functions will be ahead of tie
13:03noncom*time
13:04noncomllasram: if you tell me the clojure way to handle this, i'll use it
13:05noncomthe basic problem that i envision is that idk how will it resolve like "rect" function to belong to quil if it is created in another ns and passed to that obe
13:05noncom*one
13:05llasramMaybe an agent? Your processing rendering function get the agent state to know what to draw. Heck, that "state" could even just be functions to call. You can then update that state from any other threads
13:09noncomllasram: right, but how to make it understand that the "rect" function present in the agent state refers to the quil function, that very quil which is required in the namespace?
13:09llasramUh. Well, the `rect` function you call needs to be the quil rect function. Require the namespace, call the function
13:13noncomllasram: so, I req the ns both in the processing thread and in the other thread. I create the call '(quil/rect) in the other thread, and when unqoted and executed in the processing thread, it will automatically resolve all as needed?
13:13noncomor maybe better store it like #(quil/rect)?
13:14llasramYou seem to have some confusion regarding threads and namespaces
13:14llasramNamespaces aren't tied to a thread
13:15llasramWhatever functions you have now which perform quil rendering, you just need to ensure that those functions are called by the thread quil/processing sets up as the rendering thread
13:15llasram(Or restructure if rendering is mixed in with other logic, obvs)
13:23noncomllasram: ok i'll try
13:31noncomllasram: what is the syntax to pass several expression for evaluation in a different thread?
13:31noncomor, what is the same in this case - in a different ns
13:32bbloom(doc future)
13:32clojurebot"([& body]); Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block, unless the variant of deref with timeout is used. See also - realized?."
13:33noncombbloom: oh, not any thread, but a particular one. acually, i have to somehow pass expressions to another namespace so it executes them with it's own var bindings
13:34bbloomnoncom: eval in a namespace and in a thread are two different things
13:34xpeusing `recur` inside `lazy-seq` doesn't work. looks like I have to use the named function instead
13:34bbloomxpe: yes, becuase lazy-seq creates a (fn [] …thunk….)
13:34bbloomxpe: recur is turned into a loop, but you want laziness, not a loop
13:35bbloomxpe: you won't overflow the stack that way, since the thunk is evaluated later, after the original function has been popped off the stack
13:35xpebbloom: thanks… a little unexpected at first, but I think I'll get it soon
13:36noncomehh...
13:39bbloomxpe: try a macroexpand, it will make it obvious :-)
13:39bbloom,(macroexpand '(lazy-seq [1 2 3]))
13:39clojurebot(new clojure.lang.LazySeq (fn* [] [1 2 3]))
13:40xpebbloom: we might have differing ideas of obviousness
13:40xpehaha
13:40xpebut thanks, I've making good headway
13:40bbloom(doc recur)
13:40clojurebotIt's greek to me.
13:40bbloom&(doc recur)
13:40lazybot⇒ "Special: recur; Evaluates the exprs in order, then, in parallel, rebinds\n the bindings of the recursion point to the values of the exprs.\n Execution then jumps back to the recursion point, a loop or fn method."
13:41xpegood headway, without holding my head, too
13:41bbloomjust gotta be unafraid to explore in your repl & these things will become clear
13:42bbloom,(macroexpand '(lazy-seq (recur 1 2 3)))
13:42clojurebot(new clojure.lang.LazySeq (fn* [] (recur 1 2 3)))
13:42bbloom,(fn* [] (recur 1 2 3))
13:42clojurebot#<CompilerException java.lang.IllegalArgumentException: Mismatched argument count to recur, expected: 0 args, got: 3, compiling:(NO_SOURCE_PATH:0:0)>
13:42bbloom,(fn* [] (recur))
13:42clojurebot#<sandbox$eval85$fn__86 sandbox$eval85$fn__86@1ca1bde>
13:42bbloom,((fn* [] (recur)))
13:42bbloom^^ timeout
13:42clojurebotExecution Timed Out
13:44xpebbloom: thanks for the suggestions. I got it worked out now
13:45xpeit was a set combinatorics function slightly different than math.combinatorics. a fun problem
13:55lynaghk`Is there any strong reason to use Nginx in front of Jetty for a Compojure app? I've already got Jetty configured to gzip responses.
14:04bbloomlynaghk`: nginx won't modify the http requests you proxy through without extra instruction
14:04bbloomlynaghk`: so it's only useful if your config does something interesting
14:05llasramStatic resource files -- nginx or apache can serve static files from disk much more efficiently
14:05bbloomlynaghk`: also useful if you want to virtualize your 80 and 433 ports by post for backends that are not all jetty
14:06bblooms/post/host
14:06bbloomor hostname rather
14:12lynaghk`llasram: I've heard that but never actually seen numbers anywhere
14:12lynaghk`bbloom: not sure what you mean---load balancing?
14:13bbloomlynaghk`: i'm saying that if your server is running multiple services on a virtual host, ie foo.com and bar.com both on port 80, then you should have nginx do that
14:16lynaghk`bbloom: oh, yeah. totes. Nah, this is for a site that I expect to just get a few hundred or thousand hits a day that I can just throw on a vps all by itself
14:16bbloomyeah, jetty can do the job just fine
14:16lynaghk`so I don't need anything like that; I'll give plain Jetty a shot
14:16lynaghk`bbloom: do you have any experience setting up SSL certs with Jetty?
14:16bbloomlynaghk`: no, and that brings up the MOST IMPORTANT REASON to use nginx instead of jetty wherever possible: no xml :-)
14:17lynaghk`bbloom: ha
14:18hiredmanif you terminate ssl before jetty it is harder to do things like authenticate via client side certs
14:19llasramlynaghk`: that's a good point, but it at least in theory could be significant. Linux (and I think *BSD?) have a `sendfile` system call which allows the kernel to directly copy data from one file descriptor to another, entirely bypassing user space and skipping at least one extraneous copy
14:20bbloomlynaghk`: the absolute easiest way to configure ssl is with stunnel
14:20bbloomlynaghk`: the config file is like 4 lines
14:21bbloomit's like path-to-cert, path-to-key, in-port, out-port. DONE!
14:26lynaghk`bbloom: I'll take a look at that if Jetty gives me trouble, thank
14:26lynaghk`*thanks.
14:47derek_cI'm trying to translate a piece of Java code to Clojure. here is a part of it:
14:47derek_cFileSystems.getDefault().newWatchService()
14:47derek_cshould this be: (.newWatchService (.getDefault FileSystems))
14:47derek_c?
14:47bbloom(doc ..)
14:47clojurebot"([x form] [x form & more]); form => fieldName-symbol or (instanceMethodName-symbol args*) Expands into a member access (.) of the first member on the first argument, followed by the next member on the result, etc. For instance: (.. System (getProperties) (get \"os.name\")) expands to: (. (. System (getProperties)) (get \"os.name\")) but is easier to write, read, and understand."
14:48bbloombut i think you need: (.newWatchService (FileSystems/getDefault))
14:52derek_cbbloom: ah I didn't know that
14:53derek_chow is (.. FileSystems (getDefault) (newWatchService)) different from that you suggest?
14:53bbloom(doc .)
14:53clojurebotExcuse me?
14:53bbloom&(doc .)
14:53lazybot⇒ "Special: .; The instance member form works for both fields and methods.\n They all expand into calls to the dot operator at macroexpansion time."
14:53bbloomnotice it says "fields and methods"
14:53bbloomit probably should say INSTANCE fields & methods
14:54bbloomyou use / for static stuff
14:54bbloomwith static stuff, think of the class name as being a mini-namespace
14:56noncomok, I can't make it. what is the way to request a *variable* binding from some thread to be valid in another thread?
14:56bbloomby *variable* do you mean a dynamic var?
14:56noncomyeah
14:57bbloomsee the docs for binding, bound-fn, with-bindings, etc
14:57bbloombut what are you trying to accomplish anyway?
14:58noonianare you trying to share data between threads?
14:58derek_chmm the compiler is giving me this strange error:
14:59derek_cIllegalArgumentException No matching method found: get for class java.lang.Class clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:53)
14:59derek_cit doesn't even give me a line number
14:59derek_cdoes anyone know what could be going on?
14:59bbloomderek_c: try to invoke smaller and smaller bits of code in the repl until you narrow it down
15:04noncomthe quil library is structured in a way that every drawing function refres to the local binding of the graphics context. somehow i need to be able to execute drawing instructions, created elswhere, from another thread. what is the syntax to pass them to the quil thread so they execute at their time and with the correct context binding... sorry this may sound obscure..
15:05noncomi guess i can use an atom or an agent to pass the instructions between threads, ok
15:10avishaihi
15:10avishaihow do i force realization of a lazy-seq?
15:10Bronsacall seq on it
15:10avishaispecifically (map str (partition 6 "TESldjdflsdjflkjdsflkjalkfdjfkljadsfkljadklfj"))
15:10avishaiwill return a list of lazy seqs
15:10Bronsaor doall
15:11avishaidoall doesn't work
15:11avishaitried it
15:11nooniantry (into [] (map str (partition ...)))
15:11avishaiugly
15:11avishaidoesn't work either
15:12Bronsa,(map pr-str (partition 6 "TESldjdflsdjflkjdsflkjalkfdjfkljadsfkljadklfj"))
15:12clojurebot("(\\T \\E \\S \\l \\d ...)" "(\\d \\f \\l \\s \\d ...)" "(\\f \\l \\k \\j \\d ...)" "(\\f \\l \\k \\j \\a ...)" "(\\k \\f \\d \\j \\f ...)" ...)
15:12Bronsait's not lazyness your problem
15:13avishaiwhats pr-str?
15:13Bronsa,(doc pr-str)
15:13clojurebot"([& xs]); pr to a string, returning it"
15:13Bronsa,(doc pr)
15:13clojurebot"([] [x] [x & more]); Prints the object(s) to the output stream that is the current value of *out*. Prints the object(s), separated by spaces if there is more than one. By default, pr and prn print in a way that objects can be read by the reader"
15:14avishai (map str (partition 6 "TESldjdflsdjflkjdsflkjalkfdjfkljadsfkljadklfj"))
15:14avishai("clojure.lang.LazySeq@c83101f1" "clojure.lang.LazySeq@e55b0b10" "clojure.lang.LazySeq@e918b335" "clojure.lang.LazySeq@e918b2d1" "clojure.lang.LazySeq@f14932e7" "clojure.lang.LazySeq@f334f775" "clojure.lang.LazySeq@f1a05820")
15:14noonian(partition 6 "TESldjdflsdjflkjdsflkjalkfdjfkljadsfkljadklfj")
15:14noonian,(partition 6 "TESldjdflsdjflkjdsflkjalkfdjfkljadsfkljadklfj")
15:14clojurebot((\T \E \S \l \d ...) (\d \f \l \s \d ...) (\f \l \k \j \d ...) (\f \l \k \j \a ...) (\k \f \d \j \f ...) ...)
15:15avishaii thought this was due to repl expanding lazy-seqs
15:16avishaiso, how do i convert character list to string? map str?
15:17Bronsaoh, that's what you want
15:17avishaihmm reduce str
15:17Bronsa,(map (partial apply str) (partition 6 "TESldjdflsdjflkjdsflkjalkfdjfkljadsfkljadklfj"))
15:17clojurebot("TESldj" "dflsdj" "flkjds" "flkjal" "kfdjfk" ...)
15:17noonianyup
15:17avishai(map (comp reduce str) (partition 6 ...
15:17avishaia bit ugly
15:17avishaibut works
15:21avishaiis there a function to get the arity of a function?
15:23avishai(comp reduce str) doesn't work
15:23avishaii get ArityException Wrong number of args (1) passed to: core$reduce'
15:23noonian,(map #(apply str %) (partition 6 "TESldjdflsdjflkjdsflkjalkfdjfkljadsfkljadklfj"))
15:23clojurebot("TESldj" "dflsdj" "flkjds" "flkjal" "kfdjfk" ...)
15:23dnolen_avishai: you want (apply str ...) anyway
15:26avishaiisn't apply unefficient with big lists?
15:26avishaimy actual use case is partition 60
15:26dnolen_avishai: it is efficient
15:27avishaii read in the clojure book that apply performance starts to degrade after list size of about 4
15:27dnolen_especially apply str as it will use a StringBuilder internally
15:27avishaihuh
15:27avishainice to know
15:28noonianfunctions that take arbitrary numbers of args see those args as a seq, which I sure hope are efficient in clojure :p
15:28dnolen_avishai: in general reduce is the way to go, but apply str is optimized
15:28avishaiwhat i don't get
15:28avishaiis why #(apply str %) works
15:29avishaiand (comp apply str) doesn't
15:30noonianyou want partial, not comp, (comp f g) is like (fn [x] (f (g x))) I believe (I've never used comp so I could be wrong)
15:30gfredericksavishai: (comp apply str) is roughly equivalent to #(apply (str %))
15:31xiloi'm using vim-fireplace and wondering what's the best way to get lein repl headless to start so i don't have to do it manually
15:31noonianso (partial apply str) returns something like (fn [args] (apply str args))
15:31avishaiah
15:31avishaigot partial and comp mixed up
15:31avishaisorry
15:32avishai10x a billion
15:36creeseHas anyone tried python/fn?
16:21weavejesterI'm considering writing a library for generating unique fingerprints for Clojure data structures. Any ideas for names? The best I can think up is "fingerprint" or "data-fingerprint" :)
16:21fbernierhow would you explain in a couple of sentences how immutable and persistent data structures help with concurrency?
16:23weavejesterConcurrency issues occur when data changes.
16:23noonianif a data structure is immutable, you can freely pass it between threads without worrying about it ever changing
16:23noonianno need for locks, etc.
16:24fberniermakes sense, thanks
16:30amalloyweavejester: more unique than hashes? like actually-unique?
16:31technomancyweavejester: I'd suggest loop, whorl, or arch, but two of those are taken
16:32amalloyweavejester: gfredericks has some code that you could probably get some interesting ideas from, even if there's nothing you can steal outright: https://github.com/fredericksgary/bijector
16:32weavejesteramalloy: Essentially it would walk a tree and replace maps and sets with sorted versions in order to get a canonical ordering, and then it would serialize and hash the result.
16:33fbernierso... clojure sequences ... is it a data structure ?
16:34weavejestertechnomancy: Whorl might be a good name. There's a js project on github, but it has only 3 watchers and hasn't been touched in 3 years.
16:35weavejesterfbernier: More like an abstraction I guess.
16:39fbernierweavejester: I'm having difficulties finding the easiest words to describe what it is.
16:39fbernierboth for myself and for the crowd to whom I'll try to explain it.
16:41weavejesterfbernier: Not sure. Perhaps say it's an interface that allows a data structure to be iterated over sequentially, though that's not the complete truth.
16:42fbernieryeah I think that's what I'll go with
16:43SegFaultAXSequences provide the base iterator protocol for Clojure.
16:43SegFaultAXSimilar to #each in Ruby, or __iter__/__next__ in Python.
16:44weavejesterBut better :)
16:44nooniana particular sequence is a data structure, but many different types of data structures are sequences
16:44SegFaultAXAs long as some data type implements that protocol correctly, it benefits from the vast number of functions that also speak the protocol.
16:44clojurebotyour random number generator is brokem
16:44weavejesterI think there are some slides about the deficencies of the classic iterator model
16:44SegFaultAXLike Enumerable in Ruby.
16:45fberniergreat I get it better now
16:45fbernierthanks
16:45SegFaultAXIn Ruby, if I simply implement #each, I can mixin a huge amount of functionality for free.
16:45SegFaultAXAnd the only thing I've described is how to emit values from my data type.
16:45SegFaultAXIt implies nothing about the structure of that data, ordering, etc.
16:46SegFaultAXClojure sequences have the same benefit (as does Python's __iter__/__next__) but, as weavejester said, it's even better.
16:46fbernierImproving my knowledge of ruby while learning Clojure, nice.
16:47SegFaultAX:)
16:47SegFaultAXJust doing my part.
16:48weavejesterI guess the main benefit of seqs over iterators is that they're effectively stateless.
16:49SegFaultAXweavejester: Well I'm talking about the /process/ of iteration. Not iterators as such.
16:49fbernierSegFaultAX: "Writing a talk about Clojure for Ruby developers is slightly less than than I had originally anticipated. #clojure"
16:49fberniergot slides? :)
16:50SegFaultAXfbernier: Still working on them!
16:50fbernierok
16:50fbernierwill be doing a similar talk to a half-ruby crowd too tuesday
16:51SegFaultAXfbernier: Then I would at least start by drawing the similarities between seqs and Ruby's internal iteration protocol via #each
16:51SegFaultAXAnd the tremendous benefits therein.
16:51fbernierUnsure I want to go in such details
16:51fbernierother than the couple sentences definition you gave
16:52SegFaultAXfbernier: You can do it in 5 sentences, as I did above.
16:52fbernierah ok
16:52SegFaultAXfbernier: Feel free to copy paste. Just throw an @SegFaultAX in the credits. :)
16:52fbernierhaha great ;)
16:54SegFaultAXfbernier: Not sure the context of your talk, but I expect the people I'm presenting to to have a relatively high degree of understanding of Ruby. So I can lean pretty hard on that assumption when explaining things like this.
16:54SegFaultAXfbernier: Tailor your presentation to suit your expected audience.
16:54fbernierIt'll be a mixed crowd ... so I won't be assuming so much
16:55fberniersome .net, php devs
16:55fbernierbut mostly rubyists or ruby enthusiasts
17:01fbernierI thought after solving 76 problems on 4clojure I would have the required knowledge to give a presentation to newbies
17:01fbernierBut I realize I can't explain lots of stuff without reading on it :P
17:03bbloom4clojure is great for learning clojure in the small, but the only way to learn clojure in the large is to work with it for a while
17:03fbernierYeah probably.
17:03bbloomdid you watch the videos we recommended?
17:04fbernierI wouldn't be here trying to learn more about it if it wasn't for 4clojure though :)
17:04fbernierbbloom: not yet :( ... will do
17:05kmicuunicorns are real, but php devs exist!? http://i.imgur.com/NQHKSVE.gif
17:07fbernierwe need them to make all those wordpress sites while we work on cooler stuff
17:08fbernierthis gif is so overused but it represents exactly what learning clojure feels like: http://i.imgur.com/UmpOi.gif
17:09SegFaultAXfbernier: Relevant xkcd http://xkcd.com/224/
17:10rurumateWhere's the 'clojure compiler in clojure' project?
17:11kmicu$google clojure in clojure
17:11lazybot[Clojure - todo] http://clojure.org/todo
17:11kmicuI have another google https://github.com/cosmin/clojure-in-clojure
17:12rurumatelooks not overly active
17:13rurumateNeeds proper bytecode generation library first, I think
17:14kmicuhttps://groups.google.com/forum/#!topic/clojure-dev/puJ1PBEEsow
17:14Bronsakmicu: I'm working on completing Aaron's CinC as my GSoC project
17:15kmicuAnd GSoC...
17:15Bronsahttps://www.google-melange.com/gsoc/homepage/google/gsoc2013
17:18kmicutmux select-window -t :0
17:20rurumatewhat about rich hickey, he not interested in that
17:21bbloomrurumate: he is, but he's got a lot of stuff to work on :-)
17:21rurumatebbloom: at least he could mentor it or something
17:22bbloomand to be fair, he basically already DID write clojure-in-clojure when he wrote clojurescript ;-)
17:22SegFaultAXbbloom: Does he still hack on cljs?
17:23bbloomSegFaultAX: git log says his last commit was in 2011
17:24SegFaultAXI wonder if he's like 100% focused on trying to make Datomic happen.
17:24SegFaultAXI really wish it was open source. :(
17:24bbloomSegFaultAX: well, he's been actively contributing to core.async
17:27jtoywhat is the recommended time/date library to use with clojure, it seems like clj-time ?
17:28bbloomjtoy: the ONLY correct answer for java is joda time & clj-time is a Joda wrapper
17:29bbloomi dunno if clj-time is good, but joda is great, so that's a good start
17:29SegFaultAXclj-time mostly does a pretty good job.
17:29jtoybbloom: ok thanks, i've never really used java until clojure, and im not even sure if this counts as "using java"
17:29SegFaultAXJoda is excellent.
17:29SegFaultAXjtoy: It's all just Java :)
17:35jtoydoes clojure have a debugger? it seems painful to debug when i want to just inspect a data structure
17:36manutter51jtoy: seen the clojure.inspector namespace?
17:37jtoymanutter51: i havent, thx
17:37kmicuREPL is not good enough?
17:38manutter51must be pretty good, I almost never hear anyone talk about using clojure.inspector.
17:38nooniani'd never heard of it either
17:39jtoykmicu: how? sometimes the code is nested deep, i do use the repl for everything, but it is painful when dealing with many layers
17:39jtoyinstead it would be so much easier to be at the point right before the error happens
17:39noonianbut seems useful for inspecting deeply nested structures
17:52jtoydo you guys see a better way to do this in clojure: https://www.refheap.com/16043 i want to have integers in the format of YYYYMMDD so I can compare them, sort them, etc
17:53SegFaultAXjtoy: Use a date/time format.
17:54SegFaultAXjtoy: If you're using clj-time's formatter.
17:54jtoySegFaultAX: i was thining that earlier, im not using the formatter at all
17:55SegFaultAXjtoy: You should be.
17:55jtoyok
18:06jtoyhow can I return a hash-map from a mapping call? Im trying to do (map #( {:date (first %) :count (-> % last count) }) (group-by identity favs)) ; but get ArityException Wrong number of args (0) passed to: PersistentArrayMap clojure.lang.AFn.throwArity (AFn.java:437)
18:06bbloomjtoy: #() implies a call, you're trying to call a map
18:06bbloom,'#({:foo :bar})
18:06clojurebot(fn* [] ({:foo :bar}))
18:06bbloomsee?
18:07bbloomyou can use #(hash-map …) or use fn directly
18:07bbloomthere is also the -> trick
18:07jtoybbloom: so #() must run a function?
18:07jtoybbloom: what would i do with the -> trick here?
18:08bbloom,(map (fn [x] (vector x)) [5 10 15])
18:08clojurebot([5] [10] [15])
18:08bbloom,(map #(vector %) [5 10 15])
18:08clojurebot([5] [10] [15])
18:08bbloom,(map #([%]) [5 10 15]) ; ugh oh!
18:08clojurebot#<ArityException clojure.lang.ArityException: Wrong number of args (0) passed to: PersistentVector>
18:08bbloom,(map #(-> [%]) [5 10 15]) ; ugh oh!
18:08clojurebot([5] [10] [15])
18:08bbloomget it?
18:09hyPiRionoh just, (shocker) ##(map vector [5 10 15])
18:09lazybot⇒ ([5] [10] [15])
18:09bbloomhyPiRion: heh, well yes. of course
18:09jtoy ,(map #(-> {%}) [5 10 15])
18:09clojurebot#<RuntimeException java.lang.RuntimeException: Map literal must contain an even number of forms>
18:09jtoy ,(map #(-> {:test %}) [5 10 15])
18:09clojurebot({:test 5} {:test 10} {:test 15})
18:09jtoyah, cool
18:09bbloom,(map #(-> [1 (inc %) 2 (dec %) 3]) [5 10 15]) ; just for hyPirion
18:09clojurebot([1 6 2 4 3] [1 11 2 9 3] [1 16 2 14 3])
18:10xpewhat's a good way to fork a clojure library and use one's modifications? e.g. I want to apply this patch: http://dev.clojure.org/jira/browse/MCOMB-2
18:10bbloomjtoy: some people think that the #(-> thing is an ugly evil sin. I don't :-P
18:10xpei don't really want to push to clojars
18:10jtoyxpe, you can require any library on clojars including your own even if it is a fork
18:10jtoybbloom: why? I loveusing -> for everything
18:10hyPiRionbbloom: ##(map (juxt (constantly 1) inc (constantly 2) dec (constantly 3)) [5 10 15])
18:10lazybot⇒ ([1 6 2 4 3] [1 11 2 9 3] [1 16 2 14 3])
18:10hyPiRion~juxt
18:11clojurebotjuxt is a little hard to grok but it's the best thing ever
18:11xpejtoy: is there an easy way just to pull from a local git repository without pushing to clojars?
18:11bbloomhyPiRion: i knew you'd try that, that's why i added those constants in there: to make your approach seem ridiculous :-)
18:11hyPiRionhrm
18:11bbloomjtoy: people think that (-> x) is stupid b/c it's equiv to just x
18:11jtoyxpe, im not sure, i havent tried it
18:12bbloom#(-> %) is basically just identity
18:12jtoybbloom: oh, i see
18:12bbloombut #() CALLS SOMETHING
18:12n_bxpe: Check out "checkouts" in the lein docs
18:12bbloomso calling -> to get identity is an ugly hack to some people. they would rather you use (fn [x] {:foo x})
18:12jtoy#() vs (fn[x]) are things i dont really want to care about
18:13hyPiRion,(map (comp (partial interleave [1 2 3]) (juxt inc dec)) [5 10 15])
18:13bbloomyeah, use whatever makes sense to you :-)
18:13clojurebot((1 6 2 4) (1 11 2 9) (1 16 2 14))
18:13jtoyi like the -> % trick bc its shorter
18:13hyPiRionoh dangit.
18:13hyPiRionI give up this time.
18:13bbloomheh :-)
18:13n_bxpe: Note it's a Bad Thing™ to do production stuff like that, you should push it to a local maven repo or something if at all possible
18:13xpen_b: trademark noted thanks :)
18:25jtoyif i have to vectors of hashmaps such as [{:a 1 :b 2 } {:a 3 :b 2 ] and [{:a 1 :c3}{:a 2 :c 2 }] how can I merge them so I get [{:a 1 :b 2 :c 2} {:a 2 :b 0 :c 2} {:a 3 :b 2 :c 0} ] ?
18:26bbloommap accepts mutliple sequences to map in parallel
18:26jtoyi think i have to do a group by and then merge?
18:27bbloom,(map - [5 10 15] [2 3 4])
18:27clojurebot(3 7 11)
18:27jtoythey are unordered, i dont think i can use map in this situation
18:28bbloomthen your example is not clear
18:28n_bso you want to merge each map?
18:28jtoyhow about now: [{:a 1 :b 2 } {:a 3 :b 2 }] and [{:a 2 :c 2 } {:a 1 :c3}] how can I merge them so I get [{:a 1 :b 2 :c 2} {:a 2 :b 0 :c 2} {:a 3 :b 2 :c 0} ]
18:28n_bcan you not map merge-by across both seqs?
18:29jtoyI want to gropu-by a key (a) so i have a b c, then for each of the a's, I want to merge in the results from b and c
18:30jtoya is unique in each vector
18:42jtoyi wrote some really ugly code to do it
18:43jtoy(map #(-> {:a (first %) :b (reduce + (map (fn[x] (x :b 0)) (-> % last))) :c (reduce + (map (fn[x] (x :c 0)) (-> % last))) }) (group-by :a (concat cs bs)))
18:44xpewhat's up with projects like https://github.com/clojure/math.combinatorics/ that don't have a project.clj ?
18:44jtoythat is uggggggllllyyyyy
18:44xpeis there a good reason to not have one or are they pre-lein?
18:45amalloyxpe: clojure.contrib projects are managed by clojure.core, and they seem uninterested in adopting lein
18:45amalloyjtoy: just write a version of group-by that takes two functions, one for grouping and one for combining
18:45xpeamalloy: ok, so if I want to fork and test, run the repl, etc. what do I do?
18:46xpepom.xml. smells bad.
18:46amalloysob, really. but mvn package probably makes a jar
18:46amalloymvn test will run tests
18:46amalloyjtoy: i have one of those around somewhere, but i dunno where
18:46xpeamalloy: thanks, I won't blame the messenger :)
18:47jtoyamalloy: write my own group-by? does that mean i need to understand the original group-by so i can write a new version, or can i add my functionality to it?
18:47amalloyyou should understand the original group-by whether you're rewriting it or not
18:47amalloyit's a pretty basic, important technique
18:48jtoycool
18:48ivaraase1amalloy: isn't there a snippet to convert a pom.xml into project.clj as well?
18:48amalloy*shrug*
18:53xpeivaraase1: that would be nice. I just rearranged math.combinatorics to work with a project.clj I just made
19:03hyPiRionthis is why we all should change to lein-pom
19:05hyPiRion*lein-xml, rather
19:05hyPiRionhttps://github.com/technomancy/lein-xml
19:08ivaraase1hyPiRion: sorry, not enterprise grade at all. too few tags.
19:36Morgawrbest way to return a dictionary with only the specified keys?
19:36ghadiMorgawr: select-keys
19:37Morgawrthanks
19:43bprcemerick: ping
20:33xpedoes clojure or clojure test have a wrapper compare doubles within some precision? or I'll just do - and < 0.001
20:42n_b,(doc with-precision)
20:42clojurebot"([precision & exprs]); Sets the precision and rounding mode to be used for BigDecimal operations. Usage: (with-precision 10 (/ 1M 3)) or: (with-precision 10 :rounding HALF_DOWN (/ 1M 3)) The rounding mode is one of CEILING, FLOOR, HALF_UP, HALF_DOWN, HALF_EVEN, UP, DOWN and UNNECESSARY; it defaults to HALF_UP."
20:43xpen_b: that's useful but I'm going with: https://gist.github.com/xpe/5847084 for functions that return doubles
20:44xpeI seem to recall reading that with-precision is about presentation only -- I will need to verify that
20:46tomjack&(= 2M (with-precision 1 (+ 1.1M 1.1M)))
20:46lazybotjava.lang.SecurityException: You tripped the alarm! pop-thread-bindings is bad!
20:47tomjack,(with-precision 1 (+ 1.1 1.1))
20:47clojurebot2.2
20:49xpe,(with-precision 1 2.7182818284590455)
20:49clojurebot2.7182818284590455
20:54cbp`how can i abort evaluation in lein repl
21:14derek_cI'm doing some Java interop and just got a problem. So I have this overloaded Java method that takes either a String or another type. I'm calling this Java method with a string, but for some reason the Clojure compiler insists on using the version of the method that takes another type. Does someone know what I should do?
21:17bbloomderek_c: use type hints and/or a casting function
21:17bbloomif you want an int, for example (int x) there are functions for all the primitives & primitive arrays.
21:17bbloomif you have a class instance, use (cast TheClass x)
21:18derek_cso I want to use the String version, should I do this?
21:18derek_c(Paths/get (cast String path))
21:19derek_cdoesn't seem to work; it's still calling another version
21:19amalloybbloom: (cast foo bar) doesn't do anything
21:19bbloomamalloy: oh… derek_c ignore me
21:19amalloyfor reflective lookup, that is
21:19bbloomthen he has to use a type hint?
21:19amalloyyes
21:19bbloomi was under the impression that the compiler hinted cast calls. i guess i just imagined that
21:20bbloomi guess int, long, double, etc must be hinted b/c the types are known statically
21:20derek_cwait what do I do?
21:20amalloy(Paths/get ^String path)
21:22bbloomoh, that won't work
21:22bbloomderek_c: the issue you have is that you're trying to call a variadic function
21:22derek_chmm yeah... still the same error
21:22bbloomthe signature of get is (String first, String… more)
21:22bbloomwhich is just suggar for (String first, String[] more)
21:22bbloomthere is no 1-arg version (String first)
21:22RaynesI suspected that.
21:23bbloom(java.nio.file.Paths/get path (make-array String 0))
21:23bblooms/suggar/sugar
21:24derek_cbbloom: aha now that works
21:24derek_cthanks man
21:24bbloomnp
21:25derek_cit's weird cuz the Java code I'm looking at is simply calling the function with one string
21:25bbloomyes, the java compiler handles that automatically
21:25derek_cbbloom: oh I see
21:25bprsyntax sugar causes cancer of the semicolon... or something like that
21:33hyPiRionyeah, clojure can't do reflection that "well" on varargs
21:33bbloomarguably, perf is a major motivator for java interop, so making arbitrary array allocations obvious isn't a bad thing
21:41dnolen_core.match now also ridiculously fast when targeting CLJS - https://gist.github.com/swannodette/5847224
21:42dnolen_matching red black trees as arrays now close to 2X of the JVM when running under JavaScriptCore
21:45derek_cwhen we say let introduces an immutable binding, we don't mean that the thing that let binds to won't change, right?
21:45derek_cso if I bind x to a Java class
21:45derek_cI mean, an instance of a Java class
21:46derek_cpotentially x's inner state can still change, right?
21:48dnolen_derek_c: correct
21:49derek_cthanks. just verified
22:37jouiswalkeris there a nice function that counts the number of keys in a map up to a certain depth?
22:38jouiswalkeror better, keys within a certain depth range?
22:38jouiswalkerex {:a {:b c} {:d e} {:f {:g 'h}}}
22:39jouiswalker(count m (range 1 2)) would be 4
22:42Raynesamalloy wrote something similar at some point but consistently denies it.
22:42RaynesI was in fact in the same room with him at the time, but he cannot remember it.
22:42jouiswalkerlol
22:44amalloyjouiswalker: i don't think that would be a very good function to build all as one piece. why not build a few smaller pieces, and then glue them together?
22:45amalloyeg, start with a function that, for a given map, produces all legal key-seqs present in that map. so you'd get '((a) (a b) (a d) (a f) (a f g))
22:45amalloythen from that you can filter out the ones you want, and count them
22:46jouiswalkerthe filtering is what makes it weird though :/
22:46jouiswalkerideally i would just be able to filter things outside of a certain depth
22:46jouiswalkerand get something like a slice of the map
22:47jouiswalker({a 'b} {c {e 'f}} ) or something