#clojure logs

2011-02-21

02:25amalloyDespiteItAll: i was thinking of writing a twenty-questions program for my first foray into clojure web programming
04:35rata_what's the recommended way to generate json strings?
04:43ejacksonc.c.json ?
04:44ejacksonrata_: I've used it for a while no w/o problem
04:44rata_ejackson: ok =) thanks
04:44rata_I had heard about clj-json too, but I'll better go with contrib
04:48ejacksoncontrib is a solid choice
05:14e-userhi all
05:19e-useranyone with experience running clojureclr on mono here?
07:25Dranikis there anything like prolog for clojure?
07:30FossiDranik: logos
07:30Fossigoogle would've found that as well i guess
07:32DranikFossi, thanks
07:51edoloughlinhttps://gist.github.com/837007 — don't understand why my dispatcher doesn't work for []
07:57edoloughlin… or any arg, for that matter.
08:58TimMcDespiteItAll: Write a flatmate contracts website, where people click radio buttons to agree to certain standard options ("Pots and pans [do]/[don't] go through the dishwasher") and then agree to it by verifying an email sent to each person.
08:59TimMcDespiteItAll: There, now you have a website to write that involves user interaction, input validation, a database, and email sending.
09:01charliekiloStupid question: (def x 2) (eval '(+ x 1)) works while (eval (let [y 3] '(+ y 1))) does not. Why?
09:03TimMc,(let [y 3] '(+ y 1))
09:03clojurebot(+ y 1)
09:03TimMc,(let [y 3] (eval '(+ y 1)))
09:03clojurebotDENIED
09:03charliekiloSorry I meant (let [y 3] (eval '(+ y 1)))
09:03TimMcOoh, clojurebot doesn't like eval.
09:04charliekiloMy REPL doesn't either ;): java.lang.Exception: Unable to resolve symbol: y in this context
09:04TimMcIn that case, I don't know the answer.
09:05charliekiloI got it to work with (eval '(let [y 3] (+ y 1)))
09:05charliekilobut thats not what I want
09:06TimMcHmmm... I bet this has to do with symbols -> vars stuff, and let not introducing var bindings.
09:06TimMc...but that's beyond my knowledge, really.
09:07TimMcIn any event, what are you trying to do? Seems like you want quasiquoting instead.
09:10e-useranyone with experience running clojureclr on mono?
09:21fliebelmorning
09:21midshoi
09:41fliebelNot directly Clojure related, but anyway… The Reasoned Schemer mentioned that NAND is a universal binary relation. All other relations can de defined by it. Does such a relation exist for >binary?
09:45fliebelSo, a sensible relation for(for example) a trinary(0, 1 2) number, that can be used to define all other relations, and eventually half-adders and such. If there are non, I'm going to invent them :) (ouch, I hope I'm not saying impossible things now)
09:58dnolenfliebel: is the any-o issue fixed for you?
09:59fliebeldnolen: I havn't tried yet, I've been away the whole weekend. I did read a lot on TRS though.
10:00fliebeldnolen: I'm still intrigued by the number stuff. I can see why it would be slow, but I like it.
10:00dnolenfliebel: nice. well let me know how it goes and if anything else crops up.
10:00fliebelsure :)
10:00dnolenfliebel: it's very beautiful. all sort of arithmetic relationships appear like magic :)
10:01fliebeldnolen: I've been thinking about moving the numbers from binary relations to decimal relations. I'm not sure if it's even possible, or fast(er), but it's an interesting exercise.
10:03fliebeldnolen: I think it would be useful to have some debug option in Logos, to see how many unifications are done for a result.
10:04CozeyHello. Ring passes body to response.getOutputStream. I want to pass a result of XSLT transformation which itself requires an OutputStream. Can I somehow short-circut these? Or do I need to first get a whole output of transformation and then return it as string body to ring. seems inefficient.
10:05dnolenfliebel: yes, that would be very useful, still thinking about how to properly implement debugging facilities. A bit tricky since the whole thing works with lazy sequences.
10:06fliebeldnolen: If I implemented that number stuff, would you want it for Logos, or do I just keep that to myself?
10:08dnolenfliebel: I would definitely consider it. Keep me posted on how it goes.
10:09fliebeldnolen: Great :) I'll start out by converting the stuff from the book to Clojure, and then I plan to see if I can make it any more efficient. I haven't studied computer science though ;)
10:12fliebel(was the any-o bug really fixed in one line?)
10:13dnolenfliebel: only a couple lines. The issue was simple, reduce is not lazy, I replaced it with mplus-concat which is lazy.
10:13Cozeyhmm answering myself: looks like a job for piped streams of java's
10:17Cozeydnolen: wow! this plotter idea is absolutely fantastic!
10:18dnolenCozey: plotter?
10:18Cozeyisn't this Yours? http://www.formconstant.net/
10:18dnolenCozey: heh, yes.
10:20Cozeyas well as one drawing a day :-) hope that's working
10:20dnolenCozey: haven't done much with recently. Got a bit into a Python implementation 2-3 years ago that I haven't touched since. That stuff is fun. Pen plotters are easy to come by and they use a brain dead simple ASCII serial protocol that's well documented.
10:20Fossibit noisy on the console :)
10:21dnolenCozey: also not so much recently, but hope to get back to that.
10:22Cozeywill take a look at logos as well. . i was missing prolog
10:22Cozeyare You using SLD or something more advanced?
10:23dnolenCozey: there's quite a history of pen plotter artists, Vera Molnar is particular cool, http://www.veramolnar.com/diapo.php
10:23Cozeythis is from a plotter?
10:23Cozeybut not programmed I guess?
10:23Cozeyah, black and whites
10:23angermanWhat would be a good datastruction for a mesh to do subdivion on in clojure?
10:25Cozeyso that's where the linear pictures come from
10:25dnolenCozey: not that front image no. http://www.google.com/images?q=vera+molnar
10:26dnolenCozey: not SLD, the algorithms from The Reasoned Schemer, but with Clojure changes for better performance.
10:28Cozeyimplementation discussed in the book is this "Kanren"?
10:29Cozeyinteresting :-) thanks :D
10:32dnolenCozey: Kanren is an earlier implementation by Oleg Kiselyov. miniKanren is distillation of that work by Kiselyov, Daniel Freidman, and William Byrd.
10:33kgrad5_If i have an infinite sequence, let's say something like (iterate #(+ % 2) 1) how would I take all numbers less than some threshold? conceptually i want to do something like (take #(< % 1000) (iterate #(+ % 2) 1)) (i know that doesn't make sense)
10:33gfrlogtake-while?
10:33gfrlogif they're sorted that will work
10:33kgrad5_oh sweet, thanks a lot gfrlog
10:33gfrlog,(take-while #(< % 100) (iterate #(+ % 2) 1))
10:33clojurebot(1 3 5 7 9 11 13 15 17 19 ...)
10:34gfrlogkgrad5_: no problem
10:36chouserwhoever thought that bundling code and data together would promote code re-use was ... wrong.
10:38chouserI don't see any option other than (1) patch someone else's code (2) copy huge swaths of their code and make minor changes, or (3) use reflection hacks to work my will at runtime.
11:01MunksgaardI'm using cake to run a slime server with swank-clojure, but the connection keeps closing. I'm using clojure-1.3.0-alpha4 and swank-clojure-1.3.0-SNAPSHOT... Does anyone know how to get it working?
11:04Munksgaardi can evaluate nil in the slime REPL, but once i try to write (println "something") it closes the connection before i even get to the space
11:09Munksgaardand if i try to use an older version (clojure-1.2.0 and swank-clojure-1.2.0) it just hangs when i try to evaluate nil in the repl
11:15tensai_cirnohello guys. I'am experiencing problems with lein repl. It breaks after first error.
11:16tensai_cirnohttp://pastie.org/1589769
11:17tensai_cirnoemacs swank mode just breaks after first whitespace in parenthesis
11:17tensai_cirnoalso *Versions differ: 2010-06-04 (slime) vs. 20100404 (swank).*
11:17tensai_cirnoin emacs
11:17tensai_cirnoubuntu 10.10, emacs and slime from repo
11:22Munksgaardtensai_cirno: i've got the same problems
11:36tensai_cirnoMunksgaard, got working slime
11:36tensai_cirnoyou need to install it from technomancy repos
11:36tensai_cirnohttps://github.com/technomancy/swank-clojure
11:36tensai_cirnothere's section for emacs
11:36tensai_cirnoand ':dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]]' in project.clj
11:49Munksgaardtensai_cirno: ok, thanks
12:11Cozeywhat's the overhead of "future" ?
12:14gfrlogCozey: seems to call clojure.lang.Agent/soloExecutor
12:15Cozeyand then doing some thread pool magic... but what does it all mean? Is it really lightweight? so You can paralelize some things 'just because you can' or is it not worth it?
12:16gfrlog,(future 20)
12:16clojurebot#<core$future_call$reify__5500@404baf: :pending>
12:16gfrlog,(map deref (map #(future %) (range 10))
12:16clojurebotEOF while reading
12:16gfrlog,(map deref (map #(future %) (range 10)))
12:17clojurebot(0 1 2 3 4 5 6 7 8 9)
12:17gfrlogCozey: no idea :)
12:17gfrlogperformance test?
12:17Cozeyit seems i would need to do that
12:17gfrlogor maybe somebody else will speak up
12:17Cozeybut making benchmarks is quite a taunting task
12:17gfrlogjust don't listen when tasks taunt you
12:18gfrlogthey're only doing it because they're insecure themselves
12:20gfrlogmaybe I shouldn't make fun of strangers
12:43cdddrIf I do something like (call sorted-set some-seq), does it unwind the whole sequence at once, or process it one at a time?
12:48AWizzArdcdddr: it would have to calculate the hash of some-seq.
12:49AWizzArdsome-seq is tested via the hash if it is one of the elements in your sorted-set.
12:50cdddrUhh, my bad, I meant apply not call.
12:50cdddrI basically want to keep unique values from some-seq.
12:50cdddrSorting is nice, but I can do it in another step.
12:51gfrlogcdddr: I'm watching tv and not paying attention, but does distinct help?
12:52cdddrgfrlog: Ah, yes.
12:53cdddrI'm still at the stage where I'm not sure what the stdlib can do. :(
12:53gfrlogeasiest people to help :)
12:54cdddrHahaha, right. It's better like this, though. I remember when I "learned" Python on my own, and then I needed to stick for like 3 months on #python to realise I was being ass-backwards about almost everything. :)
12:55gfrlogthere are so many ways to write bad code...
12:55cdddrYeah. I mean, reimplementing stdlib out of ignorance is bad, but I'd take that over, say, writing COBOL in Java anytime. ;)
12:56gfrlogthe first option sounds a lot more fun
12:56clizzinanyone have any experience with parsing HTML in clojure/java? what's the best library to use?
12:57raekclizzin: enlive is very easy to use
12:57raekit uses tagsoup under the hood
12:57clizzinraek: enlive has functions specifically for parsing? i thought it was a templating library.
12:57raekit does that too... :)
12:57cdddrgfrlog: Oh, trust me. I've had the misfortune of actually seeing COBOL-in-Java. I almost cried.
12:58clizzinraek: interesting, shall check it out. thanks!
12:58raekdnolen made a tutorial that explains both the scraping and templating uses
12:59raekclizzin: minimal example (fetching the title of a page): https://github.com/raek/lcug-examples/blob/master/bot/src/se/raek/lcug/titlebot.clj
12:59clizzinraek: awesome, thanks! btw, any idea how it compares to https://github.com/getwoven/webmine? that's the other one i just remembered which might work well for parsing.
13:02fceccon|aclizzin: check https://github.com/swannodette/enlive-tutorial
13:02raekclizzin: webmine seems to use tagsoup just like evlive, but looks much more specialized towards extraction (disclaimer: I haven't used webmine)
13:03clizzinraek, fceccon|a: great, thanks for the thoughts and advice! i'll play around and see what works best for my use case.
13:31charliekiloStupid question: (def x 2) (eval '(+ x 1)) works while (let [y 3] (eval '(+ y 1))) does not (java.lang.Exception: Unable to resolve symbol: y in this context) ... Why, oh why?
13:31gfrlog(doc eval)
13:31clojurebotDENIED
13:31gfrlog,(doc eval)
13:31clojurebotDENIED
13:31gfrlogdangit
13:32gfrlogI think eval is funny about local bindings
13:32gfrlogby which I guess I mean it ignores them
13:33gfrlogwhat do you get if you (def x 12) (let [x 13] (eval '(+ x)))
13:33edoloughlinAnyone got CCW content-assist for Clojure working? It only does Java for me
13:35gfrlog,(let [def 12] (+ def 5))
13:35clojurebotDENIED
13:37charliekilo13
13:37charliekilosince it sees the first x
13:37gfrlogwouldn't 13 mean it sees the second?
13:38gfrlogI get 12
13:38charliekilooh, I thought you meant '(+ x 1) and just forgot the 1
13:38gfrlogah; yeah I guess that was unnecessarily complex
13:38gfrlogso I would assume that eval just ignores all local 'variables'
13:39gfrlogapparently it does see binding; but that's probably not what you want to do
13:39cdddrUhh, why would eval ignore the local bindings?
13:39gfrlogdunno...why wouldn't it?
13:40TimMcgfrlog: Because it is surprising.
13:40gfrlogthat is a good reason.
13:40cdddrYeah, and I don't see a good reason to ignore them.
13:40gfrlogI should retreat to "I don't know" then
13:41gfrlogmaybe it's harder to execute...
13:41TimMcgfrlog: There is a difference between local let "bindings" and def'ined vars, but I don't know enough about Clojure to say anything further on the subject.
13:41gfrlogbecause the vars are all stored somewhere public, but the local lettings are probably much...slyer?
13:41TimMcI do know that let bindings are not mutable.
13:41gfrlogwell they can be overridden
13:42gfrlog,(let [x 12] (let [x 15] x))
13:42clojurebot15
13:42TimMcSure, but that's just scope.
13:42gfrlogyeah
13:42gfrlogI would think
13:42gfrlogthat
13:42charliekilolet me ask another stupid question: is 'eval' the right function here?
13:42gfrloglettings can be handled at compile time
13:42TimMc("just scope", he said, infuriating language designers everywhere)
13:42charliekiloor is there another one I should use?
13:42gfrlogbut whatever goes into eval has to be handled at runtime
13:42TimMccharliekilo: What do you want to do?
13:43raekthe lexical scope where eval is called is does not "span" into the evaled form
13:43TimMccharliekilo: I ask because you might be trying to reimplement defmacro or something.
13:43gfrlograek: Is that a fancy restatement of "eval doesn't see local bindings"?
13:44raekgfrlog: pretty much. :)
13:44charliekiloTimMc: I am looking at SICP symbolic differentation and want to eval the resulting function with some value of x
13:44gfrlogokay, just making sure I understood
13:44gfrlogwe were wondering why it would be that way
13:44TimMcfrom a language design standpoint, preferably
13:44cdddrYou know what Clojure API docs could really use? "See also:" everywhere.
13:45gfrlogcharliekilo: I'm wondering if macros can help
13:45TimMccdddr: I tend to use clojuredocs.org
13:45gfrlogI assume the "don't write macros" mantra has an implicit "unless you would otherwise be using eval"
13:45charliekilogfrlog: thats what I was thinking, but since I am not modifying executing order, it should be possible without it, right?!?
13:45TimMcgfrlog: Oooh... symbolic differentiation via macros? I'm getting all tingly.
13:46cdddrTimMc: Ooh, that's a gem.
13:46gfrlogmaybe I should stop talking because I actually have no idea what "symbolic differentiation" means and TimMc makes me think that might be important
13:46TimMccdddr: Blame gfrlog.
13:46gfrlogfor the existence of a gem?
13:47cdddrHeh, I meant the clojuredocs site, but hey, that works, too. :)
13:47TimMccdddr: Hah! OK.
13:47gfrlognone of the currently active conversations are not confusing me.
13:48TimMccharliekilo: If you were doing symbolic differentiation of hardcoded expressions, macros *might* be appropriate, as outrageous as that idea seems to me at the moment.
13:49TimMcHowever, I suspect you are receiving sexprs as arguments and wanting to differentiate and evaluate those.
13:49TimMcQuasiquote might help you, actually.
13:50gfrlogI was thinking of macros instead of evaling
13:50gfrlogi.e., for inserting the code
13:50gfrloginside a (let)
13:50charliekiloTimMc: I will try, but it somehow does not feel right ... then again, I have not come up with a good solution either
13:50gfrlognow I'm second-guessing myself though
13:51TimMc(eval `(let [y 4] ~expr))
13:51gfrlogthat was the next thing I started thinking about
13:51gfrlogso as long as that's not dependent on other local bindings...
13:52gfrlogand even if it is you can probably do (eval `(let [x ~x] ~expr))
13:52raekiirc, fogus made a library for these kind of things
13:52TimMcgfrlog: That was my thought as well.
13:53charliekilohmm ... I guess I have to play around multiple options and see what looks nice in the flow of code
13:53gfrlogthe only way to write readable code is with triply-nested macros.
13:54raekcharliekilo: https://github.com/fogus/evalive
13:54raekexample from the docs: (evil '{message "Hello", place "Cleveland"} '(println message place))
13:55raeklooks like something that could accomplish what you are trying to do
13:55cdddrOoh, Python-style eval. :)
13:55charliekiloraek: that looks like it will work ... I'll take a look .. thanks
14:15TimMcAny quick way to turn a seq of maps into a map of seqs?
14:16brehauteg [{:a 1} {:a 2 :b 1} {:b 3}] {:a [1 2] :b [1]} ?
14:17scottjmerge-with concat?
14:17gfrlog,(doc merge-with)
14:17clojurebot"([f & maps]); Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) will be combined with t...
14:17gfrlogscottj: is that a question?
14:18scottjgfrlog: nm
14:18brehautmerge-with isnt quite right
14:18gfrlognow I'm wondering what a function called concat? would do
14:18brehautmerge-with will not call you fn if there is no conflict
14:18gfrlogscottj: sorry, I failed to notice the previous comments
14:19TimMcbrehaut: I know these maps all contain the same keys.
14:19TimMcBut no, merge-with wouldn't work.
14:19gfrlogTimMc: there's an easy way to do this
14:19cdddrbrehaut: How so? You can specify your own key-combining function.
14:20gfrlog(map (apply juxt maps) ...) should be helpful
14:20brehautcdddr: ##(merge-with (constantly :applied) {:a 1} {:b 2})
14:20sexpbot⟹ {:b 2, :a 1}
14:20cdddrbrehaut: Ahh.
14:21gfrlog(into {} (map (juxt identity #(map (apply juxt maps) %)) (keys (first maps)))
14:21gfrlogmaybe could clean that up with ->>
14:22TimMcI think I'll stick with a three-liner instead.
14:22gfrlogbut juxt is fun!
14:22TimMc,(doc juxt)
14:22clojurebot"([f] [f g] [f g h] [f g h & fs]); Alpha - name subject to change. Takes a set of functions and returns a fn that is the juxtaposition of those fns. The returned fn takes a variable number of args, a...
14:23gfrlog(apply juxt maps) is a function that takes a key and returns a vector of the key's value in all the maps
14:23TimMcI kind of see where you are going with that.
14:23gfrlogthe rest is just cruft for tying everything together into a map
14:24gfrlogI would think the (apply juxt maps) part would be useful no matter how you rearrange everything else
14:24brehautgfrlog: are you sure that even runs?
14:25gfrlognope :)
14:25gfrlogI'm sure that it would if I had a few rounds to debug it though
14:25TimMcThese maps only have two keys, and I know them.
14:26cdddrTimMc: Give in to the dark side of premature abstraction! ;)
14:26TimMc(apply juxt my-maps) is a neat trick, but too complicated for this task.
14:26gfrlogmaybe (let [vals-fn (apply juxt maps)] {:a (vals-fn :a), :b (vals-fn :b)})
14:26brehauttim then its simple
14:26cdddrIt's just like premature optimization, but with ore fun and mess. ;)
14:27TimMccdddr: I *might* write a LoM->MoL fn.
14:27TimMcbrehaut: Don't tell me I can destructure this thing...
14:27brehaut,
14:27brehaut(reduce #(merge-with conj %1 %2) {:a [] :b []} [{:a 1} {:b 2 :a 2} {:b 2}])
14:27clojurebotEOF while reading
14:27gfrlogmine had less :a's and :b's in it
14:28brehaut,(reduce #(merge-with conj %1 %2) {:a [] :b []} [{:a 1} {:b 2 :a 2} {:b 2}])
14:28clojurebot{:a [1 2], :b [2 2]}
14:28gfrlogoh nm
14:28brehautyeah its not a 'general' solution
14:28brehauteven easier
14:28brehaut,(apply merge-with conj{:a [] :b []} [{:a 1} {:b 2 :a 2} {:b 2}])
14:28clojurebot{:a [1 2], :b [2 2]}
14:29gfrlogbrehaut: I think I like it
14:29TimMchm
14:30gfrlogmaking use of the good ole' conj{:a function
14:30TimMcAfter I finish making my tests pass, I'll see if I can wedge that in.
14:31gfrlogmake a switch statement with a case for each possible number of maps that there could be
14:31TimMcData structure dilemma!
14:32TimMcI'm traversing a DAG and picking up values. I don't want duplicates, but I want to preserve topological order.
14:32brehaut,(reduce (fn [a [k v]] (update-in a [k] (fnil conj []) v)) {} (mapcat (partial map identity) [{:a 1} {:b 2 :a 2} {:b 2}]))
14:32clojurebot{:b [2 2], :a [1 2]}
14:32brehauta genera solution
14:32gfrlogokay now mine is better
14:33TimMcOK, that used *two* functions I don't know yet.
14:33brehautgfrlog: really? mine runs :P
14:33brehautupfate-in and fnil?
14:33TimMcmapcat and fnil
14:33gfrlogbrehaut: That's cuz you have a higher draft standard for irc
14:33TimMcOh man, mapcat is what I've been looking for for another thing.
14:34TimMcI had to write that once for some functional JS I was doing.
14:34brehautTimMc: haha
14:34brehautTimMc: for is often a more useful way of writing mapcat
14:35cdddrWoah, there's map-indexed? One less function in the chain.
14:37gfrlog,(let [maps [{:a 1 :b 2} {:a 2 :b 2}]] (into {} (map (juxt identity (apply juxt maps)) (keys (first maps)))))
14:37clojurebot{:a [1 2], :b [2 2]}
14:38gfrlogbrehaut: I was assuming his all-maps-have-same-keys condition
14:38brehautok sure. cause otherwise you generate interstitial nils
14:38gfrlogand miss some of the keys if they aren't in the first map
14:40TimMcThat would be the equivalent of a ragged 2D array.
14:40brehautTimMc: vector of vectors is the obvious one
14:40brehautor a map of vectors
14:40TimMcHeh, I guess what I'm basically doing is a transpose.
14:40brehautdepends on your keys
14:43brehautTimMc: if you have a vector of vectors, and you want to transpose its just ##(apply map vector [[1 2 3] [4 5 6]])
14:43sexpbot⟹ ([1 4] [2 5] [3 6])
14:44TimMc$findfn [1 2 1 2 4 1] [1 2 4]
14:44sexpbot[clojure.core/distinct]
14:45TimMcoooh
14:45gfrlogI was trying to figure out how to do $findfn just the other day... digging through the sexpbot source and no luck
14:55amalloygfrlog: it's in sexpbot.plugins.clojure
14:55amalloynear the bottom somewhere
14:55gfrlogamalloy: must have missed it. I was looking at exactly that.
14:56gfrlogI only skimmed the source, so I don't think I actually gleaned any info at all
14:56gfrlogI was hoping it'd be full of (def-thing-you-can-type "$findfn" ...)
14:58amalloygfrlog: it is! if you search for "findfn" you find what you want immediately
14:58amalloy(not $findfn, because the command prefix is configurable)
15:00amalloygfrlog: https://github.com/Raynes/sexpbot/blob/master/src/sexpbot/plugins/clojure.clj#L156
15:01gfrloghmmm
15:01gfrlogsince I didn't know it was called "findfn" I'm not sure if that would have jumped out
15:01gfrlogbut I should clarify that I don't at all mean to criticize the code.
15:04amalloygfrlog: sure? i do so enjoy sulking after being maligned
15:05gfrlogamalloy: absolutely -- I would have been shocked if the information had been accessible within the amount of effort I was willing to put in
15:05amalloylol
15:05gfrlogthen I would have written you a personal physical letter of thanks with a five dollar bill in it.
15:07amalloythe basic concept of findfn took a couple hours and a dozen lines, but all the tweaking necessary to deal with sandboxing and such makes it a huge mess
15:08amalloy$findfn [1] 1
15:08sexpbot[clojure.core/last clojure.core/count clojure.core/peek clojure.core/first clojure.core/rand-nth]
15:08amalloyi always get a laugh when rand-nth makes it into the answer list
15:09cdddramalloy: It only tries the core functions, right?
15:09amalloycdddr: https://github.com/Raynes/sexpbot/blob/master/src/sexpbot/plugins/clojure.clj#L146
15:09amalloy$findfn "test" 2 "te"
15:09sexpbot[]
15:09amalloyhm
15:10cdddrOoh.
15:10amalloy$findfn 2 "test" "te"
15:10sexpbot[clojure.contrib.string/butlast clojure.contrib.string/take]
15:10Cozey$findfn (fn [a b] a) 2
15:10sexpbot[]
15:10Cozeyany way to get functions arity?
15:10amalloyCozey: that is not an easy problem
15:10CozeyI know :-)
15:10amalloysomeone posted a hacky solution to the google group months ago
15:11amalloyCozey: http://groups.google.com/group/clojure/browse_thread/thread/d9953ada48068d78/1823e56ffba50dbb
15:28jweiss_looking for the simplest fn that will return a different value every time it is called
15:28jweiss_(i just care that the values are not equal and don't have isa? relationship)
15:29scottjjweiss_: gensym?
15:29jweiss_scottj: ah good call
15:45cinchjweiss_: (str (java.util.UUID/randomUUID))
15:47clizzinis there a way to use apply when you're calling a java method on a variable-length vector of arguments?
15:48amalloyclizzin: not really. what's your usage scenario?
15:48amalloycinch: that's not guaranteed to be different, though of course the odds are...somewhat in favor :P
15:49clizzinamalloy: i'm using clojure to wrap a java method. the clojure method takes a variable-length list of arguments at the end, and i wanted to just use apply to call various versions of the java method that take different numbers of arguments
15:50amalloyclizzin: the current "best" way to do it is manually, i think. you can hack something up with clojure.lang.Reflector if you want
15:50clizzinamalloy: alright, thanks for the info
15:50cdddr$findfn [1 2 3] [4 5] [1 2 3 4 5]
15:50sexpbot[clojure.set/union clojure.core/lazy-cat clojure.core/concat clojure.core/into]
15:52amalloycdddr: into is the least-awful of those options
15:56cdddramalloy: Yeah, but I'm doing something like (set (concat A B)), so I think concat actually fits better.
15:56amalloycdddr: (into (set A) B)?
15:57amalloy&(into (set [1 2 4 5 2]) [5 7])
15:57sexpbot⟹ #{1 2 4 5 7}
15:57cdddrOooh.
15:57drobatiI'm trying to use slime for the first time and slime-repl isn't showing up when i slime-connect
15:57cdddrAlthough it feels weird somehow.
15:57drobatiI installed slime not from packages.el
15:58amalloycdddr: or (set/union (set A) (set B)) if you like
15:58brehaut&(use 'clojure.set)
15:58sexpbot⟹ nil
15:58brehautamalloy: i dont think b needs to be a set for union
15:58amalloybrehaut: it doesn't, but that's an impl detail
15:58brehaut(union #{1 2 3} [1 3])
15:58brehautamalloy: sure
15:59amalloymight even be better for performance to make them both sets, if A were large and distinct, and B were like [1 1 1 1 1 1 ...]
16:01kjeldahldrobati: Do you have swank-clojure installed?
16:01cdddrx (map println (take 10 some-var)) inside a let... I'm going to debugging hell,
16:01gfrlogcdddr: I don't think (map println ...) normally does much
16:02drobatiI have a dev-dependency in project.clj "1.2.1"
16:02drobatikjeldahl: I use lein swank.
16:02cdddrgfrlog: Hence the take except I lied, I'm doing (count (map... :)
16:02gfrlogcdddr: oh okay
16:03cdddrMy initial, even more clueless version was (drop-while (constantly true)...
16:03gfrlog,(drop-while (constantly true) (repeat "haha"))
16:03kjeldahldrobati: swank-clojure.el is an emacs package. On github. I know nothing about lein swank.
16:03clojurebotExecution Timed Out
16:04drobatikjeldahl: lein installs swank-clojure from github for me.
16:05kjeldahldrobati: It installs an emacs package for you? You're way ahead of me then..
16:05drobatiWait. Not an emacs package.
16:06kjeldahlIt's emacs support you're struggling with, right?
16:06drobatiI believe so.
16:06amalloycdddr: (filter #{} some-var) :P
16:06drobatiThe swank server seems to work.
16:06drobatiBut no repl is showing up.
16:06scottjwhat does slime-connect do?
16:06kjeldahlNo repl inside Emacs you mean?
16:06drobatiyes
16:06drobatiSlime repl spits back a cute message.
16:07drobatiBut no repl (it opens *slime-events* though
16:07drobati)
16:07scottjwhat version of slime?
16:07gfrlogamalloy: (= (constantly true) (comp not #{}))
16:07scottjrecent versions are not supported
16:07gfrlogman if you could compare functions like that we wouldn't need to write programs anymorj
16:08drobatiscottj: I didn't know that.
16:08drobatiI'm pulling from the official slime repo.
16:08drobatibuilding and installing myself
16:09semperosdrobati: try adding this to your .emacs
16:09semperos(slime-setup '(slime-repl))
16:09drobatiI saw that before. Let me try it again but I think it was a bit quirky.
16:10semperosI had slime auto-starting my repl for me, and then "one day" it just stopped, and that solved it for me
16:10scottjgo to slime commit 605f930a or oct 15 2009
16:10drobatishould I eval that then rerun slime-connect
16:11semperosshould do the trick
16:11drobatiits up
16:11semperosgreat
16:11drobatiWorks!
16:11drobatiis the swank repl prompt user>
16:11ossarehmorning all
16:11semperosis for me
16:11drobatiperfect
16:12drobatiThanks semperos, kjeldahl, and scottj
16:12semperosnp, enjoy
16:12drobatiWill do. :)
16:13scottjdrobati: to use slime-fancy you'll need to use an older version of slime I think. http://www.youtube.com/emailataskcom to see some of the advanced slime features
16:14drobatithanks for the link
16:21TimMcWell, that yak looks pretty well shaved: https://github.com/timmc/CS4300-HW3/blob/master/src/timmcHW3/cascade.clj
16:21TimMcNow I can get back to my actual program. >_<
16:22gfrlogso if I'm implementing my own numeric type, I don't get to use the clojure.core/+ and such functions, right?
16:23gfrloggotta use (defn add) and (defn multiply)?
16:24Chousukeyou can define + and * in your own namespace too.
16:24Chousukeyou just need to exclude the core ones
16:24gfrlogyeah, but then other namespaces making use of it can't...
16:24Chousukecan't what?
16:25gfrlogcan't use the overridden functions
16:25Chousukesure they can
16:25Chousukeall functions are namespaced
16:25amalloygfrlog: c.c.generic-math
16:25cnatarenis there a place where there are tasks that need to be done for clojure-clr?
16:25Chousukewhat you can not do is augment the clojure arithmetic operators :/
16:25gfrlogChousuke: and regardless, my implementations would need to use the core ones; so it'd be sticky
16:26Chousukegfrlog: you can reimport them namespace-qualified, it's not that hard :)
16:26Chousukethe use them as core/+ etc.
16:26gfrlogyeah
16:26gfrlogis there some reason arithmetic isn't done as a protocol?
16:26Chousukespeed
16:26stuartsierraDoes `lein test` run with dev-dependencies?
16:26abedratechnomancy, is there a way to get "test" dependencies in lein?
16:27Chousukealso I guess JVM integration/historical reasons
16:27gfrlogstuartsierra: does for me I'm pretty sure
16:28gfrlogI'd say I'm completely sure, but I think you wrote a book about clojure or something, so that puts an upper limit on my sureness
16:28stuartsierraI wrote a book about Clojure, not lein.
16:28gfrlogI didn't write a book about lein
16:29stuartsierraAnd I don't intend to.
16:29gfrlogI infer from having written a book about clojure that you've used lein more than me
16:29stuartsierraNo, I use Maven.
16:29gfrlogokay, my sureness is rising then
16:29gfrloglet's say I'm sure
16:31gfrlogamalloy: c.c.generic.math-functions seems to specifically exclude arithmetic... is there some reason the arithmetic functions weren't defined as multimethods in the first place?
16:31abedragfrlog turns out it does
16:31gfrlogabedra: cool, thx
16:31amalloygfrlog: sorry, i always get these two confused: http://richhickey.github.com/clojure-contrib/generic.arithmetic-api.html#clojure.contrib.generic.arithmetic/*
16:32gfrlogaw man I missed than 5 lines above the other one
16:32gfrlogthe question still stands though
16:41amalloygfrlog: performance
16:42amalloymultimethods would slow the bejeezus out of the huge majority of apps that don't need to override +
16:42gfrlogI guess clojure.core/+ can be redeffed manually anyhow, right? perhaps to the c.c.generic.arithmetic versions?
16:43gfrlogis that a disastrous idea?
16:45brehautgfrlog: dont redefine it; refer-clojure :exclude it out of the way, and use :only the one from c.c.g.a
16:46gfrlogbrehaut: yeah...I was thinking I'd get the benefit of the operators working anywhere in the app, but I guess being explicit is bester
16:47gfrlogand won't slow down random other libs that don't need it
16:47brehautredefining this is pretty non-idiomatic clojure i think
16:47brehautyup
16:50gfrlog,(let [do 12, if 19] (+ do if))
16:50clojurebot31
16:51brehautever looked at PL/1 ?
16:51gfrlognope
16:51brehautIF IF THEN THEN ELSE ELSE is approximately valid code
16:51gfrlogthat sounds useful
16:51brehautkeywords were explicitly not reserved
16:52brehautit was an early example of overengineering
16:52brehauti think it might have had something to do with multics
16:53amalloygfrlog: ##(let [do 10 if 40] (do if))
16:53sexpbot⟹ 40
16:54gfrlogamalloy: Okay what the heck.
16:54amalloyspecial forms are only special in the function position
16:55gfrlogand special forms are always special in the function position?
16:55gfrlogthat's the part I didn't expect
16:55amalloyyes
16:55amalloy&(let [do 10 if 40] (if do 5))
16:55sexpbot⟹ 5
16:55gfrlogright
16:56gfrlogapparently you can't let reader macros though
16:57amalloygfrlog: not sure what you mean, though either way you're right
16:57gfrlogI mean
16:57gfrlog,(let [' 15] (+ 489 '))
16:57clojurebotUnmatched delimiter: )
16:59amalloyi'm not sure that counts as a reader macro, but maybe. it doesn't seem surprising to me: you can't let [ as a local either
17:00gfrlogyeah I don't know what I was thinking really
17:00gfrlogamalloy: the clojure cheatsheet says it's a reader macro
17:00gfrlogand the clojure cheatsheet has never let me down
17:01amalloyokay. i thought the name "reader macro" was reserved for things starting with #, but i seem to be wrong
17:01brehautmore importantly i think http://clojure.org/reader calls it a reader macro too
17:02gfrlogI assumed that any syntax that wasn't parentheses was a reader macro
17:02gfrlogbut they don't list map literal or set literals etc, so I'm confused
17:03brehautgfrlog: a map literal becomes a map in the AST, a ' becomes a list
17:04brehautexcuse the fuzzy use of AST
17:04gfrlogbrehaut: I would have expected that a map literal gets translated into a call to (hash-map)
17:04gfrlogmaybe that's less efficient though
17:06brehautgfrlog: but maps and vectors have meaning for evaluation, so you dont want to turn them into lists to be created at runtime
17:07gfrlogthat is a terribly good point
17:07brehaut(again, sorry for the overly impress wording. im failing to express myself right)
17:07nickikWhy not, works in CL :)
17:07brehautman i fail at words today
17:08gfrlogsince #{} is not a reader macro either, presumably we could use sets for stuff
17:08brehautoverly imprecise wording
17:08gfrlog,(let [#{a b} #{1 3}] (+ a b))
17:08clojurebotjava.lang.Exception: Unsupported binding form: #{a b}
17:08gfrlogI support that binding form
17:08brehauti dont think we need to get into a common lisp / clojure debate thanks all the same
17:09gfrlog(let [[a b] #{"I wish" "this worked"}] a)
17:09gfrlog,(let [[a b] #{"I wish" "this worked"}] a)
17:09clojurebotjava.lang.UnsupportedOperationException: nth not supported on this type: PersistentHashSet
17:09nickikI didn't want a debate it was just a fun anecdot
17:09gfrlognickik: While I see your point, I respectfully disagree.
17:10amalloy&(let [[a b] (seq #{"I wish" "this worked"})] a)
17:10sexpbot⟹ "this worked"
17:10gfrlognevermind that statement was probably more confusing than funny
17:11gfrlogamalloy: Yep, that's what I ended up doing, all over my code...
17:12brehautgfrlog: there is little to gain from using sets in forms though
17:12brehautthe binding form is a maybe
17:13gfrlogbrehaut: I know. There's just fun.
17:13gfrlogadd some randomness to which variable gets which value
17:13brehauthah
17:13brehautindeed
17:14amalloyit makes some sense for a sorted-set though
17:14brehautamalloy: sure, but there is no literal, so it would be a bit awkward for forms
17:14gfrlogno literal _yet_
17:14brehauthah
17:15brehaut#>{1 3 2}
17:15gfrlogI don't think that's beatable
17:15TimMcbrehaut: Why not #<{1 2 3} ?
17:15brehautwhy not indeed
17:15brehauti think they are both less good than
17:15brehaut#{< 1 2 3} or #{> 1 2 3}
17:16gfrlogaugh
17:16TimMc,>
17:16clojurebot#<core$_GT_ clojure.core$_GT_@1160709>
17:16brehautand {> 1 :a 2 :b}
17:16amalloybrehaut: that form is evil
17:16TimMcbrehaut: < is already a symbol
17:16gfrlog,(let [<{ "party-hat"] (println "I'm wearing my" <{))
17:16clojurebotUnmatched delimiter: ]
17:16brehautTimMc: so is >
17:17TimMcbrehaut: As in, having it inside the braces is ambiguous.
17:17brehautso is outside
17:17TimMc,{< :a 1}
17:17clojurebotjava.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 3
17:17brehautbecause then its not consistent with maps
17:17brehautits ambigous for maps both ways
17:17TimMcOutside with a # in front, it isn't ambiguous.
17:18gfrlogwe need a syntax for queues too
17:18brehautand if the sorted-map and sorted-set literals arent consistent, someone would need to be punched in the throat
17:18TimMcHmm, sorted map...
17:18brehaut,(sorted-map 1 :b 4: a :2 :d)
17:18clojurebotInvalid number: 4:
17:19brehauthah whoops
17:19brehaut,(sorted-map 1 :b 4 :a 2 :d)
17:19gfrlogis not, I counted to 4: this morning
17:19clojurebot{1 :b, 2 :d, 4 :a}
17:19gfrlogoh man I think I've spent most of the day in irc
17:20gfrlogmake sure you guys work out a syntax for finger trees too
17:20brehautnot everything needs a literal :P
17:22amalloybut brehaut, then how could anyone use my new racecar-type objects in a macro?
17:22brehautamalloy: they can go use perl and write a text munging macro ;)
17:22amalloy#<==]blue should be added to clojure.core
17:22amalloyfor rocket ships with colors
17:23brehauti dont tihnk you should force one colorspace on the definittion of colors
17:23nickikAre finger trees going to be 1.3?
17:23clojurebotexcusez-moi
17:24brehautwe need to be able to define colors using rgb, bgr, cymk, X,Y,Z, X',Y',Z', pantone and css
17:25amalloybrehaut: why stop there? let's add color gradients
17:26brehautnow i understand why CL extensible reader macros are a bad idea :P
17:32jweiss_i hate to bring this up, but the "Latest News" section at http://clojure.org is not new at all
17:33jweiss_I think the newest item there is 6 months old or more
17:33brehautthere is a new piece of clojure the language news?
17:34jweiss_i only mention it because there are people I'm trying to sell clojure to, they notice nothing changes there, and they tend to think the language is not thriving which is not true
17:34jweiss_brehaut: isn't there?
17:35brehaut'work continues on 1.3' every day is pretty uninformative news
17:35brehautcompare it to python.org/news/
17:36brehautmajor releases, major cons, books about the language
17:36brehautif you want to see the nitty gritty then dev.clojure.org is a hive of activity
17:37Chousukethe dev page doesn't look superactive either to be honest. I have no idea where all the stuff is happening.
17:38jweiss_brehaut: i guess i'm saying it's better to redefine "news" to include smaller items
17:38jweiss_than to have the page go untouched for so long
17:38brehautjweiss_: personally i'd rather people worked on the language than the news page is all im saying
17:38jweiss_i agree - that's why i hated to bring it up.
17:39jweiss_maybe the news page is not necessary
17:39jweiss_i mean, what good is the announcement that 1.1 is released?
17:39brehautif you want mroe noisy general community news, the ML, dev ML, planet.clojure.in, disclojure.org all provide a huge range of stuff
17:40jweiss_brehaut: i'm not saying this because i have difficulty finding news
17:40jweiss_there's plenty of other sources
17:40brehautjweiss_: i just dont see how you could invent more news for clojure.org
17:40jweiss_i'm just saying that if the official site has a news section, it should contain actual news :)
17:40jweiss_not links that are 6 months to 2 years old
17:41brehautso you would rather it was empty?
17:41brehautor had one item
17:41drobatiI'm not sure what I'm doing wrong with slime. But I've got a file that is connected to slime, with a -main in it. I've C-c C-k, but am failing to call the function in the repl.
17:41jweiss_yes. having it gathering dust like that is a little embarrassing for the language. makes it appear that it is not being actively worked on and used (even though that is not true)
17:41drobatiI'm extremely new to this, so I know I'm doing something wrong.
17:42jweiss_brehaut: i don't want to be one to complain and not offer to help so i'd update the news section at least occasionally if someone let me :)
17:42amalloydrobati: is your repl prompt in the right namespace?
17:42drobatiuser>
17:42drobatido i have to apply a ns to it?
17:43drobatiI've seen something about it somewhere.
17:43drobatiI think in the videos someone linked me earlier.
17:46amalloydrobati: to call a function from your foo namespace, your repl should be in that namespace (with ns foo)
17:47drobatithanks
17:47drobatididn't understand that
17:50raek(in-ns 'the-ns) is safer than (ns the-ns), since it wont't auto-refer clojure.core vars
17:50Stavroshello!
17:51Stavroshow can i retrieve the second-to-last element from a vector?
17:51raek(nth v (- (count v) 2)) ?
17:51Stavrosoh, isn't there a sort of reverse-nth?
17:52raekwell there is. (second (rseq v))
17:52Stavrosi see, thanks
17:53raektraversing the vector backwards has linear time complexity
17:53raeknth is always constant time* for vectors
17:53Stavrosi only want two elements, so that's fine
17:54drobati(in-ns 'name.space) worked. Thanks raek and amalloy.
17:55raekdrobati: in case you use Emacs: you can press C-c M-p in the source buffer to switch to that namespace
17:55drobatiThank you for that binding.
17:55amalloyStavros: ##(peek (pop [1 2 3 4 5]))
17:55sexpbot⟹ 4
17:56Stavrosamalloy: ah, thanks
17:57raekthe readme of swank-clojure lists many *really* useful bindings. I recommend trying them if you haven't seen them
18:02drobatiraek: I think I glanced through it on github.
18:02drobatiWell the bindings part.
18:33brehautis there a function that takes a seq and a predicate and returns [(take-while s) (drop-while s)]
18:33brehautand i forgot the pred in that expression
18:36brehautits called span in haskell
18:37dnolen,(group-by even? [1 2 3 4 5 6 7 8 9 0])
18:37clojurebot{false [1 3 5 7 9], true [2 4 6 8 0]}
18:38dnolenbrehaut: ^ ?
18:38brehautdnolen: not quote
18:38brehaut(span even? [2 4 5 6 7 8]) -> [[2 4], [5 6 7 8]]
18:38brehauthypothetically
18:40sattvik,(split-with #(< % 5) (range 10))
18:40clojurebot[(0 1 2 3 4) (5 6 7 8 9)]
18:40danbell,(split-with even? [2 4 5 6 7 8])
18:40clojurebot[(2 4) (5 6 7 8)]
18:40brehautah excellent. thanks!
18:50danbellanyone feeling charitable and want to explain to me why swank-clojure is both an elpa package and a lein plugin?
18:51danbellI'm 99% certain I'm confusing old blog posts with the current Way To Do Things
18:54dnolendanbell: I think swank-clojure in ELPA is just the machinery for the protocol, the client so to speak. the swank-clojure.jar is the server and it needs to be on the classpath of your current project. might be wrong tho.
18:54danbelldnolen: thx, but then what's slime for?
18:55dnolenSLIME is the mode.
18:55danbellah
18:56danbellgotcha, thx
18:58dnolendanbell: http://bc.tech.coop/blog/081209.html, nice graphic describing the relationship.
19:00danbellwhere does clojure-mode fall in there?
19:03dnolendanbell: clojure-mode is just syntax-highlighting and indentation really.
19:03danbellah
19:03danbellthe pieces are falling into place
19:04danbellok, thanks a lot
19:04danbellwas banging my head there
19:04dnolenit's all pretty confusing. crazed Lispers.
20:34amalloybrehaut: split-with is definitely the way to go, but there's also http://clojuredocs.org/clojure_contrib/clojure.contrib.seq/separate if you want something slightly different
20:34brehautamalloy: cheers
21:11TimMcI wrote a program state dependency manager that allows you to (lazily?) propagate recomputations through your application's state: https://github.com/timmc/CS4300-HW3/blob/master/src/timmcHW3/cascade.clj
21:12TimMcBasically, you give it a DAG with a "cleaner" function at each vertex. When you mark a node dirty, that propagates out to all dependant nodes, transitively.
21:14TimMcWhen you call clean on a node, it cleans all the dirty dependency nodes, then calls the node's own cleaner thunk (which does something in your app) and returns the new state with the nodes marked clean.
21:14TimMc1) Does anybody else find this useful or interesting? 2) If so, what should I call it?
21:15amalloyTimMc: sounds neat. i don't know what i'd find it useful for
21:15TimMcI wrote it for a graphics program.
21:16TimMcUse case: The user hits undo. Toolbar buttons need to be en/disabled, undo/redo menus change state, canvas is redrawn, etc.
21:16amalloyi wonder how you discover which nodes to call clean on. you can't call clean on the root node, because it has no dependents
21:16TimMcI got tired of debugging all these state recomputation cascades every time I added a feature.
21:17TimMcamalloy: https://github.com/timmc/CS4300-HW3/blob/master/src/timmcHW3/core.clj#L446 <-- I created an :all node that depends on :gui and :painting, each of which depends on several other things.
21:17TimMcSo, you can have logical nodes that have nil cleaners.
21:18TimMcChecking if a given node is clean is pretty much a constant time operation.
21:20brehautamalloy: the ? macro to the rescue
21:20amalloybrehaut: yeah?
21:20brehautim debugging mess of a tokenizer
21:21amalloyyeah, debugging messes is the use case :P
21:21brehautyes :)
21:26TimMcThe ? macro?
21:26amalloyTimMc: something i gisted a while ago
21:27brehauthttps://gist.github.com/c93c37345c49c47dcfa2
21:28brehautwhat does it do ?
21:29amalloybrehaut: it's not a special operator or anything. it "just" quotes the result of unquoting (quote x)
21:29brehautohright
21:29brehauthaha
21:29amalloy&`[x '~'x]
21:29sexpbot⟹ [clojure.core/x (quote x)]
21:30TimMcI'm struggling to read this thing.
21:30amalloyi guess more apt would be ##`[x 'x '~'x]
21:30sexpbot⟹ [clojure.core/x (quote clojure.core/x) (quote x)]
21:30TimMcI need to play with macroexpand-1 a bit.
21:32TimMc'~' = quote unquote quote?
21:32amalloyyeah
21:33TimMcSo that's... (quote (unquote (quote x)))
21:33amalloyie, it's the same as ', except that you want to leave the syntax-quoting context and enter a regular-quoting context
21:33brehautamalloy: you'll be happy to know i resisted the urge to use regexps to write this parser
21:36joshua__Is it possible to execute another Clojure program from within a Clojure program? I have a list of items in a queue and a program for processing that list of items. I have a separate program which adds items to the queue and I want to give that program the ability to say, "process the queue if it not already being processed."
21:37joshua__One way to handle this that I've considered is making a cron script that runs the first program every few minutes.
21:38joshua__(note the processing is scraping a website, the separate program is a website that allows you to add items to the queue)
21:38brehautjoshua__: why is the consumer not blocking on reading the queue
21:39joshua__brehaut, I don't understand?
21:39brehautjoshua__: are you familiar with the idea of blocking?
21:40amalloyjoshua__: he suggests having the processing program always be in "processing mode", and wait if there's nothing to do
21:40joshua__Oh... I hadn't even considered that options. That sounds like the way to do it.
21:41joshua__brehaut, my understanding of blocking is that it means that one program can't reach the resources that another program is using.. am I way off?
21:41amalloyjoshua__: yeah, you are
21:41joshua__Goes off to read wikipedia, unless you guys have better links.. yeay learning
21:42amalloyi'm having a surprisingly hard time finding a good link
21:42joshua__Oo. I think I was confusing blocking with locking..
21:44amalloyjoshua__: amusingly, the best i could do is an msdn article: http://msdn.microsoft.com/en-us/library/aa365683%28v=vs.85%29.aspx
21:50amalloyah, or http://www.makelinux.net/ldd3/chp-6-sect-2.shtml
21:53TimMcamalloy: I don't think I'm ready to understand the inner workings of macro expansion, namespaces, and symbols yet. I'll leave that ? macro for when I am.
21:54amalloyTimMc: wise words
21:54brehautamalloy: want a code improving challenge?
21:54amalloyoh noes. sure
21:54brehauthah
21:54brehauthttps://github.com/brehaut/ring/blob/master/ring-core/src/ring/middleware/accept.clj
21:54brehautits a tokenizer for the spec of 14.1 of http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41
21:55amalloybrehaut: s/seperat/separate. am i done yet? :)
21:55brehauthah you dont have to do anything
21:56brehautbut yse, i cannot spell
21:56amalloy(def token-char? (complement illegal))
21:56brehauthah yes
22:00joshua__Alright, so blocking basically means that you put a thread to sleep until some event occurs that lets you know you can now deal.
22:00brehautjoshua__: effectively, but you shouldnt be putting the thread to sleep yourself
22:01joshua__brehaut, alright, how would you put it to sleep if your not allowed to put it to sleep yourself?
22:02brehautyour queue should implement a blocking read
22:02amalloyjoshua__: ##(read)
22:02sexpbotjava.lang.Exception: EOF while reading
22:02brehautyou jsut read from the queue
22:02amalloyi'd drop the cond in quoted-string and try to combine the (recur) clauses into one since they're pretty similar, plus lift some of the repetition into an enclosing let; make it more like (if (empty? ...) [..] (let [next (ffirst cs) tail (drop 2 cs)] ...))
22:03brehautjoshua__: in clojure, lots of reference types implement blocking on deref, eg (def p (promise)) (doto (Thread. (fn [] (Thread/sleep 3000) (deliver p 1))) .start) @p
22:04brehautrun those three in a repl one at a time
22:04brehaut@p should pause for a couple of seconds and then return 1
22:04brehautthats because the promise blocks until it has a value delivered to it
22:04brehautamalloy: sure that makes sense
22:05amalloyjoshua__: you read from streams (java or c++) all the time, right? like sockets, for example?
22:06joshua__amalloy: I've done it before, but not all the time. Only once when I made a internet capable chess game for my an end-of-semester project.
22:06amalloywhen you do (.read sock), if there's data available, you get it immediately; if not, your process falls asleep until there is. this happens transparently to your program so you don't need to thing about it
22:07amalloyfile IO is the same: the data usually isn't available the second you ask for it, so your process falls asleep for a millisecond or two while the disk spins up
22:07joshua__Oh this is making a lot more sense now.
22:07joshua__I was thinking in terms of a database I would read the queue from instead of a socket that I would send it through.
22:08amalloyso the most straightforward way (maybe not best) to implement brehaut's suggestion is to write your processing program as a server that listens to some local socket and pulls events out of it
22:08amalloythe "add work" program connects to that local socket and dumps in some work
22:08brehautjoshua__: what queue implementation are you using?
22:08joshua__and than the code for submitting an item to the queue would push something into that .
22:08joshua__brehaut, haha.. I wasn't. I was using a table in mongodb ;p
22:08brehautjoshua__: oh.
22:09joshua__brehaut, but conceptually it is a list of things to process.. ;p
22:09brehautjoshua__: conceptually yes, but on the other hand, there are a heap of good queue servers around
22:09brehautand java APIs are pretty common
22:10joshua__brehaut, I agree that your guys ideas are better than my way of doing it. I think I'm going to implement amalloy's suggestion unless someone wants to toss out a better approach.
22:11brehauthttps://github.com/robey/kestrel ?
22:11brehautyou'll learn stuff from doing it by hand with sockets
22:12joshua__I think that is the way I want to go in part for the learning and in part because kestrel sounds like overkill
22:14joshua__Thanks for the help guys. Best computer science education time can buy in #clojure ;)
22:16brehautno worries
22:16amalloyprogramming with birds is always overkill
22:16brehauthaha
22:20brehaut$findfn [\a \b \c] true
22:20sexpbot[clojure.core/== clojure.core/sequential? clojure.core/reversible? clojure.core/distinct? clojure.core/boolean clojure.core/vector? clojure.core/counted? clojure.core/associative? clojure.core/< clojure.core/= clojure.core/> clojure.core/>= clojure.core/<= clojure.core/ifn? clojure.core/coll?]
22:20brehaut$findfn [\a \b nil] false
22:20sexpbot[clojure.core/keyword? clojure.core/chunked-seq? clojure.core/fn? clojure.core/not= clojure.core/nil? clojure.core/string? clojure.core/sorted? clojure.core/false? clojure.core/true? clojure.core/symbol? clojure.core/number? clojure.core/integer? clojure.core/seq? cl... http://gist.github.com/838151
22:21brehautwaaay to general
22:21brehauti fail
22:28TimMc$findfn [\a \b \c] true ==
22:28sexpbot[]
22:28TimMc:-P
22:29TimMcbrehaut: What are you looking for, anyway?
22:30brehaut(every? identity [a b c])
22:30brehautsomething to test that none of the vars are nil
22:30TimMcor false
22:31TimMc,(every? (complement nil?) [\a \b "c"])
22:31clojurebottrue
22:31TimMcBut you want a single fn?
22:31brehautTimMc: i know that they arent going to be false
22:31TimMc(apply and [\a \b \c])
22:32TimMc:-P
22:32TimMcI always forget I can't do that.
22:33rabidsnailCan I compile a clojure namespace to java bytecode and put it in, for example, a database? Or does bytecode have to go on the filesystem?
22:35TimMcIdiom/philosophy question! I'm developing this small library. Should I check for and throw exceptions on bad inputs, or should I expect relying code to give good inputs?
22:35TimMc(Relying code will only hurt itself with bad inputs.)
22:35brehautyou should check for bad inputs, but throwing exceptions is debatable
22:36amalloybrehaut: you'd rather return nil?
22:37brehautamalloy: no :P but 'exceptions' is a bit debatable
22:37amalloybrehaut: if you're checking for bad inputs, and not returning nil or throwing an exception, what are you doing when you get a bad input?
22:37brehautpass back some sort of fault type?
22:37brehautgets a bit monadic though
22:38TimMcbrehaut: They generally return nil on bad inputs anyway, just due to implementation.
22:41brehautTimMc: its not too bad if the input is simple
22:42TimMcMaybe I'll just put validation on the main, non-recursive API calls.
22:42TimMcShould catch most client errors that way.
22:43brehautTimMc: i think c.c has some error handling librarys that make exceptions better
22:43TimMcI don't care about catching them, I just want to fail fast if the client is passing in bad args.
22:43TimMcBut that's good to know.
22:44brehautwel if you dont care, then nil :P
22:44rabidsnailIs it still the case that not all of the core Clojure datastructures are serializable?
22:44rabidsnailI remember that being true in 0.9
22:45rabidsnail(and maybe 1.0, although I stopped using clojure around then)
22:45TimMcbrehaut: That won
22:45TimMcThat won't make the client fail fast.
22:45skelternetserializable?...as in java.io.Serializable?
22:45rabidsnailyeah
22:46TimMcI know this because my own client code was passing in a bad keyword, and I was getting nil propagation tht I only detected later.
23:27skelternetI could ( reduce into myListOfVectorTuples myOtherListOfVectorTuples myOtherListOfVecotrTuples) to produce my desired list of all vectors, but I can't help but think there is an easier, more idiomatic and lazy way.
23:30amalloyskelternet: ummmm, did you ask an actual question?
23:30skelternetheh...lazily? sort of?
23:30skelternetI think I expressed angst, rather than actually asked it.
23:31spewnskelternet: lazy-cat?
23:31amalloyspewn: afaik there is no reason to use lazy-cat after 1.1.0. concat is lazy
23:31spewnGood to know, thanks.
23:33skelternetI'll look at lazy-cat again. It was returning lists of lists and I was trying to unify into one large list.
23:34skelternetor seq
23:34spewnskelternet: Like amalloy said, look at concat instead.
23:35amalloyskelternet: to glue together a list of lists into one list of all the sub-elements, (1) make sure you actually want to do it, (2) (apply concat list-of-lists)
23:36amalloy&(apply concat [[1 2] [3 4 6] [9]])
23:36sexpbot⟹ (1 2 3 4 6 9)
23:36skelternetThanks! I've actually had an itch to second-guess the assumption (1)
23:38amalloyif you're getting the list of lists from a (map ...) or (for ...), you can generally cut out the middle man by asking that process to give you a single list to begin with
23:43skelternetit's a list comprehension that is feeding table names to a function that returns column definitions extracted from a remote wiki page.
23:44skelternetI'll explore tweaking the for or the function (which I'm sure has a for in it as well)
23:46tomojlazy-cat doesn't even evaluate the coll exprs until needed
23:46tomojI can't think of an example, but it seems like that could be useful
23:50brehaut"java.lang.Exception: Unable to resolve symbol: in this context (NO_SOURCE_FILE:0)"
23:50brehautanyone seen an error like that before?
23:52skelternetdo you have a lone apostrophe next to a character that appears to be blank ?
23:52joshua__( )
23:54brehauthmm nothing like that
23:55joshua__I think I get errors 'like' that when I try to call a function that doesn't exist.
23:55joshua__,(as)
23:55clojurebotjava.lang.Exception: Unable to resolve symbol: as in this context
23:55amalloybrehaut: you were doing stuff with \tab or something, right? is it possible that you have a macro that's not quoting \space properly?
23:56brehautits possible…
23:56brehautbinary chop ATM
23:57amalloy&(let [x (symbol \space)] `(var ~x))
23:57sexpbotjava.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
23:57amalloy&(let [x (symbol " ")] `(var ~x))
23:57sexpbot⟹ (var )
23:58amalloya bit comical that (symbol " ") is even allowed, but...
23:59brehautha yeah
23:59brehauti tihnk i have a hidden character
23:59brehauti removed everything and it still balked
23:59amalloybrehaut: i've always suspected you of having character after all