#clojure logs

2011-07-16

00:43mdeboardtechnomancy: I'm getting that darn "java.util.concurrent.RejectedExecutionException" again... swank 1.3.2
01:44amalloymdeboard: what did you do to fix it last time? (also would you mind killing mdeboard_? he's vexing my tab completion)
02:00amalloymdeboard: you're the one i was arguing with about github's clojure parser/highlighter, right? apparently they use pygment to color stuff
02:03amalloyfrom what i can tell, whoever wrote pygment's clojure plugin just gave the scheme plugin a mild facelift and a different list of keywords - there's some stuff that's definitely not right
05:33shtutgartHi. How can I specify maximum value of y-axis in the Incanter chart? e.g. (bar-chart [:a :b :c] [10 20 30]) gives me Y values from 0 to 30, but I need maximum value of 100
05:36Dranikhi, shtutgart! do you remember the function wrap-codepage which you've shown me?
05:37Dranikdoesn't it break CSS?
05:38shtutgartit shouldn't (unless your CSS files have a different encoding)
05:40Dranikyeah, it was in ascii...
05:40Dranikbut how about the other types of files?
05:42shtutgartah, yeah, it sets content-type to text/html, so you have to wrap only the handler which serves your pages
05:44Dranikyep :-)
05:46Dranikhere is the best example of ho to deal with the utf8
05:46Dranikhttp://code.google.com/p/world-of-meme/source/browse/src/main/clojure/net/marigolda/templating_start.clj?spec=svn42b4a10a706bab53f89a0efb50610a50bfa8444a&r=42b4a10a706bab53f89a0efb50610a50bfa8444a
05:46Draniksee the function wrap-charset
05:56shtutgartyeah, it much more general. Interesting, why some similar thing doesn't included in compojure itself
05:59Dranikprobably noone did a pullrequest or issue
05:59Draniklet me try...
06:00Dranikactually I don't know, probably it should be a ring middleware
06:02shtutgartah, see https://github.com/mmcgrana/ring/commit/2b3f560e9d9c15a8da0ec626f0f10bf9c5014ff4
06:11Dranikshtutgart, dunno when it will be available for testing
06:11Dranikbut I guess it should be so
06:11Dranikwaiting for weavejester to talk to him about his commit :-)
06:59rhebushello
07:00fliebelhi
07:00rhebuswhat's an idiomatic way of returning a map with the values modified by a function?
07:00rhebusI've got a few options but they don't feel right
07:01rhebusfor example, (merge-with (fn [x y] (inc x)) my-map my-map) to apply inc to vals of my-map but it's horribly abusive
07:01fliebelrhebus: can you paste a few lines? Sounds to me like you want to do (fn foo [m] (assoc m :foo 2 :bar 3))
07:01fliebelhm
07:02rhebusno, i want to apply a fn to each val of a map
07:02shtutgartsomething with update-in
07:03fliebelwhat about (into {} (zipmap (keys m) (map inc (vals m))))
07:03fliebel&(let [m {:a 1 :b 2}] (into {} (zipmap (keys m) (map inc (vals m)))))
07:03lazybot⇒ {:b 3, :a 2}
07:03shtutgartrhebus: btw, we have a conversation about including function update (like (update {:a 1 :b 2} :a inc :b dec)) some days ago
07:04shtutgartbut I forgot to post the suggestion on the google group
07:04rhebusthose look better than what I had
07:05rhebus(map (fn [ [x y] ] [x (inc y) ]) my-map) was my next try, but that's a list of vectors, not a map
07:05fliebelrhebus: you can use (into {}) with that as well.
07:06rhebusso keys and vals are guaranteed to preserve respective order? that's kinda neat I guess
07:06fliebelzipmap is just a fancy way of avoid handling the key in the map.
07:06fliebelrhebus: yea, that's guaranteed as far as I know.
07:07rhebuswait, why do you need into {} with zipmap?
07:07rhebus&(let [m {:a 1 :b 2}] (zipmap (keys m) (map inc (vals m))))
07:07lazybot⇒ {:b 3, :a 2}
07:07fliebelrhebus: uh, yea, I'm to used to Python.
07:07rhebus:)
07:08rhebusthanks for your help, much appreciated
07:08fliebelIn Python, zip just goes from [1 2 3] [4 5 6] to [1 4] [2 5] [3 6]
07:10rhebusI'm used to perl, where i'd probably copy-and-mutate
07:13tomoj(update {:a {:b 3 :c 4}} [:a :b] inc [:a :c] dec) too would be nice
07:13tomojoh, can't have both
09:50xom_approveshi there
09:50xom_approvesis there an idomatic pattern for this? http://pastebin.com/R6FEvtJF
09:50xom_approvesi'm really new to clojure, btw :)
09:51raekxom_approves: (map extract xml-seq) I believe
09:52xom_approveshm
09:52xom_approvesoh right the paste is simplified
09:52raekmap is lazy, though
09:52xom_approveslazy is good here
09:53raekbut otherwise the looping code looks good
09:53xom_approvesbasically i need a custom accumulation
09:53xom_approvesah okay
09:53raekreduce might be applicable too
09:54xom_approvesgod, yes so simple
09:54xom_approvesthanks raek
09:54raek(reduce #(conj %1 (extract %2))) xml-seq)
09:54raek(reduce #(conj %1 (extract %2))) [] xml-seq)
09:56xom_approves(reduce #(merge %1 (extract %2)) {} xs) in my case
10:28shtutgartHi. How can I specify maximum value of y-axis in the Incanter chart? e.g. (bar-chart [:a :b :c] [10 20 30]) gives me Y values from 0 to 30, but I need maximum value of 100
10:50cmbntr_account 0 off
11:38shtutgart,(.getMessage (Exception. "foo"))
11:38clojurebot"foo"
11:39kephaleis there a way to establish symbol bindings for a let from a map? i.e. (let-map {:a 17} [b (inc a)] (inc b))
11:39kephalesince let is a macro apply can't be used
11:40shtutgartkephale: if a map should be evaluated in runtime, then no, I think
11:41shtutgartAny ideas why I'm getting "java.lang.IllegalArgumentException: foo" on (.getMessage (IllegalArgumentException. "foo"))?
11:42shtutgart(of course actually there is more code)
11:44shtutgart(try (throw (IllegalArgumentException. "foo")) (catch Exception e (.getMessage e)))
11:44shtutgart,(try (throw (IllegalArgumentException. "foo")) (catch Exception e (.getMessage e)))
11:44clojurebotshtutgart: Cool story bro.
11:44kephalelol
11:45shtutgarteh... I'll better do it via private msgs
11:51kephaleah, push-thread-bindings
11:52kephaleerr with-bindings seems like the proper thing to use
11:53shtutgartbut you've said you need locals?
12:00kephalewell, i really just care about being able to establish bindings from a map, and update the map with new bindings in a sequential let-style
12:03shtutgarthm, probably I don't understand the whole thing, but why can't you use оыге здфшт ьфз,
12:03shtutgartsorry, I mean "why can't you use just plain map?"
12:04shtutgartDon't think that it's good to have a number of global vars for such purposes...
12:05kephale,(-> {'a 7} (assoc 'b 8))
12:05clojurebot{b 8, a 7}
12:05kephalebut I would also like to be able to reference the map
12:06kephaleto get something like:
12:06kephale,(-> {'a 7} (assoc 'b (inc a)))
12:06clojurebotjava.lang.Exception: Unable to resolve symbol: a in this context
12:06kephaleclearly that shouldnt work
12:08shtutgart,(let [{:keys [a b] :as m} {:a 1 :b 2}] (-> m (assoc :b (inc a))))
12:08clojurebot{:a 1, :b 2}
12:08shtutgartbad example, there should be (dec a) to see the difference :)
12:09kephale,(let [{:keys [a b] :as m} {:a 1 :b 2}] (-> m (assoc :c (inc a))))
12:09clojurebot{:c 2, :a 1, :b 2}
12:09kephale,(let [{:keys [a b] :as m} {:a 1 :b 2}] (-> m (assoc :c (inc a)) (assoc :d (inc c))))
12:09clojurebotjava.lang.Exception: Unable to resolve symbol: c in this context
12:10kephaleI need that ability as well
12:10kephalewhich I guess could be accomplished by wrapping an expression like that in a loop
12:11shtutgartyeah
12:11kephalecool, ty
12:11shtutgartbut there also should be more elegant and sequntial, loop-free solution
12:14kephalewell, if there is a way to pull the binding map out of a let
12:14kephalethen
12:14kephale,(let [{:keys [a b] :as m} {:a 1 :b 2} c (inc a) d (inc c)] d)
12:14clojurebot3
12:14kephaledoes leverage the let
12:17shtutgartwhat about kind of ##(reduce (fn [m [k v]] (assoc m k (v m))) {:a 1} [[:b :a] [:c :b]])
12:17lazybot⇒ {:c 1, :b 1, :a 1}
12:20shtutgartor ##(reduce (fn [m [k f]] (assoc m k (f m))) {:a 1} [[:b #(-> % :a inc)]]), or some combination of the two
12:20lazybot⇒ {:b 2, :a 1}
13:24Scorchinleiningen q: should everything in :dev-dependencies and :dependencies go in :exclusions as well?
13:47dekuderphow does one verify a record type?
13:48dekuderpif I want to create a function with a conditional based on the record passed to it
14:44mdeboardtechnomancy: So I upgraded to swank-clojure 1.3.2, and the `lein run` dev server ran ok for a day or two, but now back to the "RejectedExecutionException" errors from before
14:44mdeboardI didn't change anything at all.
14:44mdeboardOnly thing I did actually was to restart the virtualmachine in which I run ubuntu
15:05fliebelWhat do we think of Gremlin and Blueprints?
15:14mdeboardfliebel: Blueprints... the CSS framework?
15:14fliebelmdeboard: No, the graph db interface
15:19dekuderpwhen I get an error like this: Key must be integer [Thrown class java.lang.IllegalArgumentException], what kind of mistake should I be looking for?
15:20dekuderphttps://gist.github.com/1086657
15:20mdeboarddekuderp: A traceback would be nice wouldn't it
15:20dnolen_first stack overflow core.logic question, fun, http://stackoverflow.com/questions/6713424/how-do-i-express-this-logic/6719627#6719627
15:21fliebeldnolen_: congrats, that's quite an accomplishment, but it does remind me of something cgrand said about moustache...
15:21dnolen_fliebel: ?
15:21fliebeldnolen_: He thought no one was using it because he never got questions about how it worked.
15:22dekuderpmdeboard: oh, now I see where the line numbers are
15:22mdeboarddekuderp: where
15:22dnolen_fliebel: if you're saying that think moustache is a lot easier to understand, I agree :)
15:22fliebelyea :D
15:22mdeboardorite
15:22dekuderphttps://gist.github.com/1086660
15:23dekuderpI am so used to getting nice clojure errors with the offending line # at the top
15:23Demosthenesso i've heard the arguments from the CL people that "of course CL is used for commercial software", but they mean backend with a full lisp environment. racket? they have a handful, seems like web services. is anyone creating client software, like fat clients for windows and linux in clojure?
15:24dnolen_fliebel: it's a particular fun question tho, it's a tricky problem solved with very little code (tho I admit I had to think about it for a while)
15:28dekuderpI think my mistake is that I thought you could do ('[1 [2 3]] [1 0]) => 2
15:28dekuderpor I thought I saw someone use a trick like that to access a nested vector
15:30dnolen_,(get-in [1 [2 3]] [1 0])
15:33clojurebot2
15:33dnolen_dekuderp: ^
15:35dekuderpdnolen: thanks!
15:35mdeboardDemosthenes: I think most of the commercial production clojure products/interfaces are closed-source.
15:35Demosthenesmdeboard: i've picked up a few lisp dialects now, generally for unix, scripting, or backend processes. but if i need to deploy a short simple app toa windows client, my options REALLY shrink.
15:36Demosthenessbcl was great (awesome debugging!), racket's quick and simple, but neither seems suitable for me to create a short app to deploy to non-IT clients.
15:36mdeboardDemosthenes: Were you the guy asking about clj msis?
15:36Demosthenesi mean really, i need http/https, TLS/SSL, and a basic gui... :P
15:36Demosthenesnope
15:37dekuderpwhat can I use to find out what kind of record a var is? I know (instance? record-name var) but I want something like (record-type? var) that returns record-name
15:38dnolen_,(type 1)
15:38clojurebotjava.lang.Integer
15:38dnolen_dekuderp: ^
15:38bendlas`hi
15:39dekuderpdnolen: thanks again!
15:39bendlas`does somebody know, if clutch is compatible with couchdb 0.10?
15:40bendlas`in particular, if you can use the clutch view server with 0.10
15:45mdeboard,(min-key - 1 2 3)
15:45clojurebot3
15:45mdeboard,(key 1 2 3)
15:45clojurebotjava.lang.IllegalArgumentException: Wrong number of args (3) passed to: core$key
15:46dekuderpokay here is my code: https://gist.github.com/1086690 and here is the output I'm getting: https://gist.github.com/1086692
15:47dekuderpI really don't get how type is returning nothing or java.lang.Class instead of the records I use
15:50dekuderpoh I fixed it, I was using (repeat 9 Road) instead of (repeat 9 (Road.))
15:50dekuderpstupid me:P
15:52mdeboarddekuderp: tsk tsk
15:54mdeboarddekuderp: I kid, what you've written there is more than I could do :(
16:27amalloydekuderp: advice: don't use records unless you have a strong performance need
16:28amalloyi filled my first program with records, because i "wanted" classes. but records are (mostly) a higher-performance, lower-convenience version of hashmaps. see http://cemerick.com/2011/07/05/flowchart-for-choosing-the-right-clojure-type-definition-form/ for a handy little flowchart about when to use what
16:28dekuderpamalloy: I was going to use structmaps but the clojure data structure page said I should go with records ( http://clojure.org/data_structures )
16:29amalloyyes, structmaps are deprecated
16:29amalloybut take a look at cemerick's flowchart. from what i know of your application, you'll wind up at "use a regular map"
16:30dekuderpamalloy: thank you, that flow-chart is awesome
16:37amalloydekuderp: it's good policy, btw, to define a function like (make-building args) so that you can switch from hashmaps to records whenever you need to, without needing the client code to change: you can just change the implementation of make-building
16:42dekuderpamalloy: so you're saying try to keep the implementation from affecting the design right?
16:42amalloywellll, i would have used the word API, not design
16:43dekuderplol yeah my terminology is pretty bad
17:09seancorfieldclojure.java.jdbc still uses structmaps (because clojure.contrib.sql did) - i guess that needs to be fixed...
17:10seancorfieldstuart sierra made a comment about it early on when i took over c.j.j and at the time i wasn't sure what he meant but i opened a ticket http://dev.clojure.org/jira/browse/JDBC-3
17:49Kenjinhello
17:57KenjinI'm having trouble setting up clojure with emacs+slime. M-x clojure-jack-in just hangs with "Starting swank server..."
18:02jonabbeyis emacs in the right directory?
18:02jonabbeyi.e., try loading the project.clj file from lein and then run the M-x clojure-jack-in from that buffer
18:14Kenjinjonabbey: how do I load project.clj from lein
18:21Kenjinjonabbey: I open project.clj in emacs and run M-x clojure-jack-in and its seems slime.el is dumped in the *swank* buffer
18:27amalloyKenjin: you can narrow down the problem by trying `lein swank` from the command line, followed by M-x slime-connect
18:27amalloyif either of those steps succeeds, the problem is probably with the other step (if they both succeed, something's wrong with jack-in)
18:27KenjinOn the swank-clojure readme it says "From inside a project, invoke M-x clojure-jack-in". What does "from inside a project" mean?
18:27Kenjinamalloy: thank you. I'll try that
18:41raekKenjin: from any file somewhere in the project tree (even outside src/ works)
18:41dekuderpI can use :type as a key in a map, right? or is it some clojure keyword?
18:41Kenjinraek: understood. thank you
18:42raekdekuderp: the keyword with the name ":type" is not special in any way
18:43dekuderpraek: thanks
18:44amalloyraek: it's a little special, isn't it? ##(doc type) looks it up in the metadata
18:44lazybot⇒ "([x]); Returns the :type metadata of x, or its Class if none"
18:46amalloynot that dekuderp cares about that
18:48Raynesamalloy: Yeah, the keyword itself is just a normal keyboard. It just happens to be the keyword that type looks for in metadata.
18:49RaynesThe name of defn includes the letter 'd'. Doesn't make 'd' special.
18:53Kenjinis the issue with slime and autodoc still unresolved?
19:00dekuderpokay here is my new code: https://gist.github.com/1086893 and the output: https://gist.github.com/1086896
19:00dekuderpI have no clue how I'm screwing this up so badly
19:32mdeboardWhy does this work ok: http://p.mattdeboard.net/mcount_good.html but this does not: http://p.mattdeboard.net/mycount_bad.html (note the reversal of the args)
19:39amalloymdeboard: your pastes give me an nginx timeout error. try gisting instead?
19:40mdeboardimproperly configured apache :(
19:40mdeboardtry again
19:41mdeboardhad to reboot servar :(
19:41amalloymdeboard: you swapped args to mycount but not to recur
19:41mdeboardoh, gosh.
19:45dekuderpokay, I finally got my code working: https://gist.github.com/1086926
19:46dekuderpI tried cleaning it up and tried to use the paradigms you guys talk about, but if anyone could suggest any way I could make it simpler I'd really appreciate it
19:48amalloydekuderp: it's more common to use :building for type rather than "building". keywords are pretty good at enum-like things
19:49amalloyi'd delete the five-argument version of add-buildings and make it a (loop ... (recur)) in the three-argument version
19:53mdeboardawesome solution to 4clj #25 imo
19:53mdeboard#(->> % (filter odd?))
19:54amalloymdeboard: isn't that just #(filter odd? %)?
19:54mdeboardoh, yeah probably. I chose ->> at first because I misread the problem at first.. thought there was some follow-on operation I had to do
19:55mdeboardmostly just happy I properly used ->>
19:55amalloy*smile*
19:55amalloyit's an exciting thing to use
19:55dekuderpamalloy: I don't understand your first point. So I would have a key (:building) that matches to nothing, and then rewrite to just check if that key exists?
19:55amalloydekuderp: nono, :type is fine
19:55amalloyfor example, (defn make-road [] {:type :road})
19:56dekuderpand then I would have (= :road (:type road-obj)), right?
19:56amalloyyeah
19:56dekuderpokay, now I get it
19:57amalloydekuderp: here's a skin-deep rewrite of add-buildings: https://gist.github.com/1086948
20:00amalloyand (defn world-obj-to-str [world-obj] ({:building "B", :road "r", :firefighter "F"} (:type world-obj))) has a lot less boilerplate
20:03dekuderpamalloy: in your gist you used let to define new-world, in clojure is it normal to bind a var to let if it's referenced more than once?
20:03amalloythat's exactly what let is for
20:04dekuderpfor some reason I thought it was overkill to use if I wasn't defining more than 2 variables...
20:04amalloyi mean, you can use it for things that are only referenced once; it's often more readable that way because you can split things up
20:04amalloybut reuse is the main goal
20:05dekuderpamalloy: thanks again for all this useful info
20:05amalloydekuderp: nah, overkill is writing the same four lines of code twice to avoid a let :)
20:07dekuderplol well now I know that's cool to try and minimize repeating code
20:08dekuderpI'm just so used to java and constantly repeating myself I guess
20:10amalloyheh
20:10amalloydekuderp: well, java has local variables too
20:10amalloya way you can really outdistance java is by defining local *functions* to avoid repeating sections of code
20:14mdeboard4clj #23 is a SOB. #(map - (sort (map - %))) works for all the examples except the last one :(
20:14mdeboardhttp://4clojure.com/problem/23
20:15amalloydekuderp: https://github.com/flatland/useful/blob/develop/src/useful/fn.clj#L28 is an example of that sort of thing. don't worry about understanding the whole function - it's pretty abstract and a little messy. but see how i'm defining a local function `call` to avoid rewriting that code
20:16amalloymdeboard: isn't this problem asking you to reverse a sequence, not sort it in reverse order?
20:16mdeboardYeah. :P I was being cheap.
20:16amalloy*chuckle*
20:16mdeboarddidn't even look at the third one.
20:17amalloyif you wanted to do it that way, btw, ##(sort-by - [1 2 3 4 5]) is simpler
20:17lazybot⇒ (5 4 3 2 1)
20:17mdeboardahh
20:17mdeboardwas wondeirng how that worked
20:17amalloyand is equivalent to what you were doing, i think
20:17mdeboardthere you have it
20:17mdeboardyeah
20:17mdeboarddefinitely is
20:18mdeboardI guess just running "shuffle" until they appear in the proper order would be cheap too
20:19mdeboard(a joke)
20:20amalloy$google bogosort
20:20lazybot[Bogosort - Wikipedia, the free encyclopedia] http://en.wikipedia.org/wiki/Bogosort
20:21mdeboardlol
20:21mdeboardYeah, tha
20:21amalloymdeboard: quantum bogosort is a nice refinement of tha algorithm, getting it down to O(n)
20:22mdeboardlolirl
20:22mdeboardyeah I guess all possible permutations would exist simultaneously
20:39mdeboardamalloy: Explain:
20:39mdeboard,(into '() [1 2 3 4 5])
20:39clojurebot(5 4 3 2 1)
20:39mdeboardwhy is that reversed?
20:39amalloy&(conj '(1 2 3) 4)
20:39lazybot⇒ (4 1 2 3)
20:40mdeboardOhhh
20:40amalloylists (and seqs in general) conj on the left
20:40mdeboardoh righ tlisp reads right ot left
20:40amalloyuhhh
20:41amalloyi don't understand that explanation
20:43mdeboardDon't fight it, it will just make this more difficult
20:50amalloy&(reduce (partial list 'conj) () [1 2 3 4 5])
20:50lazybot⇒ (conj (conj (conj (conj (conj () 1) 2) 3) 4) 5)
20:51amalloymdeboard: that's what into is doing, under the hood. and because ##(conj '(1) 2) is '(2 1), the whole thing balloons out to the left
20:51lazybot⇒ (2 1)
20:51mdeboardahh
21:41tomojI just met the expression problem face to face for the first time I think
22:02mdeboardamalloy: In problems.clj for 4clj what is the ":_id" keyword? It's all ove rthe place. Is it a function? Shortcut for a query?
22:02amalloymdeboard: mongodb's unique identifier. each document you store gets a new _id
22:03mdeboardspecifically "(apply min-key :_id unsolved)"
22:03amalloywe (wrongly imo) hijack that to be the problem's numeric id
22:03mdeboardjust get the smallest id among unsolved
22:03amalloyso http://4clojure.com/problem/23 has its data stored in mongo with an _id of 23
22:04amalloyanyway, (apply min-key :_id unsolved) isn't *exactly* what you said. it returns the problem with the smallest id, not the smallest id
22:04mdeboardah ok
22:05mdeboardyeah that makes sense
22:05amalloy&(let [problems [{:_id 4 :data "TEST", :_id 9 :data "SAMPLE"}]], (apply min-key :_id problems))
22:05lazybotjava.lang.IllegalArgumentException: Duplicate key: :_id
22:05mdeboardkind of like an ORM in practice
22:05amalloy&(let [problems [{:_id 4 :data "TEST"} {:_id 9 :data "SAMPLE"}]], (apply min-key :_id problems))
22:05lazybot⇒ {:_id 4, :data "TEST"}
22:06amalloynot really. i mean, i don't use any ORMs, but my understanding is that they're for mapping the application level notion of objects onto the table-oriented database
22:06amalloymongodb is a document/object centric db, so we just put maps in and get maps out
22:10mdeboardamalloy: http://p.mattdeboard.net/nextunsolved.html would this work to only retrieve problems whose id is greater than the last problem solved? Biggest annoyance with 4clj righ tnow
22:10mdeboardfor me
22:10mdeboardI can't run lein run to test it out myself unfortunately
22:11mdeboardgetitng those execution exceptions
22:11mdeboards/test it out/play with it
22:12amalloymdeboard: care to step into #4clojure?
22:12mdeboardsure