2011-04-17
| 00:05 | christophercodri | fairly new to Clojure and a little stuck... |
| 00:06 | christophercodri | (defn process-file [file-name] |
| 00:06 | christophercodri | (with-open [rdr (BufferedReader. (FileReader. file-name))] |
| 00:06 | christophercodri | (doseq [line (line-seq rdr)] |
| 00:06 | christophercodri | (println |
| 00:06 | christophercodri | (let [c line] (conj @calldb (grab-first c)))))))) |
| 00:06 | christophercodri | oops.. |
| 00:08 | christophercodri | trying to push things onto a vector from a file. |
| 00:33 | ataggart | christophercodri: what's the question? |
| 00:34 | christophercodri | I am trying to update an empty vector with a bunch of values that I am pushing from a file |
| 00:35 | christophercodri | I don't think I am retaining the change with doseq |
| 00:35 | tomoj | &(let [a (atom [])] [(conj @a 3) (conj @a 4) @a]) |
| 00:35 | sexpbot | ⟹ [[3] [4] []] |
| 00:36 | ataggart | (vec (line-seq (reader file-name))) |
| 00:36 | ataggart | ^ that will do it |
| 00:36 | ataggart | reader is in clojure.java.io |
| 00:37 | ataggart | and you need to put the reader in a with-out, but that' the general idea |
| 00:37 | ataggart | erm with-open |
| 00:37 | ataggart | I need more or less beer, can't tell which |
| 00:37 | christophercodri | haha |
| 00:38 | ataggart | and right now, if you think you need a reference type (e.g., atom) you're probably wrong |
| 00:39 | christophercodri | probably |
| 00:41 | ataggart | and just to prove to myself I'm right... |
| 00:41 | ataggart | ,(first (with-open [rdr (reader "http://www.google.com")] (vec (line-seq rdr)))) |
| 00:41 | clojurebot | java.lang.Exception: Unable to resolve symbol: reader in this context |
| 00:41 | ataggart | bah |
| 00:42 | ataggart | ,(use 'clojure.java.io) |
| 00:42 | clojurebot | nil |
| 00:42 | ataggart | ,(first (with-open [rdr (reader "http://www.google.com/")] (vec (line-seq rdr)))) |
| 00:42 | clojurebot | java.security.AccessControlException: access denied (java.net.SocketPermission www.google.com:80 connect,resolve) |
| 00:42 | ataggart | well, if not for the sandbox, that'd work |
| 00:43 | christophercodri | he |
| 00:44 | christophercodri | good stuff, I got what I wanted... now I just need to clean up some of the mess |
| 00:44 | christophercodri | my vector is full of stuff I don't need at the moment |
| 00:44 | christophercodri | other* stuff |
| 03:28 | mreynolds | I'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:28 | mreynolds | Is type hinting the right thing to do here? |
| 03:33 | amalloy | mreynolds: link to the java method you're calling? |
| 03:33 | mreynolds | http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html .submit |
| 03:33 | mreynolds | Type hints are not the answer, but I'm not sure what is |
| 03:34 | amalloy | if type-hinting is not doing it, try (cast Runnable #(...)) |
| 03:34 | mreynolds | I'll do that |
| 03:35 | amalloy | &(doc cast) |
| 03:35 | sexpbot | ⟹ "([c x]); Throws a ClassCastException if x is not a c, else returns x." |
| 03:36 | amalloy | not sure that's so helpful, but... |
| 03:37 | mreynolds | well, that got rid of the error.... lemme see if it works :) |
| 03:37 | mreynolds | Nice, that worked, thanks! |
| 03:41 | mreynolds | I 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:46 | amalloy | $source cast |
| 03:46 | sexpbot | cast is http://is.gd/xGG74t |
| 03:46 | mreynolds | Interesting that it just punts to the java option |
| 03:46 | amalloy | mreynolds: there isn't really another way |
| 03:47 | mreynolds | Clojure's type inference is still semi-magic to me :) |
| 03:50 | amalloy | it 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:51 | amalloy | but in most clojure code you don't bother hinting, and all interop gets done with reflection |
| 03:52 | mreynolds | amalloy: 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:53 | amalloy | if you're interested you can have a look at clojure.lang.Reflector |
| 03:53 | amalloy | which is where most of the magic happens |
| 03:53 | mreynolds | amalloy: Will do. I plan to do a "tour" after I get this project off the ground. |
| 03:55 | mreynolds | Honestly, 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:56 | markoman | this is not proper keyword :0 ? |
| 03:56 | markoman | or :1 |
| 03:56 | mreynolds | Should be? |
| 03:56 | mreynolds | I use them that way |
| 03:57 | markoman | hmh, intelliJ marks as error on REPL |
| 03:57 | amalloy | &:1 |
| 03:57 | sexpbot | ⟹ :1 |
| 03:58 | amalloy | markoman: throws an actual clojure exception, or just highlights it as an error? |
| 03:58 | amalloy | (presuming the latter, this is just an indication that intellij is not the best clojure ide) |
| 03:58 | markoman | highlights, and wont let me eval it |
| 03:59 | amalloy | haha ouch |
| 03:59 | amalloy | time to roll out :zero :P |
| 03:59 | amalloy | :smallest-nonnegative-number |
| 03:59 | markoman | i like intelliJ the most so far, but yes it seems a bug there |
| 04:00 | mreynolds | yeah, clojure support is still somewhat weak outside of emacs |
| 04:00 | amalloy | mreynolds: ccw is coming along nicely from what i hear |
| 04:00 | mreynolds | eclipse's clojure support is actually pretty good, but still has weird parsing bugs with keywords and such |
| 04:00 | mreynolds | amalloy: 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:02 | markoman | {:zero 0} evals well, all the other but that starts with :{number} |
| 04:03 | markoman | same problem is on code editor |
| 04:03 | markoman | but it looks like it works runtime |
| 04:03 | markoman | as it should I guess :) |
| 04:04 | amalloy | &(keyword "i can make a crazy keyword") |
| 04:04 | sexpbot | ⟹ :i can make a crazy keyword |
| 04:05 | amalloy | &(keyword "maybe even one with : in it") |
| 04:05 | sexpbot | ⟹ :maybe even one with : in it |
| 04:05 | amalloy | &(keyword "but probably / isn't allowed?") |
| 04:05 | sexpbot | ⟹ :but probably / isn't allowed? |
| 04:07 | mreynolds | I have to imagine the text is just treated as a string, right? So you could put anything in there? |
| 04:07 | mreynolds | Be hard to type in a repl, of course |
| 04:11 | amalloy | mreynolds: i thought / might be forbidden because it's the namespace separator |
| 04:41 | raek | mreynolds: in my blog, the function argument was type hinted as a Callable |
| 04:42 | mreynolds | raek: Ahhhh, right, in the parameters |
| 04:42 | mreynolds | raek: Sorry, missed that |
| 04:43 | raek | hrm, I wonder why ^Runnable #(...) shouldn't work... |
| 04:43 | mreynolds | from the docs, it looked like type hints only work on parameters |
| 04:43 | mreynolds | At least, that's all I've seen from use |
| 04:44 | raek | mreynolds: but do you get some kind of error, or just a reflection warning? |
| 04:45 | opqdonut_ | can you type hint expressions too? I thought it was only symbols |
| 04:45 | mreynolds | raek: It just said "multiple types...." |
| 04:45 | mreynolds | raek: Don't have the error handy, sorry |
| 04:45 | mreynolds | I can dig it up if you're curious |
| 04:45 | opqdonut_ | also, ISTR the various interfaces that clojure fns implement overlapping with eachother |
| 04:46 | opqdonut_ | something like (FutureTask. function) not knowing whether to treat function as Runnable or Callable |
| 04:46 | raek | java.lang.IllegalArgumentException: More than one matching method found: submit |
| 04:46 | mreynolds | opqdonut_: I was using submit, which has a similar issue |
| 04:46 | mreynolds | There you go |
| 04:46 | opqdonut_ | so you'll have to reify the relevant instance yourself |
| 04:46 | raek | ok, I get this when I typehint the executor service, but not the function |
| 04:48 | raek | and when I hint both, I get the same error |
| 04:49 | raek | letting the function and typehinting the symbol worked... |
| 04:49 | raek | (let [^Runnable f #(inc 1)] (.submit ^ExecutorService pool f)) |
| 04:49 | raek | (let [f #(inc 1)] (.submit ^ExecutorService pool ^Runnable f)) |
| 04:50 | raek | ,(meta '^{:foo "bar"}#(inc 1)) |
| 04:50 | clojurebot | {:foo "bar"} |
| 04:50 | amalloy | raek: perhaps the compiler isn't interested on the tag of a literal, because it already knows what its type is? |
| 04:51 | raek | ,'#(inc 1) |
| 04:51 | clojurebot | (fn* [] (inc 1)) |
| 04:51 | raek | hrm, maybe so |
| 04:51 | amalloy | whereas tagging a symbol has meaning |
| 07:34 | markoman | how 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:42 | mids | ,(merge {:x 1 :y 1} {:x 2 :z 1}) |
| 07:43 | clojurebot | {:z 1, :x 2, :y 1} |
| 07:51 | markoman | thanks |
| 08:24 | Vinzent | Is there midje users here? What's the right way to say {:a {:b #(...)}} => {:a {:b fn?}} ? |
| 09:34 | fliebel | When I have a type implementing one method of a protocol, can I use extend to implement the other, or will that conflict? |
| 10:20 | jaley | hi 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:23 | fliebel | jaley: I think you just have to put them in the right dir. |
| 10:23 | fliebel | src/jvm that is |
| 10:24 | jaley | fliebel: 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:25 | Vinzent | Still no midje users here? Why I got "Midje caught an exception when translating this form" when writing (provided *var* => a-value) ? |
| 10:25 | fliebel | jaley: You might be able to configure it like that, but src/jvm works for me. |
| 10:25 | jaley | fliebel: hmmm.. looking at the code you're right. it's just passing in "src" and "jvm" as string constants. |
| 10:26 | fliebel | Why didn't anyone warn me :( IllegalArgumentException class examples.pong.bat already directly implements interface begame.object.visible for protocol:#'begame.object/visible |
| 10:27 | fliebel | I'm trying to implement on half of the protocol first, and then extend the other half later. |
| 10:30 | jaley | fliebel: awesome. that got it. thanks |
| 10:32 | jaley | I 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:36 | fliebel | jaley: Sounds okay to me. |
| 10:44 | fliebel | Could 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:54 | TimMc | fliebel: Unfortunately, I have forgotten pretty much everything from my databases class. |
| 10:55 | TimMc | Try asking me last semester. :-) |
| 10:59 | Raynes | fliebel: IIRC, cemerick's brain is just a CouchDB database. |
| 11:01 | TimMc | That doesn't mean he knows how it works. :-) |
| 11:26 | fliebel | Raynes, TimMc: I'd love to know how *my* brain works ;) |
| 11:39 | fliebel | TimMc, Raynes: Asking in #CouchDB reveals that every view has its own B-tree indeed. I got to have a B-graph or something... |
| 12:44 | ihodes | heyo--anyone have a suggestion as to where i should start if i want to do secure login and sessions etc? |
| 12:48 | anonymouse89 | is there a real clean way to do a partial sum over a list of values? |
| 12:48 | anonymouse89 | like (1 2 3 4) -> (1 3 6 10) |
| 12:52 | anonymouse89 | I vaguely remember a core fn like reduce, but leaving the intermediate values |
| 12:53 | jarpiain | ,(reductions + [1 2 3 4]) |
| 12:53 | clojurebot | (1 3 6 10) |
| 12:53 | ihodes | reductions |
| 12:53 | ihodes | there you go ;) |
| 12:53 | anonymouse89 | ihodes: that's it! thanks |
| 12:54 | ihodes | anonymous89: no problem, though i think jarpiain and i basically raced the latency on that one |
| 12:55 | anonymouse89 | jarpiain: thanks too! |
| 12:55 | ihodes | also, i suppose it's anonymouse89--that's a tricky nick. |
| 12:56 | anonymouse89 | ihodes: do you not have a tab-comlete for usernames? |
| 12:59 | ihodes | anonymouse89: 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:01 | anonymouse89 | another quick question, doseq is never lazy, correct? |
| 13:02 | ihodes | correct; the do's are the antilazy. |
| 14:04 | mec | is there a builtin for [(filter pred coll) (remove pred coll)] ? |
| 14:06 | raek | mec: ((juxt filter remove) pred coll) |
| 14:06 | raek | or clojure.contrib.seq/separate |
| 14:07 | mec | raek: thanks |
| 14:18 | devn | mmm, juxt |
| 14:20 | devn | anyone know if there's a way to extract an archive of google groups posts? |
| 14:20 | devn | like a collection of html files, or something? |
| 14:21 | fliebel | devn: downthemall can crawl it for you. |
| 14:34 | __name__ | Can I match the value in defmethod with a function? |
| 14:39 | raek | __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:40 | raek | don't forget that the value is matched with isa? and not = |
| 14:42 | raek | so you can still group values together using 'derive' |
| 14:43 | devn | fliebel: got a link? |
| 14:43 | raek | (defn has-foo-nature? [x] (isa? x ::foo)) (derive String :foo) (defmethod bar String ...) |
| 14:44 | raek | s/ :foo/ ::foo/ |
| 14:44 | sexpbot | <raek> (defn has-foo-nature? [x] (isa? x ::foo)) (derive String ::foo) (defmethod bar String ...) |
| 14:44 | fliebel | $google downthemall |
| 14:44 | sexpbot | First out of 168 results is: DownThemAll! |
| 14:44 | sexpbot | http://www.downthemall.net/ |
| 14:45 | raek | __name__: ^ that's a workaround which in some way could be considered equivalent to defining a method for the predicate has-foo-nature? |
| 14:46 | raek | (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:47 | raek | sometihng user-supplied instead of isa? |
| 14:48 | Quiark | hi, what's the equivalent of User.class in Clojure (User.class in Java returns an instance of Class describing the class User) |
| 14:48 | raek | Quiark: just User |
| 14:49 | raek | ,(class java.util.ArrayList) |
| 14:49 | clojurebot | java.lang.Class |
| 14:49 | __name__ | raek: yeah |
| 14:49 | Quiark | then we've got bigger problems |
| 14:50 | Quiark | java.lang.IllegalArgumentException: No matching method found: fetchConnection for class com.restfb.DefaultFacebookClient |
| 14:51 | Quiark | ok, maybe because this method has a variable number of arguments |
| 14:51 | raek | __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:52 | raek | Quiark: 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:53 | raek | ,(String/format "%d %d %d" (into-array [1 2 3])) |
| 14:53 | clojurebot | "1 2 3" |
| 14:54 | raek | __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:55 | raek | note that it is entirely possible to roll your own multimethod alternative... |
| 14:56 | Quiark | raek, aha, so I must pass an empty array even when I don't use any of the variable arguments |
| 14:57 | raek | Quiark: yes, unless the method happens to have an overloaded version without the varargs |
| 14:58 | raek | ,(String/format "foo" (make-array Object 0)) |
| 14:58 | clojurebot | "foo" |
| 14:59 | Quiark | kthxbai |
| 15:00 | TimMc | $findfn (make-array Object 0) |
| 15:00 | sexpbot | [] |
| 15:00 | TimMc | $findfn (make-array Integer 0) |
| 15:00 | sexpbot | [] |
| 15:00 | TimMc | ,(int-array) |
| 15:00 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args (0) passed to: core$int-array |
| 15:01 | TimMc | Ah, it wants a coll. |
| 15:25 | amalloy | __name__: dnolen has been working on some deep magic to allow predicate dispatch. dunno what state it's in |
| 20:07 | seancorfield | https://github.com/clojure/java.jdbc yay! |
| 20:56 | TimMc | seancorfield: Confused. Will the namespace actually be java.jdbc? |
| 20:57 | seancorfield | clojure.java.jdbc |
| 20:57 | seancorfield | like the new clojure.tools.logging etc |
| 23:42 | brehaut | anyone know if its possible to have both positional and named varargs in a function? |
| 23:43 | amalloy | brehaut: er what? |
| 23:44 | brehaut | so (fn [& r] …) captures positional varargs, (fn [& {:keys [a b c] :or {a 1 b 2 c 3}}] …) captures named args |
| 23:45 | brehaut | im failing at destructuring both |
| 23:45 | amalloy | oh |
| 23:46 | brehaut | i 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:46 | amalloy | brehaut: there isn't a way to do this with just destructuring |
| 23:47 | brehaut | thats what i was afraid of |
| 23:47 | mec | (fn [& [a b c :as {:keys [d e] :or {d 1 e 3}}]) would that work? |
| 23:47 | amalloy | but you could do something like scan the arglist for keywords, since presumably keywords are illegal for rpc calls? |
| 23:47 | brehaut | amalloy: i think that will probably do for my needs yeah |
| 23:47 | brehaut | amalloy: and yes they are |
| 23:48 | brehaut | mec: those positional args are not variadic |
| 23:48 | amalloy | plus, they require the whole arglist to be a well-formed map: specifically, an even number of arguments |
| 23:48 | brehaut | bbs |
| 23:48 | mec | ah right |
| 23:49 | brehaut | amalloy: im beginning to wonder if maybe just a dynamic binding would be better |