#clojure logs

2011-04-17

00:05christophercodrifairly new to Clojure and a little stuck...
00:06christophercodri(defn process-file [file-name]
00:06christophercodri (with-open [rdr (BufferedReader. (FileReader. file-name))]
00:06christophercodri (doseq [line (line-seq rdr)]
00:06christophercodri (println
00:06christophercodri (let [c line] (conj @calldb (grab-first c))))))))
00:06christophercodrioops..
00:08christophercodritrying to push things onto a vector from a file.
00:33ataggartchristophercodri: what's the question?
00:34christophercodriI am trying to update an empty vector with a bunch of values that I am pushing from a file
00:35christophercodriI don't think I am retaining the change with doseq
00:35tomoj&(let [a (atom [])] [(conj @a 3) (conj @a 4) @a])
00:35sexpbot⟹ [[3] [4] []]
00:36ataggart(vec (line-seq (reader file-name)))
00:36ataggart^ that will do it
00:36ataggartreader is in clojure.java.io
00:37ataggartand you need to put the reader in a with-out, but that' the general idea
00:37ataggarterm with-open
00:37ataggartI need more or less beer, can't tell which
00:37christophercodrihaha
00:38ataggartand right now, if you think you need a reference type (e.g., atom) you're probably wrong
00:39christophercodriprobably
00:41ataggartand just to prove to myself I'm right...
00:41ataggart,(first (with-open [rdr (reader "http://www.google.com")] (vec (line-seq rdr))))
00:41clojurebotjava.lang.Exception: Unable to resolve symbol: reader in this context
00:41ataggartbah
00:42ataggart,(use 'clojure.java.io)
00:42clojurebotnil
00:42ataggart,(first (with-open [rdr (reader "http://www.google.com/")] (vec (line-seq rdr))))
00:42clojurebotjava.security.AccessControlException: access denied (java.net.SocketPermission www.google.com:80 connect,resolve)
00:42ataggartwell, if not for the sandbox, that'd work
00:43christophercodrihe
00:44christophercodrigood stuff, I got what I wanted... now I just need to clean up some of the mess
00:44christophercodrimy vector is full of stuff I don't need at the moment
00:44christophercodriother* stuff
03:28mreynoldsI'm running into a problem with executors where my call can be both a Callable and a Runnable. I tried type hinting like so (.submit executor ^Runnable #(print-protocol "s" (server-sequence server-stream))) but that doesn't seem to resolve the issue
03:28mreynoldsIs type hinting the right thing to do here?
03:33amalloymreynolds: link to the java method you're calling?
03:33mreynoldshttp://download.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html .submit
03:33mreynoldsType hints are not the answer, but I'm not sure what is
03:34amalloyif type-hinting is not doing it, try (cast Runnable #(...))
03:34mreynoldsI'll do that
03:35amalloy&(doc cast)
03:35sexpbot⟹ "([c x]); Throws a ClassCastException if x is not a c, else returns x."
03:36amalloynot sure that's so helpful, but...
03:37mreynoldswell, that got rid of the error.... lemme see if it works :)
03:37mreynoldsNice, that worked, thanks!
03:41mreynoldsI think I get that the internal impl, somehow, can figure out that it's one or the other, but flails if it's both. Raek's blog has a post, but it doesn't end up using an ambiguous method, so it "Just Works". I guess I don't really understand it either, but I'm ok with that :)
03:46amalloy$source cast
03:46sexpbotcast is http://is.gd/xGG74t
03:46mreynoldsInteresting that it just punts to the java option
03:46amalloymreynolds: there isn't really another way
03:47mreynoldsClojure's type inference is still semi-magic to me :)
03:50amalloyit doesn't really have very much type inference, as far as i'm aware. i mean, yes, if you hint something then it sorta bubbles out to the results of method calls on that object
03:51amalloybut in most clojure code you don't bother hinting, and all interop gets done with reflection
03:52mreynoldsamalloy: Yeah, I don't understand how that works just yet. I do in Java, but that's very straightforward in the bytecode, so that's different.
03:53amalloyif you're interested you can have a look at clojure.lang.Reflector
03:53amalloywhich is where most of the magic happens
03:53mreynoldsamalloy: Will do. I plan to do a "tour" after I get this project off the ground.
03:55mreynoldsHonestly, I'm just really happy at how fast I'm getting my projects done. It takes some change of mindset, but I have been able to write things quickly that were hard in Java. I'm planning to invest more heavily in Clojure as time permits.
03:56markomanthis is not proper keyword :0 ?
03:56markomanor :1
03:56mreynoldsShould be?
03:56mreynoldsI use them that way
03:57markomanhmh, intelliJ marks as error on REPL
03:57amalloy&:1
03:57sexpbot⟹ :1
03:58amalloymarkoman: throws an actual clojure exception, or just highlights it as an error?
03:58amalloy(presuming the latter, this is just an indication that intellij is not the best clojure ide)
03:58markomanhighlights, and wont let me eval it
03:59amalloyhaha ouch
03:59amalloytime to roll out :zero :P
03:59amalloy:smallest-nonnegative-number
03:59markomani like intelliJ the most so far, but yes it seems a bug there
04:00mreynoldsyeah, clojure support is still somewhat weak outside of emacs
04:00amalloymreynolds: ccw is coming along nicely from what i hear
04:00mreynoldseclipse's clojure support is actually pretty good, but still has weird parsing bugs with keywords and such
04:00mreynoldsamalloy: Yeah, I'm liking it so far short of a few gripes. Thankfully I can switch to default mode and fix them then swap back quickly.
04:02markoman{:zero 0} evals well, all the other but that starts with :{number}
04:03markomansame problem is on code editor
04:03markomanbut it looks like it works runtime
04:03markomanas it should I guess :)
04:04amalloy&(keyword "i can make a crazy keyword")
04:04sexpbot⟹ :i can make a crazy keyword
04:05amalloy&(keyword "maybe even one with : in it")
04:05sexpbot⟹ :maybe even one with : in it
04:05amalloy&(keyword "but probably / isn't allowed?")
04:05sexpbot⟹ :but probably / isn't allowed?
04:07mreynoldsI have to imagine the text is just treated as a string, right? So you could put anything in there?
04:07mreynoldsBe hard to type in a repl, of course
04:11amalloymreynolds: i thought / might be forbidden because it's the namespace separator
04:41raekmreynolds: in my blog, the function argument was type hinted as a Callable
04:42mreynoldsraek: Ahhhh, right, in the parameters
04:42mreynoldsraek: Sorry, missed that
04:43raekhrm, I wonder why ^Runnable #(...) shouldn't work...
04:43mreynoldsfrom the docs, it looked like type hints only work on parameters
04:43mreynoldsAt least, that's all I've seen from use
04:44raekmreynolds: but do you get some kind of error, or just a reflection warning?
04:45opqdonut_can you type hint expressions too? I thought it was only symbols
04:45mreynoldsraek: It just said "multiple types...."
04:45mreynoldsraek: Don't have the error handy, sorry
04:45mreynoldsI can dig it up if you're curious
04:45opqdonut_also, ISTR the various interfaces that clojure fns implement overlapping with eachother
04:46opqdonut_something like (FutureTask. function) not knowing whether to treat function as Runnable or Callable
04:46raekjava.lang.IllegalArgumentException: More than one matching method found: submit
04:46mreynoldsopqdonut_: I was using submit, which has a similar issue
04:46mreynoldsThere you go
04:46opqdonut_so you'll have to reify the relevant instance yourself
04:46raekok, I get this when I typehint the executor service, but not the function
04:48raekand when I hint both, I get the same error
04:49raekletting the function and typehinting the symbol worked...
04:49raek(let [^Runnable f #(inc 1)] (.submit ^ExecutorService pool f))
04:49raek(let [f #(inc 1)] (.submit ^ExecutorService pool ^Runnable f))
04:50raek,(meta '^{:foo "bar"}#(inc 1))
04:50clojurebot{:foo "bar"}
04:50amalloyraek: perhaps the compiler isn't interested on the tag of a literal, because it already knows what its type is?
04:51raek,'#(inc 1)
04:51clojurebot(fn* [] (inc 1))
04:51raekhrm, maybe so
04:51amalloywhereas tagging a symbol has meaning
07:34markomanhow do I do this: (assoc {:x 1 :y 1} {:x 2 :z 1}) -> {:x 2 :y 1 :z 1} is it possible to kind of explode {:x 2 :z 1} map?
07:42mids,(merge {:x 1 :y 1} {:x 2 :z 1})
07:43clojurebot{:z 1, :x 2, :y 1}
07:51markomanthanks
08:24VinzentIs there midje users here? What's the right way to say {:a {:b #(...)}} => {:a {:b fn?}} ?
09:34fliebelWhen I have a type implementing one method of a protocol, can I use extend to implement the other, or will that conflict?
10:20jaleyhi guys! can anyone point me toward some instructions for compile java code with cake, if they exist? I've been looking around the github project but not found anything.
10:23fliebeljaley: I think you just have to put them in the right dir.
10:23fliebelsrc/jvm that is
10:24jaleyfliebel: ah really? I have to have my source in src/jvm? interesting... I'm migrating a lein project to cake, I previously had a :source-java in my project.clj
10:25VinzentStill no midje users here? Why I got "Midje caught an exception when translating this form" when writing (provided *var* => a-value) ?
10:25fliebeljaley: You might be able to configure it like that, but src/jvm works for me.
10:25jaleyfliebel: hmmm.. looking at the code you're right. it's just passing in "src" and "jvm" as string constants.
10:26fliebelWhy didn't anyone warn me :( IllegalArgumentException class examples.pong.bat already directly implements interface begame.object.visible for protocol:#'begame.object/visible
10:27fliebelI'm trying to implement on half of the protocol first, and then extend the other half later.
10:30jaleyfliebel: awesome. that got it. thanks
10:32jaleyI have a code-gen custom task. is there an easy way to make cake run it before the default compile task? Only option I see is to undeftask compile, then redefine it with the dependency and call the original task?
10:36fliebeljaley: Sounds okay to me.
10:44fliebelCould anyone who knows about these things explain me how databases store their indexes? For example, CouchDB uses a B+ tree, and can produce views sorted by any key. Does this mean it stores a tree for every view, or is there something smart to sort/index data by multiple keys? *has the weird feeling TimMc or cemerick might know*
10:54TimMcfliebel: Unfortunately, I have forgotten pretty much everything from my databases class.
10:55TimMcTry asking me last semester. :-)
10:59Raynesfliebel: IIRC, cemerick's brain is just a CouchDB database.
11:01TimMcThat doesn't mean he knows how it works. :-)
11:26fliebelRaynes, TimMc: I'd love to know how *my* brain works ;)
11:39fliebelTimMc, Raynes: Asking in #CouchDB reveals that every view has its own B-tree indeed. I got to have a B-graph or something...
12:44ihodesheyo--anyone have a suggestion as to where i should start if i want to do secure login and sessions etc?
12:48anonymouse89is there a real clean way to do a partial sum over a list of values?
12:48anonymouse89like (1 2 3 4) -> (1 3 6 10)
12:52anonymouse89I vaguely remember a core fn like reduce, but leaving the intermediate values
12:53jarpiain,(reductions + [1 2 3 4])
12:53clojurebot(1 3 6 10)
12:53ihodesreductions
12:53ihodesthere you go ;)
12:53anonymouse89ihodes: that's it! thanks
12:54ihodesanonymous89: no problem, though i think jarpiain and i basically raced the latency on that one
12:55anonymouse89jarpiain: thanks too!
12:55ihodesalso, i suppose it's anonymouse89--that's a tricky nick.
12:56anonymouse89ihodes: do you not have a tab-comlete for usernames?
12:59ihodesanonymouse89: wow--no i've always just typed them. now i use tab-complete. sigh. i'm using irssi in tmux, and i didn't know about tab-complete
13:01anonymouse89another quick question, doseq is never lazy, correct?
13:02ihodescorrect; the do's are the antilazy.
14:04mecis there a builtin for [(filter pred coll) (remove pred coll)] ?
14:06raekmec: ((juxt filter remove) pred coll)
14:06raekor clojure.contrib.seq/separate
14:07mecraek: thanks
14:18devnmmm, juxt
14:20devnanyone know if there's a way to extract an archive of google groups posts?
14:20devnlike a collection of html files, or something?
14:21fliebeldevn: downthemall can crawl it for you.
14:34__name__Can I match the value in defmethod with a function?
14:39raek__name__: to use something like (defmethod foo string? ...) instead of (defmethod foo String ...)? if so, then no.
14:40__name__raek: yeah, that's what i meant.
14:40__name__too bad.
14:40raekdon't forget that the value is matched with isa? and not =
14:42raekso you can still group values together using 'derive'
14:43devnfliebel: got a link?
14:43raek(defn has-foo-nature? [x] (isa? x ::foo)) (derive String :foo) (defmethod bar String ...)
14:44raeks/ :foo/ ::foo/
14:44sexpbot<raek> (defn has-foo-nature? [x] (isa? x ::foo)) (derive String ::foo) (defmethod bar String ...)
14:44fliebel$google downthemall
14:44sexpbotFirst out of 168 results is: DownThemAll!
14:44sexpbothttp://www.downthemall.net/
14:45raek__name__: ^ that's a workaround which in some way could be considered equivalent to defining a method for the predicate has-foo-nature?
14:46raek(of course, this might not always be possible to do)
14:46__name__okay
14:46__name__where's the reason for not allowing a user-defined match fun?
14:47raeksometihng user-supplied instead of isa?
14:48Quiarkhi, what's the equivalent of User.class in Clojure (User.class in Java returns an instance of Class describing the class User)
14:48raekQuiark: just User
14:49raek,(class java.util.ArrayList)
14:49clojurebotjava.lang.Class
14:49__name__raek: yeah
14:49Quiarkthen we've got bigger problems
14:50Quiarkjava.lang.IllegalArgumentException: No matching method found: fetchConnection for class com.restfb.DefaultFacebookClient
14:51Quiarkok, maybe because this method has a variable number of arguments
14:51raek__name__: that sounds like an even more general approach to dispatch. what method should be chosen when multiple predicates return true?
14:51__name__raek: isa? can return true for multiple predicates too.
14:51__name__hence the prioritization mechanism
14:52raekQuiark: varargs are a bit different in Java. (int a, int... b) actually looks like (int a, int[] b) on the JVM level (after the java compiler is done)
14:53raek,(String/format "%d %d %d" (into-array [1 2 3]))
14:53clojurebot"1 2 3"
14:54raek__name__: fair enough. but I think you have to ask rhickey himself for the rationale... :)
14:54__name__Does your Bot have a message thing?
14:55raeknote that it is entirely possible to roll your own multimethod alternative...
14:56Quiarkraek, aha, so I must pass an empty array even when I don't use any of the variable arguments
14:57raekQuiark: yes, unless the method happens to have an overloaded version without the varargs
14:58raek,(String/format "foo" (make-array Object 0))
14:58clojurebot"foo"
14:59Quiarkkthxbai
15:00TimMc$findfn (make-array Object 0)
15:00sexpbot[]
15:00TimMc$findfn (make-array Integer 0)
15:00sexpbot[]
15:00TimMc,(int-array)
15:00clojurebotjava.lang.IllegalArgumentException: Wrong number of args (0) passed to: core$int-array
15:01TimMcAh, it wants a coll.
15:25amalloy__name__: dnolen has been working on some deep magic to allow predicate dispatch. dunno what state it's in
20:07seancorfieldhttps://github.com/clojure/java.jdbc yay!
20:56TimMcseancorfield: Confused. Will the namespace actually be java.jdbc?
20:57seancorfieldclojure.java.jdbc
20:57seancorfieldlike the new clojure.tools.logging etc
23:42brehautanyone know if its possible to have both positional and named varargs in a function?
23:43amalloybrehaut: er what?
23:44brehautso (fn [& r] …) captures positional varargs, (fn [& {:keys [a b c] :or {a 1 b 2 c 3}}] …) captures named args
23:45brehautim failing at destructuring both
23:45amalloyoh
23:46brehauti have a function does RPC (thus doesnt know how many positional arguments it might get) but i want to add a flag to it (rather than doing a dynamic scope binding if possible)
23:46amalloybrehaut: there isn't a way to do this with just destructuring
23:47brehautthats what i was afraid of
23:47mec(fn [& [a b c :as {:keys [d e] :or {d 1 e 3}}]) would that work?
23:47amalloybut you could do something like scan the arglist for keywords, since presumably keywords are illegal for rpc calls?
23:47brehautamalloy: i think that will probably do for my needs yeah
23:47brehautamalloy: and yes they are
23:48brehautmec: those positional args are not variadic
23:48amalloyplus, they require the whole arglist to be a well-formed map: specifically, an even number of arguments
23:48brehautbbs
23:48mecah right
23:49brehautamalloy: im beginning to wonder if maybe just a dynamic binding would be better