2010-05-22
| 01:20 | scottj | Is it just my lein/swank/etc or does everyone get a connection refused error after the first connection (even if the first has ,disconnect-ed)? |
| 01:31 | replaca | scottj: I believe that's a known problem. I think the newest version of swank-clojure has a fix, but I'm not positive |
| 03:17 | scottj | replaca: thanks. yes it is fixed now |
| 07:27 | pocket_ | Hello |
| 07:28 | Borkdude | HI |
| 07:28 | Borkdude | (sorry, caps was on) |
| 07:29 | pocket_ | I newbie to Clojure. |
| 07:29 | pocket_ | So I make othello game to practice. |
| 07:29 | pocket_ | Then I want to use list to save game state(board state) |
| 07:30 | pocket_ | But I cant find any function to change list atom. |
| 07:31 | Borkdude | pocket_, is there a reason why you're not using a persistentvector for that? |
| 07:31 | Borkdude | changing in functional programming usually means: returning a new board |
| 07:32 | pocket_ | Hmm... |
| 07:33 | Borkdude | Maybe you can take a look at the snake game in Programming Clojure: http://www.pragprog.com/titles/shcloj/programming-clojure |
| 07:33 | sexpbot | "The Pragmatic Bookshelf | Programming Clojure" |
| 07:34 | pocket_ | If I want to change like this '(0 1 2 0 2) => '(0 1 2 2 2). |
| 07:34 | tomoj | you should certainly not be using lists |
| 07:35 | tomoj | changing something inside a list will be O(n) (i.e. too slow) |
| 07:35 | tomoj | well, it might not be too slow for your needs, but vectors are better here like Borkdude said |
| 07:35 | pocket_ | Hmm... I have 'programming-clojure'. So I must re-read it.. |
| 07:35 | pocket_ | Thank you. |
| 07:35 | Borkdude | No problem |
| 07:36 | tomoj | ,(assoc [0 1 2 0 2] 3 2) |
| 07:36 | clojurebot | [0 1 2 2 2] |
| 07:38 | pocket_ | tomoj_ thank you. |
| 07:39 | tcrayford | is there a way to turn a thing made with defrecord into a map? |
| 07:40 | AWizzArd | tcrayford: can you be more specific? |
| 07:40 | AWizzArd | The records are practically maps |
| 07:40 | tcrayford | so I define a record (defrecord Foo [a b c]), and I need to actually turn it into a map (so I can store it in mongodb using congomongo) |
| 07:41 | AWizzArd | Well, it is a map. |
| 07:41 | AWizzArd | If your lib does not support it yet then try (into {} some-foo) |
| 07:41 | tcrayford | that works |
| 07:42 | AWizzArd | You can also (keys foo), (vals foo), etc. Very map-like. |
| 07:48 | pocket_ | Is there any function to generate vector like repeat? |
| 07:50 | pocket_ | Repeat returns lazy-seq but I want to make make vector contain sixty-four 0. |
| 07:52 | pocket_ | Shoud I make it with hands? |
| 07:55 | _mst | running the lazy-seq through (vec ...) should do the trick |
| 07:55 | _mst | ,(vec (repeat 64 0)) |
| 07:55 | clojurebot | [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] |
| 07:56 | pocket_ | _mst wow very thanks! |
| 07:56 | _mst | no problem :) |
| 08:17 | LaPingvino | ,(vec (repeat 64 "clojure")) |
| 08:17 | clojurebot | ["clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "clojure" "cloj |
| 08:17 | LaPingvino | :P |
| 09:08 | Borkdude | wow, the primes lazy seq looks really weird |
| 11:31 | moshisushi | hello! i'm a little confused regarding the diffrence between apply and reduce. can someone clear this matter? |
| 11:33 | Raynes | moshisushi: apply applies a function to the elements of a sequence as if they were individual arguments. It basically dumps all the elements of the sequence into the argument list of the function. |
| 11:34 | Raynes | $(apply (partial + 5 5) [1 2 3 4]) |
| 11:34 | sexpbot | => 20 |
| 11:34 | Raynes | reduce is an entirely different beast. |
| 11:34 | moshisushi | Raynes: lemme see.. |
| 11:35 | moshisushi | so in this case: |
| 11:35 | moshisushi | (apply str ["hello" "foo" "bar"]) |
| 11:35 | moshisushi | "expands" to (str "hello" "foo" "bar") |
| 11:36 | Raynes | apply is a function and not a macro, so it doesn't really 'expand' to anything, but it is the equivalent of doing that, yes. |
| 11:36 | moshisushi | while (reduce str ["hello" "foo" "bar"]) is iterative application of str? |
| 11:36 | moshisushi | not iterative.. but well, you know :) |
| 11:36 | Raynes | $(reduce str ["hello" "foo "bar"]) |
| 11:36 | sexpbot | EOF while reading string |
| 11:36 | moshisushi | Raynes: yeah, hence the "" around expand :) |
| 11:36 | Raynes | $(reduce str ["hello" "foo" "bar"]) |
| 11:36 | sexpbot | => "hellofoobar" |
| 11:37 | Raynes | It accomplishes the same thing in this case, but differently. |
| 11:37 | moshisushi | Raynes: $ to invoke with sexpbot? |
| 11:37 | moshisushi | $(println "foo") |
| 11:37 | sexpbot | => foo nil |
| 11:37 | moshisushi | hee hee |
| 11:38 | Raynes | apply applies a single function to all the arguments of the sequence, while reduce takes two elements at first (unless you supply an initial accumulator value) and then applies the function to those and then applies the function to those and the next element of the sequence and so on. |
| 11:38 | moshisushi | Raynes: yes i really only tried it with str and with (apply + [1 2 3 4]) |
| 11:38 | Raynes | Yeah, $ is sexpbot's prepend. |
| 11:38 | moshisushi | and the reduce based equivalence |
| 11:38 | moshisushi | so i didn't see the difference |
| 11:38 | Raynes | :) |
| 11:38 | Raynes | I hope I helped clear things up. |
| 11:38 | moshisushi | since they are computationally equivalent in that case |
| 11:39 | moshisushi | Raynes: yeah sure! |
| 11:39 | moshisushi | lotsa thanks |
| 11:39 | Raynes | Lotsa your welcomes. :> |
| 11:43 | Raynes | $(reduce + 10 [1 2 3 4 5]) |
| 11:43 | sexpbot | => 25 |
| 12:06 | naeu | how would i check for the presence of false in a seq? Is the best approach: (some #(= false %) y) |
| 12:24 | pd | naeu: (some false? y) |
| 12:25 | naeu | pd: perfect, thanks |
| 14:42 | LauJensen | Good evening goodfolk |
| 14:43 | technomancy | LauJensen: Good morning. (http://www.total-knowledge.com/~ilya/mips/ugt.html) |
| 14:44 | LauJensen | Funny :) |
| 14:44 | LauJensen | Like H. Simpson said "its funny cause its true", there's always a little chatter about local times here and there |
| 14:46 | pedroteixeira | hi there, anyone knows if it is ok to use defstruct + multimethods, or should adopt defprotocol + defrecord? (for a brand new project) |
| 14:46 | technomancy | clojurebot: ugt is Universal Greeting Time: http://www.total-knowledge.com/~ilya/mips/ugt.html |
| 14:46 | clojurebot | In Ordnung |
| 14:46 | sexpbot | "UGT" |
| 14:47 | dysinger | sexpbot -> ignored |
| 14:48 | technomancy | (setq erc-ignored-list '([...])) |
| 14:54 | Chousuke | pedroteixeira: structs are pretty much made obsolete by records |
| 14:54 | Chousuke | pedroteixeira: but using multimethods is okay, if you want the flexibility |
| 14:55 | Chousuke | pedroteixeira: you can also use plain maps if you just want something quick and easy :) |
| 15:04 | pedroteixeira | thanks, Chousuke. guess will start with maps, guess they'll be easier for serialization also :) |
| 15:27 | duncanm | if i have a call to (mapcat f coll), how do i change that to a pmap call? |
| 15:27 | duncanm | is it that same as (concat (pmap f coll)) ? |
| 15:30 | duncanm | ahh |
| 15:30 | duncanm | (apply concat (pmap f coll)) |
| 16:22 | AWizzArd | ~seen rhickey |
| 16:22 | clojurebot | rhickey was last seen joining #clojure, 573 minutes ago |
| 16:37 | OForero | is there and ant target that does a local m2 install of a locally compiled clojure? |
| 17:13 | remleduff | OForero: Is that what 'ant ci-build' does? |
| 17:13 | technomancy | OForero: do you know about build.clojure.org? |
| 17:14 | OForero | no |
| 17:14 | OForero | are those daily builds? |
| 17:14 | technomancy | yeah |
| 17:14 | technomancy | every commit, actually |
| 17:27 | derefed | I have a namespace with the :gen-class option and it extends a Java class. How can I call methods inherited from that class? (Where in Java, I would use "this" as the object in question to call methods on) |
| 17:30 | technomancy | ugh; backing off last-var-wins just broke all libs that use duck-streams |
| 17:31 | technomancy | which was supposed to be added back in as a "compatibility" layer |
| 17:41 | technomancy | are there any hacky ways to get a client JVM on a 64-bit machine? |
| 17:44 | AWizzArd | technomancy: not that I know of |
| 17:45 | opqdonut | you can always run a 32bit jvm |
| 17:45 | AWizzArd | Be it the windows or linux jdk, I “only” had the -server vm in the 64-bit installation. |
| 17:46 | AWizzArd | ,(.pow 2M 128) |
| 17:46 | clojurebot | 340282366920938463463374607431768211456M |
| 17:46 | technomancy | opqdonut: using ia32-libs or something? |
| 17:47 | technomancy | that would sure be nice for quick scripts |
| 17:47 | technomancy | 4s to perform lein clean is redoinkulous |
| 17:49 | AWizzArd | technomancy: how much mhz and ram? |
| 17:50 | AWizzArd | And how fast is it if you call it a few times in a row, when the os will have cached a bit of the vm? |
| 17:50 | technomancy | AWizzArd: 1.8 core 2 duo; 4gb ram |
| 17:50 | technomancy | the client VM absolutely smokes it for quick things like this |
| 18:20 | remleduff | What's the difference between running at a REPL and "require" of a file, that allows me to (defprotocol) a protocol repeatedly in a repl, but not in a file? |
| 18:21 | Chousuke | there shouldn't be a difference that matters :/ |
| 18:21 | remleduff | $(defprotocol Base (foo [o])) |
| 18:21 | sexpbot | Var null/null is unbound. |
| 18:21 | Chousuke | unless you're AOT compiling the file. |
| 18:22 | Chousuke | that might affect something |
| 18:22 | remleduff | No, just doing 'require of the file in a repl |
| 18:23 | remleduff | I get java.lang.LinkageError: loader (instance of clojure/lang/DynamicClassLoader): attempted duplicate class definition for name: "clojure/test_clojure/protocols/Base" |
| 18:25 | remleduff | I'm trying to do this to create a test case for ticket #353: http://gist.github.com/410416 |
| 18:27 | remleduff | Works fine just typed into a repl |
| 18:27 | remleduff | I mean, it doesn't work as expected |
| 18:27 | remleduff | I mean, as expected, it doesn't work |
| 18:27 | remleduff | As opposed to not working, in a non-useful way ;) |
| 18:39 | remleduff | Is anyone around who can give me permission to post messages on clojure-dev? |
| 19:24 | boredomist | What would be the idiomatic way of checking to see if something is a map? |
| 19:24 | boredomist | I currently do this: (not= (class content) clojure.lang.PersistentArrayMap) where content might or might not be a map |
| 19:27 | remleduff | map? or associative? probably |
| 19:28 | boredomist | Wow, how'd I forget map? |
| 19:28 | boredomist | Thanks |
| 19:28 | arkahn | what about the isa? macro |
| 19:31 | arkahn | ,(isa? {} clojure.lang.PersistentArrayMap) |
| 19:31 | clojurebot | false |
| 19:34 | remleduff | ,(class {}) |
| 19:34 | clojurebot | clojure.lang.PersistentArrayMap |
| 19:34 | remleduff | weird |
| 19:34 | arkahn | : / |
| 19:35 | remleduff | (instance? {} clojure.lang.PersistentArrayMap) |
| 19:35 | remleduff | ,(instance? {} clojure.lang.PersistentArrayMap) |
| 19:35 | clojurebot | java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.Class |
| 19:35 | remleduff | ,(instance? clojure.lang.PersistentArrayMap {}) |
| 19:35 | clojurebot | true |
| 19:36 | remleduff | (isa? {} (assoc {} :a 1)) |
| 19:36 | remleduff | ,(isa? {} (assoc {} :a 1)) |
| 19:36 | clojurebot | false |
| 19:36 | arkahn | ,(isa? clojure.lang.PersistentArrayMap {}) |
| 19:36 | clojurebot | false |
| 19:38 | arkahn | my bad - it looks like is is for inheritence. The right macro to use would be instance? instead (maybe) |
| 19:38 | arkahn | s/is/isa?/ |
| 19:38 | sexpbot | my bad - it looks like isa? isa? for inheritence. The right macro to use would be instance? instead (maybe) |
| 19:38 | arkahn | lol |
| 19:41 | remleduff | isa? is nice because it catches inheritance though, which you'd want |
| 19:42 | remleduff | ,(isa? clojure.lang.PeristentArrayMap clojure.lang.Associative) |
| 19:42 | clojurebot | java.lang.ClassNotFoundException: clojure.lang.PeristentArrayMap |
| 19:43 | remleduff | ,(isa? clojure.lang.PersistentArrayMap clojure.lang.Associative) |
| 19:43 | clojurebot | true |
| 19:43 | remleduff | New rule, I'm not allowed to use clojurebot without first typing it into a local repl |
| 19:43 | arkahn | isa? can do inheritence but can it /only/ do inheritence? |
| 19:44 | remleduff | ,(isa? (type {}) clojure.lang.Associative) |
| 19:44 | clojurebot | true |
| 19:44 | remleduff | What do you mean only? |
| 19:44 | arkahn | oh ... I thought maybe isa? forced a parent/child evaluation, making it different from instance? instead of a superset of it |
| 19:45 | arkahn | ,(isa? clojure.lang.PersistentArrayMap clojure.lang.PersistentArrayMap) |
| 19:45 | clojurebot | true |
| 19:45 | arkahn | ah ha |
| 19:47 | arkahn | meh - instance? is still different because, of course, it checks to see whether x is an instantion of y, not just type checking |
| 19:51 | tomoj | boredomist: please don't check for PersistentArrayMap |
| 19:53 | tomoj | we need a chart of performance guarantees with an axis for predicates like map?, associative?, an axis for interfaces, and an axis for the clojure function, with x's where the operation is not supported |
| 19:55 | remleduff | My only qualm with map? is that it returns false of Java maps |
| 19:55 | remleduff | s/of/for/ |
| 19:55 | sexpbot | My only qualm with map? is that it returns false for Java maps |
| 19:55 | remleduff | Thanks sexpbot |
| 19:56 | tomoj | do java maps support the same operations as clojure maps? |
| 19:56 | tomoj | would need two predicates if not, I guess |
| 19:57 | remleduff | Hmm, maybe not |
| 19:57 | remleduff | ,(vals (-> (java.util.HashMap.) (.put :a 1))) |
| 19:57 | clojurebot | nil |
| 19:58 | remleduff | ,(vals (into {} (-> (java.util.HashMap.) (.put :a 1)))) |
| 19:58 | clojurebot | nil |
| 19:58 | tomoj | ,(-> (java.util.HashMap.) (.put :a 1)) |
| 19:58 | clojurebot | nil |
| 19:58 | tomoj | ,(vals (into {} (doto (java.util.HashMap.) (.put :a 1)))) |
| 19:58 | clojurebot | (1) |
| 19:59 | remleduff | Ah shucks |
| 19:59 | remleduff | I even tried that in my repl and didn't realize what I was getting wrong |
| 19:59 | remleduff | So, I'm not sure what predicate to use for "anything that will work with keys and vals and map destructuring" |
| 20:00 | tomoj | good question |
| 20:00 | remleduff | I guess (instance? java.util.Map x) |
| 20:00 | somnium | maybe instance? x java.util.Map |
| 20:01 | somnium | ,(instance? java.util.Map {}) |
| 20:01 | clojurebot | true |
| 20:02 | somnium | ,(instance? java.util.Map (java.util.HashMap.)) |
| 20:02 | clojurebot | true |
| 20:02 | tomoj | it looks like destructuring uses symbol? vector? and map? |
| 20:02 | tomoj | and otherwise it throws an error |
| 20:03 | tomoj | ,(let [{:keys [x y]} (doto (java.util.HashMap.) (.put :x 1) (.put :y 2))] [x y]) |
| 20:03 | clojurebot | [1 2] |
| 20:03 | tomoj | strange |
| 20:03 | tomoj | ,(map? (java.util.HashMap.)) |
| 20:03 | clojurebot | false |
| 20:03 | tomoj | maybe this has changed in 1.2.0? |
| 20:04 | somnium | I think it just checks the literals in the destructuring form |
| 20:04 | tomoj | the forms? |
| 20:04 | remleduff | That works in my 1.1.0 repl too |
| 20:05 | tomoj | I see the same behavior in 1.2.0 |
| 20:05 | somnium | I mean, I dont think it uses a predicate on the target, it just tries to take it apart according to {:keys ...} [[& xs]] ... |
| 20:05 | tomoj | despite the symbol? vector? map? check, I must not understand what it's checking |
| 20:05 | tomoj | ah, I see, of course |
| 20:06 | technomancy | tomoj: it works the other way; clojure maps implement j.u.Map |
| 20:07 | technomancy | oh, nm; I see you saw that |
| 20:11 | tomoj | I think (apply hash-map) might be happening to the map |
| 20:11 | tomoj | so whatever hash-map can deal with is what you can destructure with a map, I think |
| 20:11 | tomoj | but not at all sure |
| 20:11 | technomancy | more likely (into {} %) |
| 20:12 | tomoj | don't see any into anywhere in destructure |
| 20:12 | technomancy | ignore me; I am not paying attention to context |
| 20:15 | somnium | Is there any cost to using protocols? if you were for example to replace every (defn foo ...) with (defprotocol IFoo (foo ...)) |
| 20:17 | remleduff | Can't have a zero-arg protocol function |
| 20:19 | remleduff | You have to use the "extend" Protocol stuff for basic types if you want the first parameter to be, say, a map |
| 20:20 | remleduff | Which is "fast" but not as fast as defining protocol functions inline in deftype or defrecord |
| 20:20 | somnium | It just wondered about trying to use pattern matching to generate protocols |
| 20:21 | somnium | limited to one match I guess |
| 20:21 | somnium | ah true |
| 20:24 | remleduff | Is there a way to see all the protocols that have been extended to some type? |
| 20:24 | remleduff | Like I want to see all protocols extended to "nil" |
| 20:29 | remleduff | Hmm, you get a warning message if a protocol overwrites a defn, but not if a defn overwrites a protocol function |
| 20:55 | technomancy | the java cli launcher is just plain nuts |
| 20:55 | technomancy | on OS X, adding "-client" has no effect, but adding "-d32" switches to the client JVM |
| 20:56 | danlarkin | choo choooo |
| 20:56 | technomancy | but on 64-bit Linux, adding "-d32" makes it fail to launch. |
| 21:44 | brweber2 | hey all, is there anything built in clojure or clojure-contrib that does object equality with metadata? I know that metadata is not normally part of the equality comparison, but is there a utility that does include it? |
| 21:45 | brweber2 | anyone around? |
| 22:01 | chouser | you can manually compare the equality |
| 22:01 | chouser | (= (meta a) (meta b)) |
| 22:04 | brweber2 | chouser, thanks |
| 22:04 | brweber2 | is there anything that will recursively do that for any data structure? equality of metadata and data structure? |
| 22:04 | brweber2 | chouser how is the book coming along btw? |
| 22:05 | brweber2 | chouser my pitiful attempt was something like this |
| 22:05 | brweber2 | ,(defn compare-with-metadata [#^clojure.core/IObj a #^clojure.core/IObj b] |
| 22:05 | brweber2 | (let [a-meta (meta a) b-meta (meta b)] |
| 22:05 | clojurebot | EOF while reading |
| 22:05 | brweber2 | (if (or a-meta b-meta) |
| 22:05 | brweber2 | (and (= a-meta b-meta)(= a b)) |
| 22:05 | brweber2 | (= a b)))) |
| 22:06 | brweber2 | I suppose the if isn't necessary |
| 22:07 | brweber2 | and that isn't recursive |
| 22:08 | brweber2 | chouser was hoping to find an impl in contrib :) |
| 22:13 | chouser | it's pretty much an abuse of metadata. |
| 22:14 | chouser | that might explain why there's nothing in contrib |
| 22:16 | brweber2 | chouser, agreed, let me back up and say what I am trying to do |
| 22:17 | brweber2 | I want to verify that a macro has properly copied the metadata over as part of the transformation |
| 22:17 | brweber2 | so I was looking for a utility method to verify it for that reason, I want to know that the metadata didn't accidentally get dropped by the macro |
| 22:36 | defn | ,((fn this [] (try :foo (finally (this))))) |
| 22:36 | clojurebot | defn: I don't understand. |
| 22:38 | defn | http://stackoverflow.com/questions/500607/what-are-the-lesser-known-but-cool-data-structures |
| 22:38 | sexpbot | "What are the lesser known but cool data structures ? - Stack Overflow" |
| 22:39 | danlarkin | wow thanks sexpbot that was useful |
| 22:39 | danlarkin | I couldn't tell where that link was headed |
| 22:39 | defn | ;) |
| 22:39 | defn | Heya Dan |
| 22:44 | brweber2 | hey all, I asked a question a few minutes ago, can anyone take a crack at it? |
| 22:44 | brweber2 | I can repost if that is helpful |
| 23:26 | johnmn3 | I found some example code on the web that I want to translate to clojure. The author builds an abstract class and then, in another file, extends that class. |
| 23:27 | johnmn3 | How would I translate that into clojure? |
| 23:30 | johnmn3 | I've seen :extends in the ns definition of .clj files. but do the protocols and deftype/defrecord stuff work here? |
| 23:31 | technomancy | johnmn3: you're asking how to translate the mechanism, but the mechanism is uninteresting. you should be asking how to do what that example code is actually meant to do. |
| 23:32 | johnmn3 | technomancy: yea, getting rid of the whole mechanism would be preferable. Here's a link to the site: http://www.jroller.com/santhosh/date/20050620#file%5Fpath%5Fautocompletion |
| 23:33 | technomancy | are you asking about how to separate out the GUI control from the file-related logic? |
| 23:33 | johnmn3 | I'm not familiar with abstract classes |
| 23:34 | johnmn3 | I'm trying to build word completion into an editor |
| 23:34 | johnmn3 | googling found me that example. |
| 23:35 | johnmn3 | I think I could brute force the whole think with just keystroke listeners, but... |
| 23:36 | johnmn3 | I'd still need to learn from this example how to get the jlist to popup at the right place, have it interact intutively, and insert the completion after the caret, etc. |
| 23:38 | technomancy | sorry, /me knows next to nothing about GUI toolkits |
| 23:38 | johnmn3 | np. |
| 23:39 | johnmn3 | yea, it's a pain how GUIs pull you into their OO frameworks. |
| 23:39 | johnmn3 | and I don't know anything about abstract classes |
| 23:45 | johnmn3 | I think I'll try to implement this in terms of defrecord, defprotocol and extend-protocol. |
| 23:58 | brweber2 | hey technomancy |