#clojure logs

2010-05-22

01:20scottjIs 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:31replacascottj: I believe that's a known problem. I think the newest version of swank-clojure has a fix, but I'm not positive
03:17scottjreplaca: thanks. yes it is fixed now
07:27pocket_Hello
07:28BorkdudeHI
07:28Borkdude(sorry, caps was on)
07:29pocket_I newbie to Clojure.
07:29pocket_So I make othello game to practice.
07:29pocket_Then I want to use list to save game state(board state)
07:30pocket_But I cant find any function to change list atom.
07:31Borkdudepocket_, is there a reason why you're not using a persistentvector for that?
07:31Borkdudechanging in functional programming usually means: returning a new board
07:32pocket_Hmm...
07:33BorkdudeMaybe you can take a look at the snake game in Programming Clojure: http://www.pragprog.com/titles/shcloj/programming-clojure
07:33sexpbot"The Pragmatic Bookshelf | Programming Clojure"
07:34pocket_If I want to change like this '(0 1 2 0 2) => '(0 1 2 2 2).
07:34tomojyou should certainly not be using lists
07:35tomojchanging something inside a list will be O(n) (i.e. too slow)
07:35tomojwell, it might not be too slow for your needs, but vectors are better here like Borkdude said
07:35pocket_Hmm... I have 'programming-clojure'. So I must re-read it..
07:35pocket_Thank you.
07:35BorkdudeNo problem
07:36tomoj,(assoc [0 1 2 0 2] 3 2)
07:36clojurebot[0 1 2 2 2]
07:38pocket_tomoj_ thank you.
07:39tcrayfordis there a way to turn a thing made with defrecord into a map?
07:40AWizzArdtcrayford: can you be more specific?
07:40AWizzArdThe records are practically maps
07:40tcrayfordso 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:41AWizzArdWell, it is a map.
07:41AWizzArdIf your lib does not support it yet then try (into {} some-foo)
07:41tcrayfordthat works
07:42AWizzArdYou can also (keys foo), (vals foo), etc. Very map-like.
07:48pocket_Is there any function to generate vector like repeat?
07:50pocket_Repeat returns lazy-seq but I want to make make vector contain sixty-four 0.
07:52pocket_Shoud I make it with hands?
07:55_mstrunning the lazy-seq through (vec ...) should do the trick
07:55_mst,(vec (repeat 64 0))
07:55clojurebot[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:56pocket__mst wow very thanks!
07:56_mstno problem :)
08:17LaPingvino,(vec (repeat 64 "clojure"))
08:17clojurebot["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:17LaPingvino:P
09:08Borkdudewow, the primes lazy seq looks really weird
11:31moshisushihello! i'm a little confused regarding the diffrence between apply and reduce. can someone clear this matter?
11:33Raynesmoshisushi: 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:34Raynes$(apply (partial + 5 5) [1 2 3 4])
11:34sexpbot=> 20
11:34Raynesreduce is an entirely different beast.
11:34moshisushiRaynes: lemme see..
11:35moshisushiso in this case:
11:35moshisushi(apply str ["hello" "foo" "bar"])
11:35moshisushi"expands" to (str "hello" "foo" "bar")
11:36Raynesapply 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:36moshisushiwhile (reduce str ["hello" "foo" "bar"]) is iterative application of str?
11:36moshisushinot iterative.. but well, you know :)
11:36Raynes$(reduce str ["hello" "foo "bar"])
11:36sexpbotEOF while reading string
11:36moshisushiRaynes: yeah, hence the "" around expand :)
11:36Raynes$(reduce str ["hello" "foo" "bar"])
11:36sexpbot=> "hellofoobar"
11:37RaynesIt accomplishes the same thing in this case, but differently.
11:37moshisushiRaynes: $ to invoke with sexpbot?
11:37moshisushi$(println "foo")
11:37sexpbot=> foo nil
11:37moshisushihee hee
11:38Raynesapply 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:38moshisushiRaynes: yes i really only tried it with str and with (apply + [1 2 3 4])
11:38RaynesYeah, $ is sexpbot's prepend.
11:38moshisushiand the reduce based equivalence
11:38moshisushiso i didn't see the difference
11:38Raynes:)
11:38RaynesI hope I helped clear things up.
11:38moshisushisince they are computationally equivalent in that case
11:39moshisushiRaynes: yeah sure!
11:39moshisushilotsa thanks
11:39RaynesLotsa your welcomes. :>
11:43Raynes$(reduce + 10 [1 2 3 4 5])
11:43sexpbot=> 25
12:06naeuhow would i check for the presence of false in a seq? Is the best approach: (some #(= false %) y)
12:24pdnaeu: (some false? y)
12:25naeupd: perfect, thanks
14:42LauJensenGood evening goodfolk
14:43technomancyLauJensen: Good morning. (http://www.total-knowledge.com/~ilya/mips/ugt.html)
14:44LauJensenFunny :)
14:44LauJensenLike H. Simpson said "its funny cause its true", there's always a little chatter about local times here and there
14:46pedroteixeirahi there, anyone knows if it is ok to use defstruct + multimethods, or should adopt defprotocol + defrecord? (for a brand new project)
14:46technomancyclojurebot: ugt is Universal Greeting Time: http://www.total-knowledge.com/~ilya/mips/ugt.html
14:46clojurebotIn Ordnung
14:46sexpbot"UGT"
14:47dysingersexpbot -> ignored
14:48technomancy(setq erc-ignored-list '([...]))
14:54Chousukepedroteixeira: structs are pretty much made obsolete by records
14:54Chousukepedroteixeira: but using multimethods is okay, if you want the flexibility
14:55Chousukepedroteixeira: you can also use plain maps if you just want something quick and easy :)
15:04pedroteixeirathanks, Chousuke. guess will start with maps, guess they'll be easier for serialization also :)
15:27duncanmif i have a call to (mapcat f coll), how do i change that to a pmap call?
15:27duncanmis it that same as (concat (pmap f coll)) ?
15:30duncanmahh
15:30duncanm(apply concat (pmap f coll))
16:22AWizzArd~seen rhickey
16:22clojurebotrhickey was last seen joining #clojure, 573 minutes ago
16:37OForerois there and ant target that does a local m2 install of a locally compiled clojure?
17:13remleduffOForero: Is that what 'ant ci-build' does?
17:13technomancyOForero: do you know about build.clojure.org?
17:14OForerono
17:14OForeroare those daily builds?
17:14technomancyyeah
17:14technomancyevery commit, actually
17:27derefedI 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:30technomancyugh; backing off last-var-wins just broke all libs that use duck-streams
17:31technomancywhich was supposed to be added back in as a "compatibility" layer
17:41technomancyare there any hacky ways to get a client JVM on a 64-bit machine?
17:44AWizzArdtechnomancy: not that I know of
17:45opqdonutyou can always run a 32bit jvm
17:45AWizzArdBe it the windows or linux jdk, I “only” had the -server vm in the 64-bit installation.
17:46AWizzArd,(.pow 2M 128)
17:46clojurebot340282366920938463463374607431768211456M
17:46technomancyopqdonut: using ia32-libs or something?
17:47technomancythat would sure be nice for quick scripts
17:47technomancy4s to perform lein clean is redoinkulous
17:49AWizzArdtechnomancy: how much mhz and ram?
17:50AWizzArdAnd 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:50technomancyAWizzArd: 1.8 core 2 duo; 4gb ram
17:50technomancythe client VM absolutely smokes it for quick things like this
18:20remleduffWhat'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:21Chousukethere shouldn't be a difference that matters :/
18:21remleduff$(defprotocol Base (foo [o]))
18:21sexpbotVar null/null is unbound.
18:21Chousukeunless you're AOT compiling the file.
18:22Chousukethat might affect something
18:22remleduffNo, just doing 'require of the file in a repl
18:23remleduffI get java.lang.LinkageError: loader (instance of clojure/lang/DynamicClassLoader): attempted duplicate class definition for name: "clojure/test_clojure/protocols/Base"
18:25remleduffI'm trying to do this to create a test case for ticket #353: http://gist.github.com/410416
18:27remleduffWorks fine just typed into a repl
18:27remleduffI mean, it doesn't work as expected
18:27remleduffI mean, as expected, it doesn't work
18:27remleduffAs opposed to not working, in a non-useful way ;)
18:39remleduffIs anyone around who can give me permission to post messages on clojure-dev?
19:24boredomistWhat would be the idiomatic way of checking to see if something is a map?
19:24boredomistI currently do this: (not= (class content) clojure.lang.PersistentArrayMap) where content might or might not be a map
19:27remleduffmap? or associative? probably
19:28boredomistWow, how'd I forget map?
19:28boredomistThanks
19:28arkahnwhat about the isa? macro
19:31arkahn,(isa? {} clojure.lang.PersistentArrayMap)
19:31clojurebotfalse
19:34remleduff,(class {})
19:34clojurebotclojure.lang.PersistentArrayMap
19:34remleduffweird
19:34arkahn: /
19:35remleduff(instance? {} clojure.lang.PersistentArrayMap)
19:35remleduff,(instance? {} clojure.lang.PersistentArrayMap)
19:35clojurebotjava.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.Class
19:35remleduff,(instance? clojure.lang.PersistentArrayMap {})
19:35clojurebottrue
19:36remleduff(isa? {} (assoc {} :a 1))
19:36remleduff,(isa? {} (assoc {} :a 1))
19:36clojurebotfalse
19:36arkahn,(isa? clojure.lang.PersistentArrayMap {})
19:36clojurebotfalse
19:38arkahnmy bad - it looks like is is for inheritence. The right macro to use would be instance? instead (maybe)
19:38arkahns/is/isa?/
19:38sexpbotmy bad - it looks like isa? isa? for inheritence. The right macro to use would be instance? instead (maybe)
19:38arkahnlol
19:41remleduffisa? is nice because it catches inheritance though, which you'd want
19:42remleduff,(isa? clojure.lang.PeristentArrayMap clojure.lang.Associative)
19:42clojurebotjava.lang.ClassNotFoundException: clojure.lang.PeristentArrayMap
19:43remleduff,(isa? clojure.lang.PersistentArrayMap clojure.lang.Associative)
19:43clojurebottrue
19:43remleduffNew rule, I'm not allowed to use clojurebot without first typing it into a local repl
19:43arkahnisa? can do inheritence but can it /only/ do inheritence?
19:44remleduff,(isa? (type {}) clojure.lang.Associative)
19:44clojurebottrue
19:44remleduffWhat do you mean only?
19:44arkahnoh ... I thought maybe isa? forced a parent/child evaluation, making it different from instance? instead of a superset of it
19:45arkahn,(isa? clojure.lang.PersistentArrayMap clojure.lang.PersistentArrayMap)
19:45clojurebottrue
19:45arkahnah ha
19:47arkahnmeh - instance? is still different because, of course, it checks to see whether x is an instantion of y, not just type checking
19:51tomojboredomist: please don't check for PersistentArrayMap
19:53tomojwe 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:55remleduffMy only qualm with map? is that it returns false of Java maps
19:55remleduffs/of/for/
19:55sexpbotMy only qualm with map? is that it returns false for Java maps
19:55remleduffThanks sexpbot
19:56tomojdo java maps support the same operations as clojure maps?
19:56tomojwould need two predicates if not, I guess
19:57remleduffHmm, maybe not
19:57remleduff,(vals (-> (java.util.HashMap.) (.put :a 1)))
19:57clojurebotnil
19:58remleduff,(vals (into {} (-> (java.util.HashMap.) (.put :a 1))))
19:58clojurebotnil
19:58tomoj,(-> (java.util.HashMap.) (.put :a 1))
19:58clojurebotnil
19:58tomoj,(vals (into {} (doto (java.util.HashMap.) (.put :a 1))))
19:58clojurebot(1)
19:59remleduffAh shucks
19:59remleduffI even tried that in my repl and didn't realize what I was getting wrong
19:59remleduffSo, I'm not sure what predicate to use for "anything that will work with keys and vals and map destructuring"
20:00tomojgood question
20:00remleduffI guess (instance? java.util.Map x)
20:00somniummaybe instance? x java.util.Map
20:01somnium,(instance? java.util.Map {})
20:01clojurebottrue
20:02somnium,(instance? java.util.Map (java.util.HashMap.))
20:02clojurebottrue
20:02tomojit looks like destructuring uses symbol? vector? and map?
20:02tomojand otherwise it throws an error
20:03tomoj,(let [{:keys [x y]} (doto (java.util.HashMap.) (.put :x 1) (.put :y 2))] [x y])
20:03clojurebot[1 2]
20:03tomojstrange
20:03tomoj,(map? (java.util.HashMap.))
20:03clojurebotfalse
20:03tomojmaybe this has changed in 1.2.0?
20:04somniumI think it just checks the literals in the destructuring form
20:04tomojthe forms?
20:04remleduffThat works in my 1.1.0 repl too
20:05tomojI see the same behavior in 1.2.0
20:05somniumI mean, I dont think it uses a predicate on the target, it just tries to take it apart according to {:keys ...} [[& xs]] ...
20:05tomojdespite the symbol? vector? map? check, I must not understand what it's checking
20:05tomojah, I see, of course
20:06technomancytomoj: it works the other way; clojure maps implement j.u.Map
20:07technomancyoh, nm; I see you saw that
20:11tomojI think (apply hash-map) might be happening to the map
20:11tomojso whatever hash-map can deal with is what you can destructure with a map, I think
20:11tomojbut not at all sure
20:11technomancymore likely (into {} %)
20:12tomojdon't see any into anywhere in destructure
20:12technomancyignore me; I am not paying attention to context
20:15somniumIs there any cost to using protocols? if you were for example to replace every (defn foo ...) with (defprotocol IFoo (foo ...))
20:17remleduffCan't have a zero-arg protocol function
20:19remleduffYou have to use the "extend" Protocol stuff for basic types if you want the first parameter to be, say, a map
20:20remleduffWhich is "fast" but not as fast as defining protocol functions inline in deftype or defrecord
20:20somniumIt just wondered about trying to use pattern matching to generate protocols
20:21somniumlimited to one match I guess
20:21somniumah true
20:24remleduffIs there a way to see all the protocols that have been extended to some type?
20:24remleduffLike I want to see all protocols extended to "nil"
20:29remleduffHmm, you get a warning message if a protocol overwrites a defn, but not if a defn overwrites a protocol function
20:55technomancythe java cli launcher is just plain nuts
20:55technomancyon OS X, adding "-client" has no effect, but adding "-d32" switches to the client JVM
20:56danlarkinchoo choooo
20:56technomancybut on 64-bit Linux, adding "-d32" makes it fail to launch.
21:44brweber2hey 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:45brweber2anyone around?
22:01chouseryou can manually compare the equality
22:01chouser(= (meta a) (meta b))
22:04brweber2chouser, thanks
22:04brweber2is there anything that will recursively do that for any data structure? equality of metadata and data structure?
22:04brweber2chouser how is the book coming along btw?
22:05brweber2chouser my pitiful attempt was something like this
22:05brweber2,(defn compare-with-metadata [#^clojure.core/IObj a #^clojure.core/IObj b]
22:05brweber2 (let [a-meta (meta a) b-meta (meta b)]
22:05clojurebotEOF while reading
22:05brweber2 (if (or a-meta b-meta)
22:05brweber2 (and (= a-meta b-meta)(= a b))
22:05brweber2 (= a b))))
22:06brweber2I suppose the if isn't necessary
22:07brweber2and that isn't recursive
22:08brweber2chouser was hoping to find an impl in contrib :)
22:13chouserit's pretty much an abuse of metadata.
22:14chouserthat might explain why there's nothing in contrib
22:16brweber2chouser, agreed, let me back up and say what I am trying to do
22:17brweber2I want to verify that a macro has properly copied the metadata over as part of the transformation
22:17brweber2so 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:36defn,((fn this [] (try :foo (finally (this)))))
22:36clojurebotdefn: I don't understand.
22:38defnhttp://stackoverflow.com/questions/500607/what-are-the-lesser-known-but-cool-data-structures
22:38sexpbot"What are the lesser known but cool data structures ? - Stack Overflow"
22:39danlarkinwow thanks sexpbot that was useful
22:39danlarkinI couldn't tell where that link was headed
22:39defn;)
22:39defnHeya Dan
22:44brweber2hey all, I asked a question a few minutes ago, can anyone take a crack at it?
22:44brweber2I can repost if that is helpful
23:26johnmn3I 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:27johnmn3How would I translate that into clojure?
23:30johnmn3I've seen :extends in the ns definition of .clj files. but do the protocols and deftype/defrecord stuff work here?
23:31technomancyjohnmn3: 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:32johnmn3technomancy: 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:33technomancyare you asking about how to separate out the GUI control from the file-related logic?
23:33johnmn3I'm not familiar with abstract classes
23:34johnmn3I'm trying to build word completion into an editor
23:34johnmn3googling found me that example.
23:35johnmn3I think I could brute force the whole think with just keystroke listeners, but...
23:36johnmn3I'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:38technomancysorry, /me knows next to nothing about GUI toolkits
23:38johnmn3np.
23:39johnmn3yea, it's a pain how GUIs pull you into their OO frameworks.
23:39johnmn3and I don't know anything about abstract classes
23:45johnmn3I think I'll try to implement this in terms of defrecord, defprotocol and extend-protocol.
23:58brweber2hey technomancy