#clojure logs

2011-07-14

00:00amalloythen the whole problem just reduces to ##(partition-by identity [1 1 2 1 1 1 3 3])
00:00sexpbot⟹ ((1 1) (2) (1 1 1) (3 3))
00:01jamiltronAh that's interesting.
00:01amalloyalso if you find yourself using first/rest much, step back and consider destructuring
00:03jamiltronI need to get more practice at destructuring.
00:06amalloy&((fn [[head & tail]] {:head head, :tail tail}) '(some list with stuff))
00:06sexpbot⟹ {:head some, :tail (list with stuff)}
00:15amalloyjamiltron: you might also like a couple things i've written. basically case studies of iterative refactoring in clojure: http://hubpages.com/hub/The-evolution-of-an-idea and http://groups.google.com/group/clojure/browse_thread/thread/ac2c7ce8d57f36bb/7aed5adae7bb3450?show_docid=7aed5adae7bb3450
00:17jamiltronNice, I'll bookmark those.
00:17jamiltronThank you.
00:26zakwilsonIs there a way with sandbar.stateful-session to get at and modify a list of all the sessions? I'm writing code to block users and I want to destroy their session if they're logged in.
00:34ihodeszakwilson: why not just invalidate their session server-side?
00:34ihodeszakwilson: you're talking about actually changing their cookie? that isn't secure.
00:35zakwilsonI'm talking about writing a function that says "if user ID 5 is logged in, log them out"
00:55ihodeszakwilson: i think it's in the sandbar-session atom in the stateful-session namespace. take a peak in there
01:00zakwilsonihodes: sandbar.stateful-session/sandbar-session is unbound except in threads called from the function returned by its wrapper.
01:12amalloyzakwilson: actually destroying ring cookies sounds hard. why not just insert another middleware between you and ring, which you can add "destroyed" sessions to? then if it sees an incoming request associated with a destroyed session, unset the session before calling the rest of your stack
01:13zakwilsonamalloy: that was plan B.
02:21amalloydoes a macro exist in core to transform (something expr1 expr2) into something like (map (fn [f] (f)) (list (fn [] expr1) (fn [] expr2)))? that is, take a series of expressions and return a seq that lazily evaluates them?
02:22amalloyi saw a form that looked like (or (f expr1) (f expr2) (f expr3)) and wanted to transform it into (some f [expr1 expr2 expr3]), but if any expressions are costly that ruins the short-circuiting. i wrote the macro myself to enable (some f (lazily expr1 expr2 expr3)), but if it's in core i'd rather use it
02:44tsdhStupid question, but are the current clojure java api docs online somewhere?
02:45tsdhThere's pacific.mpi-cbg.de/javadoc/, but isn't there some official site?
02:47amalloytsdh: the clojure java api docs?
02:47ajatsdh: the canonical java API would probably be on Oracle's site.
02:48amalloy$javadoc String
02:48sexpbothttp://download.oracle.com/javase/6/docs/api/java/lang/String.html
02:48amalloyis where the ordinary javadoc is
02:48tsdhSure the clojure java API docs. :-)
02:48amalloybut if you're looking for something clojure-specific you're unlikely to find it, especially if you don't clarify what "clojure java api docs" means :P
02:48tsdh$javadoc IPersistentCollection
02:48sexpbotJavadoc not found. Try http://download.oracle.com/javase/6/docs/api/
02:49amalloynobody wrote javadoc for that stuff
02:50tsdhamalloy: Yes, but still you'd have at least a listing of signatures.
02:50amalloyreading the source for interface declarations is pretty easy. for concrete implementations, that's harder
02:50amalloythere's also clojure.contrib.repl-utils/show
02:51tsdhOk, nevermind.
02:54ajatsdh: That interface isn't part of the java api, as far as I can tell. It's from clojure. Google doesn't seem to have trouble finding docs.
02:55tsdhYes, it's a clojure interface and you can find it with google. But that's no official clojure site, so I cannot know what version that is.
02:57amalloytsdh: clone the clojure git repo
02:57amalloythat's how i answer questions about clojure internals
02:58ajatsdh: Clojure.org is as close to a dt
02:59amalloydt?
02:59tsdhamalloy: Yeah, *I* have it. We (my working group) want to switch from standard java collections to persistent, immutable collections in our graph library. So it seems there are 2 candidates: clojure's stuff and pcollections. On the one hand, I'm somewhat in favour of pcollections, because of their nicer java interface (generics). On the other hand, lately I use more and more clojure working with that library...
02:59ajatsdh: Standard as you'll be able to find. As amalloy said, internals are basically from the reference implementation.
03:01mikesomethingwhy do i get this?
03:01mikesomethingCompilerException Either this object does not exist, or this user does not have permission to access it.
03:02amalloyi'm guessing you're trying to work with an object that either doesn't exist or you don't have permission to access. without more details, it's hard to guess anything more useful
03:02tsdhamalloy: haha!
03:02mikesomething(def rept_utils (new com.google.api.adwords.lib.utils.ReportUtils user (long 1234)))
03:02mikesomething#'google/rept_utils
03:03mikesomethingsorry, i'll do a pastie
03:04mikesomethinghttp://pastie.org/2211207
03:04mikesomethinghow do i get permission to access?
03:06mikesomethingamalloy?
03:06amalloymaybe that's clojure telling you not to access non-public members? i dunno
03:06clojurebotamalloy: therfor I return [previous] if rest is empty
03:07mikesomethingit is a public member
03:07mikesomethinghttp://google-api-adwords-java.googlecode.com/svn-history/r171/trunk/docs/com/google/api/adwords/lib/utils/ReportUtils.html
03:07amalloyclojurebot: you can't at least find a juxt quote?
03:07clojurebotsyntax-quote is very hairy
03:08amalloy*shrug*
03:09mikesomethingcan i use reflection to call that?
03:20amalloyclojurebot: amalloy is <amalloy> just use juxt, it'll be great
03:20clojurebotAlles klar
05:14clgvI wonder whether I should prefer anonymous function closures over partial or vice versa? (limited to the case where partial is applicable, i.e. #(do-something outer-val ...) vs (partial do-something outerval) )
05:19bsteuberclgv: probably just a matter of taste, but I prefer #() for brevity and consistency with cases where partial doesn't apply
05:20clgvok.
05:23ejacksoni'm the opposite, I ilke partial as it clues me in to the semantics of what I'm doing
05:34ZabaQI'm toying with Clojure, but one aspect I'm finding hard to work with is the error messages..I'm finding it hard to work backward from a jvm runtime error to a clojure bug..any tips for debugging welcome..
05:34ZabaQI'm from a CL background, not a Java one ..
05:35bsteuberZabaQ: yeah, that's really one of clojure's current weaknesses
05:36bsteuberbut when you have a specific exception, you can always ask here
06:09tsdhIs there an i>
06:09tsdhups...
06:09tsdhIs there an integer division function in clojure?
06:10tsdhAh, `quot'.
06:51shtutgartIs it possible to specify ranges for Incanter chart? e.g. I want to always have numbers from 1 to 100 on the y-axis
06:55tsdhWhy does (class (int (+ 1 1))) return java.lang.Long in clojure 1.3?
07:00talios,(class (int (+ 1 1)))
07:00clojurebotjava.lang.Integer
07:00taliosgood question.
07:00Dranikhi all!
07:00Dranikhow can I idiomatically set utf8 charset through :content-type in ring?
07:01tsdhtalios: That's clojure 1.2, isn't it?
07:02clgvtsdh: yes it is clojure 1.2
07:02clgv,(clojure-version)
07:02clojurebot"1.2.0"
07:02tsdhHm, ok. What works (but is ugly) is (class (Integer/valueOf (+ 1 1)))...
07:02shtutgartDranik: I have (defn wrap-codepage [handler] #(content-type (handler %) "text/html; charset=utf-8"))
07:03Dranikshtutgart: let me try...
07:04Dranikshtutgart: thanks!
07:04shtutgartnp
07:46Gamli$findfn even? [2 4 6 20 90] true
07:46sexpbot[clojure.core/not= clojure.core/some clojure.core/distinct? clojure.core/every?]
07:56aleonhardthi, everyone. i'm building a toy project in clojure that requires http ("rest") communication. if possible at all, i want to avoid using apache httpcomponents directly. what's the "state of the art" for clojure http client libraries?
07:57aleonhardtit's hard to tell which forks of which projects are abandoned, and which ones are not.
07:57taliosaleonhardt: https://github.com/neotyk/http.async.client - built ontop of the awesome async-http-client
07:59aleonhardttalios: cheers. would you recommend that over clj-http?
08:00taliosi've not tried the http.asynch clojure port, but I use asynch all the time. much nicer. been awhile since i've used clj-http tho so not sure. but I think it will be, as asynch uses nio and futures and all concurrent goodness
08:25fliebelIs there any Clojurey thing for doing tf-idf, k-means and all these things?
08:39ejacksonfliebel: what is tf-idf ?
08:41ejacksonoh. Well the JVM is pretty weak all round for machine learning and math, actually
08:50fliebelejackson: some bag-of-words metric. Why is the JVM weak for this?
08:51ejacksonlack of libs
08:51fliebelejackson: Hm, then I'll have to write my own.
08:51ejacksonthe best I came across was weka
08:52ejacksonwhich has an associated book
08:56clgvfliebel: there is a parallel implementation of a kmeans https://github.com/johannkraus/McKmeans
08:57fliebelclgv: pre-lein?
09:00fliebelclgv: But yea, k-means can easily be split up into k tasks I guess.
09:00fliebelI think I'm just going to port the "mining the social web" code.
09:00clgvfliebel: seems so. dont complain - you aksed - I remembered ;)
09:01fliebelclgv: Thanks for remembering, I might use it as a reference :)
09:05ejacksonMacKays book has a good discussion k-means and suggests an algo to do it (newton raphson) that you could take as a reference too. The book is free online.
09:09ejacksonof course, the point of his discussion is that you should *not* use kmeans... :)
09:09fliebelejackson: huh?
09:09ejacksonyeah, its a probability density optimising algo, so has lots of pathologies.
09:10ejacksonput a cluster centre over a data point and lets its stdev go to zero and you get infinity probability density
09:10ejacksonoopsie !
09:11ejacksonso if you newton raphson bit actually work, you should find this as the maximum likelihood solution
09:16fliebelejackson: this ? http://www.inference.phy.cam.ac.uk/mackay/itprnn/ps/284.292.pdf
09:17ejacksonthat's the first bit of it where he introduces kmeans
09:18ejacksonhe then uses it in the following chapters as an example of a maximum likelihood algo and shows it blowing up
09:18ejacksoni think he actually print *KABOOOM* somewhere ;)
09:18fliebelouch
09:19ejacksonso he's make a much more general point
09:19ejacksonfabulous discussion
09:22clgvejackson: but despite that the algorithm should remain applicable in certain problems?
09:23ejacksoni would probably say no
09:23clgvapplication problems are often much easier than the worst-case theorists are concerned about
09:24ejacksonbut i'm a little strident
09:24fliebelclgv: So you're saying that running with k-means might be just fine?
09:25clgvfliebel: kmeans is still taught in some university lectures so I cannot imagine that it has entirely no use.
09:26clgvthe question will be which characteristic your data has and how kmeans performs on that
09:27fliebelclgv: The only way to know is to try...
09:29ejacksonthe problem with machine learning stuff is exactly this. It might work, it might not, we might be able to determine if it has worked, but we might not... its too unsettling for me :)
09:31clgvejackson: his kaboom is related to "soft k-means", if he describes another variant, he does not relate the problem to it.
09:31ejacksonno, the point is general
09:32clgvbut he says "Soft K-means can blow up"
09:32clgvwould have to search the scipt to see which versions he defines
09:32clgvno time for that right now ;)
09:33clgvah there is an enhancement described in 22.3
09:33ejacksonbut trust me on this, any ML algo will bite you in the eye eventually
09:34clgvI dont do clustering .... yet ;)
09:34jweissis there a better way: (last (take-while f (iterate g 0)))
09:34clgvwhat is your ML algo?
09:34jweissi just want the last value, but don't want to traverse the list
09:35clgvjweiss: recursion with loop-recur?
09:35ejacksonclgv: what is my ML algo ?
09:36jweissclgv: yeah, i suppose i meant a functional way :)
09:36jweissi guess i could try trampoline
09:36clgvejackson: yeah. you used that abbreviation
09:36clgvah any ^^
09:36ejacksonoh sorry, maximum likelihood
09:36jweissactually that won't really help me
09:38ejacksonclgv: lots of probability space have points of infinite density, but no mass, and any maximum likelihood algo, if it works, will find these, despite the fact that they are useless.
09:39ejacksonbe it k-means, soft kmeans, or whatever.
09:41clgvejackson: but that doesnt mean in general that the specific problem I have has these points
09:41ejacksonnot does it tell you that it does not
09:41ejacksonand you have no way of knowing up front if this is the case
09:42ejacksonunknown unkown, Rumsfeld style.
09:42clgvIf I have means to analyse the properties of my problem instance I might be able to tell
09:44ejacksonsure, and I'd encourage that. But the suck it and see attitude the pervades a lot of what passes as research in machine learning is a one way ticket to a self applied lobotomy.
09:44ejacksonooh, dear, I am getting stident :)
09:45clgvlol
10:02fliebelwhat do cake/lein do when finding a conflicting version? Especially for Clojure itself.
10:03clgvfliebel: evil grinning at you ;)
10:04ejacksonKABOOM
10:04ejackson:P
10:04fliebelclgv: That's the thing, it just seems to swallow hard and make a decision. I never had a conflict.
10:05clgvfliebel: I didnt actually try it.
10:11fliebelThe reason I want to know is because I'd like to use 1.3, but I don't know what will happen with dependencies.
10:30technomancyfliebel: whatever's closer to the root of your dependency tree wins
10:38edw`Is it gauche to name a non-func with a question mark e.g. (let [required? (:required options)] ...)?
10:41jweissis this a bug in clojure.zip? seems you cannot edit a loc when you're at the 'end'. (-> (zip/seq-zip [1]) zip/next (zip/edit identity))
10:41jweissgives "clojure.lang.Keyword cannot be cast to clojure.lang.Associative"
11:06fliebeltechnomancy: Thanks, so I guess that means that if 1.3 does not break things, I can use it.
11:11devncemerick: what, you don't want (fn) aliased to (ƒ)?
11:11devncemerick: ;)
11:11scgilardijweiss: http://www.exampler.com/blog/2010/09/01/editing-trees-in-clojure-with-clojurezip/ says "Notice also that I explicitly wrapped the tree in a seq. If you use seq-zip on an unwrapped vector, you’ll get confusing results."
11:12scgilardithat does seem to solve it
11:13cemerickdevn: snowman would be funner :-D
11:13scgilardi(-> (zip/seq-zip (seq [1])) zip/next (zip/edit inc) zip/root)
11:13cemerickdevn: I distinctly remember there being discussions a long while ago about how λ should be defined in clojure.core as an alias for fn.
11:13tsdhIs there something better than (first (for [a (lazy-seq) b (lazy-seq) :when (pred a b)] [a b])) to get the first a and b matching pred?
11:13cemerickDidn't go far, as you can imagine.
11:14devncemerick: the klingon destroyer UTF char!
11:14fliebelcemerick: I've seenan emcas setup that abbreviated to it.
11:14cemerickdevn: wait, what?
11:16devncemerick: http://www.evertype.com/standards/csur/klingon.html
11:17devnif we're going to bring UTF into the fold as aliases for function names we might as well go all out!
11:17devncemerick: U+F8FF => KLINGON MUMMIFICATION GLYPH
11:18devnenterprisey: fancy.
11:18tsdh
11:18tsdhWhat a huge char...
11:18enterpriseyhay guys I hav a featur request clojure should make str work like SQL! for enterprise programming!
11:18enterprisey(defn enterprise-str [& xs] (if (some nil? xs) nil (apply str xs)))
11:18devnbahahaha
11:19jcromartieseriously WTF is up with SQL
11:19jcromartieis that just T-SQL
11:19jcromartie?
11:19devn&(inc jcromartie)
11:19sexpbotjava.lang.Exception: Unable to resolve symbol: jcromartie in this context
11:19devn(inc jcromartie)
11:19sexpbot⟹ 2
11:19devnthere we go...
11:19cemerickdevn: oh, private use range, OK. I thought I'd have known about it if it were a recognized char already. :-)
11:19jcromartieI think it is just Microsoft. It's because they are enterprise class.
11:20devncemerick: :)
11:34scgilardijweiss: see also vector-zip
11:35jweissscgilardi: that was just an example, it does the same with my own zipper as well
11:35jweissnot sure why it doesn't fail with vector-zip
11:36scgilardihave you looked at the source for seq-zip and vector-zip?
12:04technomancywait, klingon is just a new orthography for latin letters?
12:04technomancyI'm so disillusioned!
12:05Scriptorisn't the vocabulary different?
12:05Scriptorwell, dumb question, they clearly have their own vocabulary
12:06ejacksontechnomancy: that's just federationocentric propoganda.
12:07ScriptorI'm never gonna understand emacs's C-x o
12:07Scriptorit switched between two irc chan buffers 6 times before going to another
12:59cemerickThe ML is actually worse than I thought.
13:00technomancycemerick: luckily mike m. seems to be the only one daft enough to respond to wesson in most cases
13:02technomancycemerick: looks like you missed my answer last night; lein javac should run automatically before clojure AOT if :java-source-path is set in project.clj
13:04cemericktechnomancy: Right, thanks. And no way to make it run after clojure AOT?
13:04fliebelWhat is this tf-idf impl doing? http://thecomputersarewinning.com/post/simple-tfidf-in-clojure The Py impl from "mining the social web" is much simpler: https://github.com/ptwobrussell/Mining-the-Social-Web/blob/master/python_code/buzz__tf_idf.py
13:05technomancycemerick: for that you need hooks
13:06cemerickah, so you can add a before hook to whatever var holds the AOT "task" and kick off javac yourself?
13:07technomancy(add-hook #'leiningen.compile/compile (fn [compile project & args] (apply compile project args) (javac project))) ; something like that
13:08technomancyactually there's an robert.hooke/append macro that basically does that.
13:10cemericktechnomancy: Got it, thanks. Are the hooks in lein documented anywhere? I'll add a footnote in the book if so.
13:11technomancycemerick: it's not really leiningen-specific, so https://github.com/technomancy/robert-hooke is probably your best bet.
13:11technomancyit just happens to be bundled with lein
13:13technomancyah, append/prepend won't work if the call you're appending needs access to the args of the hooked function, which javac does.
13:13technomancyno real backwards-compatible way to support that without anaphora.
13:13technomancyI love it when the docs for a library are longer than the implementation.
13:24amalloytechnomancy: i think i'll start including-by-reference things like War and Peace in all my docs so i can get your seal of approval
13:26technomancyhm; I am really not up on my Russians =\
13:26technomancyBrothers K is on my queue, but not near the head.
13:27technomancybut don't let that put you off on your literary references!
13:48jweissanyone know if it's possible to pass jvm args to 'lein run'? as in 'lein run -Dmy.prop=myval'
13:49jweissthat doesn't actually work ^
13:49amalloy$google leiningen sample project.clj :jvm-opts
13:49sexpbotFirst out of 254 results is: technomancy/leiningen at master - GitHub
13:49sexpbothttps://github.com/technomancy/leiningen/blame/master/sample.project.clj
13:50amalloyi wonder why it picked a blame
13:53jweissamalloy: that doesn't really help me - i know i can put em in project.clj but i want to pass system properties that might be different for each run.
13:54jweissunless i can set jvmopts on the cmd line as well?
13:54amalloyi dunno what lein's solution to that is. cake has a notion of "contexts", which solve this problem neatly, but i don't know them very well
13:55technomancyjweiss: JVM_OPTS=foo lein run
13:55jweissaha, should have thought of that. thanks technomancy
13:55technomancysure
14:16Dranikhi all!
14:16DranikI'm trying to enable utf8 for my webapp using the function: (defn wrap-codepage [handler] #(:content-type (handler %) "text/html; charset=utf-8"))
14:17DranikI use it here: (def app (-> (handler/site main-routes) wrap-codepage wrap-session))
14:17Dranikbut it doesn't work. what I'm doing wrong/
14:17Dranik?
14:20Dranikthis is what I get: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IPersistentMap
14:21amalloyDranik: you want to assoc the :content-type, not just return it
14:21amalloy(defn wrap-codepage [handler] (fn [req] (assoc (handler req) :content-type "text/html; charset=utf-8")))
14:22Draniklet me try...
14:23technomancyhave you guys used rep at all?
14:23technomancyI've got to say I am a huge fan
14:23technomancyhttp://clojars.org/rep
14:25Dranikthis is what I've got instead of utf8: <html><body>??????, ???!</body></html>
14:26Draniktechnomancy, what's that?
14:26technomancyit's like repl, but without the l.
14:26Dranikare there any differences with usual repl?
14:26technomancyyes, it doesn't loop
14:26mefestoDranik: shouldn't your wrap-codepage be returning a function that accepts a request and delegates to the handler?
14:26Dranik:-)
14:26technomancydon't get me wrong, sometimes you want to loop.
14:26technomancybut
14:26technomancysometimes you don't!
14:27Dranikmefesto: I don't know that stuff well. can you show me how to do that correctly?
14:27amalloymefesto: he does
14:27amalloynote the #
14:27mefestoDranik: https://gist.github.com/1083075
14:28mefestoamalloy: oh i see it now... sry
14:28Draniktechnomancy, for what tasks do you prefer rep?
14:28amalloyi think it's clearer the way i wrote it, with an explicit (fn [req]), but some people like #...there's just no accounting for taste
14:28technomancyDranik: mostly joking, but it's nice for parallel cluster control.
14:53amalloytechnomancy: i just write my whole program correctly in one go, so there's no need for a loop
14:53technomancynow we're talking
14:56iceywhy even bother with the P? you could just have a RE
14:58Scriptorreally, you just need R
14:58technomancybrilliant; relentless pursuit of simplicity.
14:58amalloyi think just E is the important one
14:59amalloyyou can always malloc/new up the forms the reader produces by hand, and pass those to the runtime
14:59iceydeveloping with RE is the "trust me, I got this" mode of development
15:07amalloywhat's up with http://groups.google.com/group/clojure/browse_thread/thread/dbf4c482d5d7f0e1/963c16209cce044e ? i don't recognize the names, so i'd guess spam, but the group is moderated so maybe these are actual clojure developers?
15:13dansi cant get vimclojure to work - no syntax highlighting and nailgun keeps giving connection refused
15:14danshttps://gist.github.com/1083193 this is the error i keep getting
15:15dansand :set ft? brings up filetype=, which is probably why the syntax highlighting doesnt work
15:15dansit doesnt recognise a clj file as clojure
15:16Scriptordans: in your vimrc, what do the lines you added for vimclojure look like?
15:20sjldans: Are you running nailgun on your own or having vimclojure run it for you?
15:36tsdhHi. Can someone explain me this protocol error? http://pastebin.com/3uQT9Pwh
15:39amalloytsdh: well, i'd guess ge isn't something Delete-able. as an aside, delete! is easier to implement as (defn delete! [& things] (doseq [thing things] (delete! thing)))
15:40tsdhamalloy: But it errors at compile time, not when calling it.
15:41amalloyeeeenteresting. well, i don't know that much about protocols, but it compiles fine for me
15:41amalloy(on clojure 1.2.1-
15:41amalloy)
15:42amalloyhttps://gist.github.com/1083265
15:43tsdhamalloy: Yes, that compiles for me, too...
15:44tsdhWho needs Vertex and Edge when he has Integer and Double, right?
15:44amalloyindeed
15:46tsdhArgh, got it! Wanna guess?
15:46tsdhStarts with A and ends with T.
15:47amalloyassault
15:47tsdhAOT
15:47danssorry Scriptor , sjl
15:48danshere is my vimrc https://gist.github.com/1083276
15:48danssjl: I'm trying and failing at both
15:48dansthe error i pasted was from within vim
15:48tsdhYesterday, I AOT compiled some classes only to disassemble them to see what clojure creates for classes, but I forgot to "lein clean" afterwards.
15:48tsdhs/classes/namespaces/
15:48sexpbot<tsdh> Yesterday, I AOT compiled some namespaces only to disassemble them to see what clojure creates for namespaces, but I forgot to "lein clean" afterwards.
15:52sjldans: do you use lein?
15:54Scriptorgah, does vimclojure even have a project page anymore?
15:54danssjl: yes
15:57sjldans: lein plugin install vimclojure 1.0.0 ; cd myproj ; lein vimclojure
15:58dans1.0.0?
15:58sjl(it's been a while since I did this, so I might be wrong -- I've switched to SLIMV for Vim+Clojure/Lisp now)
15:59sjldans: I think so.
16:00babilensjl: What were your reasons for the switch? I like vimclojure a lot, but have not really played with slimv yet. (I just use slimv's paredit)
16:01babilendans: And the project page is https://bitbucket.org/kotarak/vimclojure
16:01dansthanks
16:01dansi've been on that page
16:02sjlbabilen: mainly I wanted as similar an environment as possible for Clojure and Lisp
16:02danstried following everything thats said, but it jsut doesnt wanna work
16:02sjlI didn't want to have to learn two completely separate interfaces
16:03sjland SLIMV's tutorial convinced me it was mature enough to be usable: http://kovisoft.bitbucket.org/tutorial.html
16:04dansi think ill try SLIMV then
16:04dansdoes it also do syntax highlighting?
16:06babilensjl: Ok, I can absolutely understand that. I was just curious what slimv would offer me over vimclojure as I like the latter a lot.
16:07sjlbabilen: If you just do Clojure, then the answer is "not much of anything"
16:08babilendans: vimclojure is a bit tricky to setup, because it basically consists of three parts that have to be present. 1. vim plugin 2. nailgun client 3. nailgun server
16:08Scriptordans: looks like it doesn't, so I'd suggest using vimclojure just for that
16:08sjldans: It does, but to be honest I cheated by forking SLIMV and replacing its Clojure syntax/indent files with the ones from VimClojure :)
16:08babilensjl: heh :)
16:08Scriptorthat's what I use it for anyway, though it's been a year or so since I set it up
16:09dansbabilen: i'd be happy with just the syntax highlighting for the moment
16:09dansnevermind nailgun
16:10Scriptordans: then I think you should be fine just having the files copied to plugins, syntax, etcl
16:11dansi should be :(
16:11Scriptorhmm, take out anything that uses nailgun
16:11Scriptor(from vimrc)
16:13babilendans: What I have done is essentially: 1. Use vundle for vim plugins (https://github.com/babilen/dotfiles/blob/master/vim/vimrc) 2. Compile the ng client from kotaraks repository and "install" it to ~/bin 3. lein-vimclojure from autre + nailgun server -- http://paste.debian.net/122913/ in project.clj -- But note that there is a new version of lein-vimclojure here http://clojars.org/org.clojars.oskarkv/lein-vimclojure
16:14babilendans: You can also find the rest of the vimlojure plugin configuration in my vimrc -- There is also a never version of vimclojure-server. I'll try that later, thanks for making me aware of that :)
16:17dansok, ill try with vundle :)
16:17dansthanks
16:17babilendans: Having installed that you can start the nailgun server with "lein vimclojure &"
16:17babilendans: Good luck -- please also read https://github.com/gmarik/vundle
16:18babilendans: As there are new versions around I am not sure if my configuration reflects the current state-of-the-art, but it is working. I'll upgrade later tonight and will let you know.
16:22dansbabilen, do i have to move ng to ~/bin
16:22dansi've put it in ~/.ng/
16:24dansand after addings the dependencies, i need to run lein deps right?
16:24babilendans: Fine as well, just make sure to adjust the path in your .vimrc -- vimclojure#NailgunClient
16:24babilenindeed
16:25dansbabilen, i've added both lein and ng to my $PATH, so they should run with just lein and ng
16:25danscuriously they dont, i get zsh command not found
16:26danssorry, ng is working now
16:26dansit's just lein which doesnt
16:26dans:/home/daniel/code/cloj/lein:/home/daniel/.ng/ng
16:28babilenyou add directories to your PATH, make that ":/home/daniel/code/cloj/:/home/daniel/.ng/" -- or ask in #zsh ;)
16:30danshmm ok
16:31dansyou're right :/
16:35dansvim still doesnt recognise the clj filetype
16:38babilendans: This is getting somehow off-topic in here :-\ -- But have you installed the bundles? Do you see VimClojure in ":scriptnames" ?
16:39dansyes, and i just loaded vim again and the highlighting randomly appeared :/
16:39dansbut anyway, working :D
16:40dansi have to refresh my vimrc maybe, reopening wasnt enough
16:41dansthanks for all your help babilen
16:50babilendans: You are welcome! Do you have a repl? Start it with "\sr" for example
16:57dansbabilen, i dont yet
16:58dansi need to put the nailgun stuff back in my vimrc
16:58dansstill get the could not determine namespace - connection refused error there
16:59dansi have to set up my classpath or something dont i?
16:59gtrak`how do you easily navigate in clojure-mode?
17:00dansi'm coming from a ror/node.js background, i am pretty new to java
17:13babilendans: you need the ng client in your PATH and you start the nailgun server with "lein vimclojure &". Have you done that?
17:22dansThat's not a task. Use "lein help" to list all tasks.
17:23dansbabilen, thats what i get when running lein vimclojure &
17:26babilendans: You ran "lein deps" before that? Could you paste your project.clj (created with "lein new") and the output of "lein deps" to http://paste.debian.net please?
17:27danshttp://paste.debian.net/122921/
17:28danshttp://paste.debian.net/122922/
17:28babilenAh, forget that. Lets install it globally. Could you run "lein plugin install org.clojars.oskarkv/lein-vimclojure 1.0.0-SNAPSHOT"
17:32dansok, done
17:33babilendans: Now run "lein vimclojure &" in a directory with project.clj
17:33babilendans: I would just create a new one now (lein new) and test with that.
17:33danssucess :)
17:35dansnow i get a new error with \sr http://paste.debian.net/122923/
17:40babilendans: So, the server started? That should mean that "ng" is not in your PATH -- Could you run "which ng". Does it find ng? Do you have "let vimclojure#NailgunClient = /home/<YOUR_USER>/.ng/ng" and "let vimclojure#WantNailgun = 1" in your vimrc?
17:40danswhich ng finds it
17:41dansits in my path so i just have let vimclojure#NailClient = "ng"
17:41babilenserver started and those two in ~/.vimrc?
17:41dansyeah
17:41babilenhmm
17:43babilenCould you run "ng ng-stop ; lein vimclojure &" and try again? Please paste the output you get, your .vimrc and any error you get when you do "\sr"
17:44babilen(single paste)
17:44dansNGServer started on 127.0.0.1, port 2113
17:45danshttp://paste.debian.net/122924/
17:46dansand same error with \sr: http://paste.debian.net/122923/
17:47babilendans: You do *not* give the absolute path for vimclojure#NailgunClient. Please look above and replace <YOUR_USER> with your username. You also don't want "10" as value of ParenRainbow
17:47babilendans: You did install ng to ~/.ng/ng didn't you?
17:48dansyes babilen, but it said in the vimclojure docs that if its in your path, ng is sufficient
17:48dansill try being explicit
17:49babilendans: Hmm, right. Try something like: http://paste.debian.net/122925/ :\
17:52dekuderpwhen I run "lein swank", I get "That's not a task. Use 'lein help' to list all tasks."
17:52dekuderpand it was working a half-minute ago
17:53dansdoesn't work babilen :( sorry, but im gunna have to get to bed, got work in 6 hours
17:53dansthanks for your help
17:54babilendans: good night
17:54dansnight
18:00krlhow do you map over a vector and get a vector output?
18:01mefesto,(vec (map inc (range 5)))
18:01clojurebot[1 2 3 4 5]
18:01amalloyif you're mapping over it, you probably don't really care that it's a vector
18:02Scriptorkrl: use reduce with conj
18:02Scriptoralthough it won't be lazy
18:02amalloyvectors have to do quite a bit of housekeeping to keep their performance guarantees, and if you're going to just treat them as seqs anyway, you should strive to only make them vectors when it becomes necessary
18:03Scriptorwhat's the best way to use vectors if not as a seq, collections that will be accessed at any nth place and not just with first/rest?
18:04amalloyScriptor: yes, and/or conjing onto the right
18:05amalloyi mean, using vectors as seqs is great
18:05amalloybut don't turn then back into vectors just for fun
18:05Scriptorgot it
18:05krlhmm. this might be true. i need to get the last n elements of a (potentially very long, and growing) sequence. would this work better with a vector or a list?
18:06amalloy&(doc take-last)
18:06sexpbot⟹ "([n coll]); Returns a seq of the last n items in coll. Depending on the type of coll may be no better than linear time. For vectors, see also subvec."
18:06Scriptor,(doc subvec)
18:06clojurebot"([v start] [v start end]); Returns a persistent vector of the items in vector from start (inclusive) to end (exclusive). If end is not supplied, defaults to (count vector). This operation is O(1) and very fast, as the resulting vector shares structure with the original and no trimming is done."
18:07krlah. i guess i really need to test for a certain condition in the list, and cut off accordingly though
18:08amalloy&[(doc drop-while) (doc take-while)]
18:08sexpbot⟹ ["([pred coll]); Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns nil." "([pred coll]); Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of side-effects."]
18:09amalloysee also split-with, partition-by
18:09krlah no take-last-while though? i guess i could store the stuff in reverse order from the start
18:09amalloytake-last-while? just combine take-last and take-while
18:10amalloyor something like that. you aren't really clear about what you want
18:10gtrak`if you treat the vector as a stack, peek should give you the head, which is the last, right?
18:11gtrak`for lists, the head is the front
18:11krlgtrak`: yes of course. i should think in terms of a stack. this made it clearer
18:11gtrak`there's a peek function already
18:12Scriptorkrl: so, to go back to the problem, you have to map over a seq to get a new (very large) seq from which you want the last n elements of?
18:12Scriptorwhat type is the original seq?
18:13krli don't need to map it really, that was my confusion
18:13Scriptorah
18:13krlso a stack will be sufficient
18:13krlproblem solved :)
19:39mdeboardAnyone have any idea why when I do "clojure-jack-in" the swank buffer only says, "Process swank exited abnormally with code 1\nThat's not a task. Use "lein help" to list all tasks." error?
19:39mdeboardOn swank-clojure 1.3.2 btw
19:39mdeboardoh hm
19:41mdeboardNo, that's not it
19:51mdeboardAdditionally, I'm pretty stumped on http://4clojure.com/problem/19
19:51mdeboardI tried #(last %) which should work fine but doesn't
19:51mdeboardalso just "last" :P
19:52mdeboardoh, special restrictions :)
19:53amalloymdeboard: yeah, we didn't think that "last" was a very clever solution to that problem
19:54mdeboardus poor beginners :(
19:54amalloythere are so many interesting ways to implement last, though
19:54mdeboardI think I got it though.
19:55amalloy(comp first (partial take-last 1))
19:55mdeboardstop stop
19:55mdeboardI'm trying to do it myself :|
19:55amalloyhaha i know
19:55amalloydon't use that one
19:55amalloyit's not much of a hint anyway
19:56amalloyjust a demonstration of a silly way you could do it
20:00mdeboardlol well this feels cheap #(first (reverse %))
20:00mdeboardbut hey take away last I"l just reimplement it :|
20:02mdeboardhrmph
20:03jamiltronMay I ask for suggestions for a more idiomatic way to solve a 4clojure problem?
20:03gfrlog`yes.
20:03gfrlog`clojurebot: anyone?
20:03clojurebotPlease do not ask if anyone uses, knows, is good with, can help you with <some program or library>. Instead, ask your real question and someone will answer if they can help.
20:04jamiltronhttps://gist.github.com/1083758
20:05gfrlog`hmm
20:06gfrlog`it doesn't look too bad. one thing is to use destructuring in your let, instead of calling first/rest directly
20:06gfrlog`(let [[x & xs] n] ...)
20:07jamiltronAh right, I was suggested doing this last night. I suppose it hasn't sunk in yet :P
20:07jamiltronOn a different problem.
20:08gfrlog`there _might_ be stack issues with the use of concat. I can never tell when that's going to happen
20:08amalloymdeboard: i think that's the same as my first solution to last
20:09jamiltrongfrlog`: that's kind of what I was wondering. I think the way I do it requires a mix of concat and cons due to the possibility of nested sequences, but I was wondering if there was perhaps some use of map that may be able to take care of it.
20:09amalloygfrlog`: yes, i think there are if you have a seq that's nested a few thousand levels deep
20:10gfrlog`jamiltron: mapcat comes to mind, but I think you could only use it to make something equivalent
20:11gfrlog`I could imagine a creative use of loop that would avoid direct recursion, but I suspect most people here would call that uglier
20:11gfrlog`(direct? explicit? named? what did I even mean?)
20:11amalloygfrlog`: you would imagine wrong, i think
20:11gfrlog`amalloy: you imagine?
20:11amalloythis recursive algo needs to keep a stack
20:12amalloybecause it's not just iteration dressed up as recursion
20:12gfrlog`amalloy: what are we talking about? mapcat or loop?
20:12amalloyflatten
20:12amalloyor loop?
20:12amalloymy point is: you can't cleverly use loop to avoid recursion in flatten
20:12gfrlog`oooh
20:13gfrlog`I thought you were objecting to the OTHER half of that statement
20:13jamiltronloop/recur on releases the stack if recur is strictly in the tail position, right?
20:14gfrlog`amalloy: I didn't mean to avoid any kind of recursion. There would certainly be implicit recursion with a stack. I meant no explicitely calling the function itself again
20:14gfrlog`given that loop is essentially recursion, it's not that much of a distinction
20:14gfrlog`jamiltron: yes, and the compiler won't let you put recur anywhere else
20:15amalloygfrlog`: i can't tell. are you claiming/proposing that you can write (defn flat ...impl...) where impl doesn't use the symbol flat?
20:15gfrlog`amalloy: yes
20:16gfrlog`I mean the way you've stated it it's even trivialer than what I was claiming
20:16amalloyi mean, obviously that's possible if you define a different named function and recurse on that, but in a non-cheater sense i don't think you can do it. i'd be interested to see if you can
20:16mdeboardWow this is hard to google. What's ->> again?
20:16gfrlog`amalloy: I'm trying right now
20:16mdeboard`->>`
20:16mdeboard,(->>)
20:16clojurebotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$--GT
20:16amalloy&(->> (range) (filter even?) (take 5) (reduce +))
20:16sexpbot⟹ 20
20:17amalloy&(clojure.walk/macroexpand-all '(->> (range) (filter even?) (take 5) (reduce +)))
20:17sexpbot⟹ (reduce + (take 5 (filter even? (range))))
20:18amalloymdeboard: c'est bon?
20:18mdeboardamalloy: oui
20:21gfrlog`amalloy: https://gist.github.com/1083792
20:22amalloyi see. i would have called that super-extra-explicit recursion (managing the stack yourself), whereas implicit recursion would be more like (map flat (...))
20:22amalloylooks nice though
20:22gfrlog`thx
20:22gfrlog`it all turing complete
20:23gfrlog`whenever I put adjectives on the word recursion I usually feel like I have no chance of actually communicating anything
20:23amalloy*chuckle*
20:25jamiltronThanks for all the help I think this channel is really helping me pick up better Clojure practices.
20:25gfrlog`then the channel is well-named
20:26mdeboardWill someone hit me if I use commas for white space while I'm learning :(
20:26gfrlog`mdeboard: I use commas for whitespace all the time
20:26mdeboard(comp keyword, str) makes my brain hurt lses than (comp keyword str)
20:26amalloymdeboard: knock yourself out
20:26gfrlog`okay that's weird though
20:26amalloyhaha yes
20:26mdeboardhaters
20:26jamiltronLike the way I did the compress a sequence problem before was a big consing-self-recursive mess, until amalloy showed me partition-by and I've started practicing using map more.
20:27mdeboard(map,,(comp,,keyword,,str),,[1,2,],,),
20:27mdeboardಠ_ಠ
20:27amalloy,,,,,,,,,,,,,,1,,,,,,,,
20:27clojurebot1
20:27mdeboardlol
20:27mdeboard,(,,,,,,,,,,,,,+,,,,,,,,,,,,,,,,,,,,,,,,(+,,2,3),)
20:27clojurebot5
20:28mdeboardawesome.
20:28amalloyi mean, god gave you commas so you can put them wherever you think it makes things clearer
20:28amalloybut you should also try to get over the "need" to put commas everywhere that languages with complicated grammars have
20:28amalloy(and every other language has a complex grammar)
20:29mdeboardYo'ure right, it's just tough for me to analogize
20:29jamiltronIs it generally a bad idea to call the various cons, conj, concat functions in a reduce?
20:30amalloyjamiltron: cons and conj, knock yourself out. concat...welll...usually that's not a problem
20:30mdeboardI guess comp is a more concise/faster way of a for loop
20:30mdeboardor even a list generator
20:30amalloymdeboard: eh? they seem unrelated
20:30mdeboardlist comprehension*
20:30jamiltronWhat is the potential problem with concat?
20:30amalloy$google stackoverflow dbyrne sieve
20:30sexpbot[recursion - Recursive function causing a stack overflow - Stack ...] http://stackoverflow.com/questions/2946764/recursive-function-causing-a-stack-overflow
20:30amalloyjamiltron: that, basically
20:31amalloyje
20:31amalloyer
20:31amalloyhe's using loop/filter, but the same concerns apply to reduce/concat
20:32amalloyand you can usually use ##(doc into) instead of reducing with conj/concat
20:32sexpbot⟹ "([to from]); Returns a new coll consisting of to-coll with all of the items of from-coll conjoined."
20:32mdeboardamalloy: re: comp/fo http://dpaste.com/568868/
20:32jamiltronAh! Let me try using into instead
20:32mdeboardfor mutable state langs
20:34mdeboard->> is like a uh... a signal that what follows is a schematic for how to process raw materials and what to do with it at the end.
20:35mdeboardlearning hath occured
20:35mdeboard,(->> [1 2 3 4 5] (reverse) (first))
20:35clojurebot5
20:35mdeboardalright! gimme five clojurebot!
20:36mdeboard,(->> [1 2 3 4 5] (reverse) (first))
20:36clojurebot5
20:36mdeboardawesome
20:37mdeboardWhat's the time complexity of ->>
20:37gfrlog`it's a macro
20:37amalloy0
20:37gfrlog`O(N)
20:38gfrlog`it's gotta walk through the args to assemble the output code
20:38amalloygfrlog`: c'mon, O(0) because he's asking about runtime
20:38gfrlog`hmm
20:38gfrlog`I guess
20:38gfrlog`good point
20:38gfrlog`macros run at compile time?
20:38gfrlog`I'm not sure if I knew that or not...
20:39mdeboardwait, I think my question was more cmplex than I thought. O(0)?
20:39gfrlog`mdeboard: do you know how macros work?
20:39amalloymdeboard: recall my previous example: ##(clojure.walk/macroexpand-all '(->> (range) (filter even?) (take 5) (reduce +)))
20:39sexpbot⟹ (reduce + (take 5 (filter even? (range))))
20:40amalloythat all happens *completely before* any code is executed, as if you'd written the latter code to begin with
20:41mdeboardso, how come every search engine on earth isn't written in clojure
20:41amalloyuh
20:41mdeboardobv I'm an idiot so bear with me.
20:41amalloyyou seem to be conflating "complexity of code that ->> lets you write" with "complexity of ->>"
20:41mdeboardI see
20:41mdeboardProbably
20:42amalloy->> is nothing but a tool to write your code in a way that's more natural or descriptive
20:43amalloyonce it's expanded, it's as if there was no ->> to begin with, and you wrote the non-natural-feeling version
20:43mdeboardAh I see
20:43mdeboardok
20:43jamiltronSo ->> isn't speeding anything up - it doesn't reduce your algorithm to O(0), it's simply transforming what you wrote to another (possibly) less convenient form.
20:44mdeboard->> seems easier to grok imo
20:44jamiltronchange possible less to possibly more
20:44amalloymdeboard: only if you use it in cases that it makes easier to grok
20:44jamiltronI wrote that incorrectly.
20:45amalloyeg, you can write ##(->> :v (list k) (for [k [1 2 3]]))
20:45sexpbot⟹ ((1 :v) (2 :v) (3 :v))
20:46amalloyor even, god help us, ##(->> k (list :v) (for [k [1 2 3]]))
20:46sexpbot⟹ ((:v 1) (:v 2) (:v 3))
20:46amalloyanyway, that's enough from me. i'm headed home. enjoy 4clojure
20:47jamiltronThanks for the help!
20:47mdeboardamalloy: What about with like 5x more commas
20:47mdeboardoh
20:48mdeboardau revoir
20:48amalloyhar har
21:51dekuderphow does one dynamically add keys to a map?
21:51dekuderpI am trying to create a simple 10x10 map
21:52dekuderp{:0 {:0 {:item building} ... is what I want to create
21:52amalloyassoc?
21:52clojurebotthen its perfect. but of course, there are a lot of other parts too that changes. so after I make assoc :show, is there a problem I make again (def data (assoc data :list ...)
22:03dekuderp,(assoc :0 (assoc :0 '(1, 2, 3)))
22:03clojurebotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$assoc
22:04dekuderp,(assoc {} 'a 1)
22:04clojurebot{a 1}
22:05dekuderp,(assoc {} :a 1)
22:05clojurebot{:a 1}
22:05ihodesthere should be a "cool facts about clojure" website
22:06dekuderpso do I have to write code to automatically prepend the colon to a given symbol name?
22:06ihodes(keyword "h")
22:06ihodes,(keyword "h")
22:06clojurebot:h
22:07ihodes,(keyword 'h)
22:07clojurebot:h
22:09dnolen_(assoc {} [1 2] 'foo)
22:09dnolen_,(assoc {} [1 2] 'foo)
22:09clojurebot{[1 2] foo}
22:14amalloydekuderp: if using keywords as the map keys is inconvenient, then don't use keywords
22:25dekuderpamalloy: what do you mean? how could you use something besides a keyword for a map key?
22:26amalloy<dnolen_> ,(assoc {} [1 2] 'foo)
22:26dnolen_dekuderp: you can use anything for a key.
22:26dekuderp,(keyword '1)
22:26clojurebotnil
22:26dnolen_dekuderp: a keyword is type of object
22:27dnolen_dekuderp: you can use any object for a key.
22:28dnolen_,{["this" #{1 2 3} "is" 'a "krazee" 'key] 'yes-man}
22:28clojurebot{["this" #{1 2 3} "is" a "krazee" key] yes-man}
22:33dekuderpso is that vector being treated as a key?
22:35amalloy&(keys {["this" #{1 2 3} "is" 'a "krazee" 'key] 'yes-man})
22:35sexpbot⟹ (["this" #{1 2 3} "is" a "krazee" key])