#clojure log - May 22 2010

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

1: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)?

1: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

3:17 scottj: replaca: thanks. yes it is fixed now

7:27 pocket_: Hello

7:28 Borkdude: HI

7:28 (sorry, caps was on)

7:29 pocket_: I newbie to Clojure.

7:29 So I make othello game to practice.

7:29 Then I want to use list to save game state(board state)

7:30 But I cant find any function to change list atom.

7:31 Borkdude: pocket_, is there a reason why you're not using a persistentvector for that?

7:31 changing in functional programming usually means: returning a new board

7:32 pocket_: Hmm...

7:33 Borkdude: Maybe you can take a look at the snake game in Programming Clojure: http://www.pragprog.com/titles/shcloj/programming-clojure

7:33 sexpbot: "The Pragmatic Bookshelf | Programming Clojure"

7:34 pocket_: If I want to change like this '(0 1 2 0 2) => '(0 1 2 2 2).

7:34 tomoj: you should certainly not be using lists

7:35 changing something inside a list will be O(n) (i.e. too slow)

7:35 well, it might not be too slow for your needs, but vectors are better here like Borkdude said

7:35 pocket_: Hmm... I have 'programming-clojure'. So I must re-read it..

7:35 Thank you.

7:35 Borkdude: No problem

7:36 tomoj: ,(assoc [0 1 2 0 2] 3 2)

7:36 clojurebot: [0 1 2 2 2]

7:38 pocket_: tomoj_ thank you.

7:39 tcrayford: is there a way to turn a thing made with defrecord into a map?

7:40 AWizzArd: tcrayford: can you be more specific?

7:40 The records are practically maps

7: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)

7:41 AWizzArd: Well, it is a map.

7:41 If your lib does not support it yet then try (into {} some-foo)

7:41 tcrayford: that works

7:42 AWizzArd: You can also (keys foo), (vals foo), etc. Very map-like.

7:48 pocket_: Is there any function to generate vector like repeat?

7:50 Repeat returns lazy-seq but I want to make make vector contain sixty-four 0.

7:52 Shoud I make it with hands?

7:55 _mst: running the lazy-seq through (vec ...) should do the trick

7:55 ,(vec (repeat 64 0))

7: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]

7:56 pocket_: _mst wow very thanks!

7:56 _mst: no problem :)

8:17 LaPingvino: ,(vec (repeat 64 "clojure"))

8: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

8:17 LaPingvino: :P

9: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 $(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 so in this case:

11:35 (apply str ["hello" "foo" "bar"])

11:35 "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 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 $(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 so i didn't see the difference

11:38 Raynes: :)

11:38 I hope I helped clear things up.

11:38 moshisushi: since they are computationally equivalent in that case

11:39 Raynes: yeah sure!

11:39 lotsa thanks

11:39 Raynes: Lotsa your welcomes. :>

11:43 $(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 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 pedroteixeira: but using multimethods is okay, if you want the flexibility

14:55 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 is it that same as (concat (pmap f coll)) ?

15:30 ahh

15:30 (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 are those daily builds?

17:14 technomancy: yeah

17:14 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 which was supposed to be added back in as a "compatibility" layer

17:41 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 ,(.pow 2M 128)

17:46 clojurebot: 340282366920938463463374607431768211456M

17:46 technomancy: opqdonut: using ia32-libs or something?

17:47 that would sure be nice for quick scripts

17:47 4s to perform lein clean is redoinkulous

17:49 AWizzArd: technomancy: how much mhz and ram?

17:50 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 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 that might affect something

18:22 remleduff: No, just doing 'require of the file in a repl

18:23 I get java.lang.LinkageError: loader (instance of clojure/lang/DynamicClassLoader): attempted duplicate class definition for name: "clojure/test_clojure/protocols/Base"

18:25 I'm trying to do this to create a test case for ticket #353: http://gist.github.com/410416

18:27 Works fine just typed into a repl

18:27 I mean, it doesn't work as expected

18:27 I mean, as expected, it doesn't work

18:27 As opposed to not working, in a non-useful way ;)

18:39 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 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 Thanks

19:28 arkahn: what about the isa? macro

19:31 ,(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 ,(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 ,(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 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 ,(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 ,(isa? clojure.lang.PersistentArrayMap clojure.lang.PersistentArrayMap)

19:45 clojurebot: true

19:45 arkahn: ah ha

19:47 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 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 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 would need two predicates if not, I guess

19:57 remleduff: Hmm, maybe not

19:57 ,(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 I even tried that in my repl and didn't realize what I was getting wrong

19:59 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 ,(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 and otherwise it throws an error

20:03 ,(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 ,(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 ah, I see, of course

20:06 technomancy: tomoj: it works the other way; clojure maps implement j.u.Map

20:07 oh, nm; I see you saw that

20:11 tomoj: I think (apply hash-map) might be happening to the map

20:11 so whatever hash-map can deal with is what you can destructure with a map, I think

20:11 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 You have to use the "extend" Protocol stuff for basic types if you want the first parameter to be, say, a map

20:20 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 limited to one match I guess

20:21 ah true

20:24 remleduff: Is there a way to see all the protocols that have been extended to some type?

20:24 Like I want to see all protocols extended to "nil"

20:29 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 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 anyone around?

22:01 chouser: you can manually compare the equality

22:01 (= (meta a) (meta b))

22:04 brweber2: chouser, thanks

22:04 is there anything that will recursively do that for any data structure? equality of metadata and data structure?

22:04 chouser how is the book coming along btw?

22:05 chouser my pitiful attempt was something like this

22:05 ,(defn compare-with-metadata [#^clojure.core/IObj a #^clojure.core/IObj b]

22:05 (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 (and (= a-meta b-meta)(= a b))

22:05 (= a b))))

22:06 I suppose the if isn't necessary

22:07 and that isn't recursive

22:08 chouser was hoping to find an impl in contrib :)

22:13 chouser: it's pretty much an abuse of metadata.

22:14 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 I want to verify that a macro has properly copied the metadata over as part of the transformation

22:17 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 I couldn't tell where that link was headed

22:39 defn: ;)

22:39 Heya Dan

22:44 brweber2: hey all, I asked a question a few minutes ago, can anyone take a crack at it?

22:44 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 How would I translate that into clojure?

23:30 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 I'm trying to build word completion into an editor

23:34 googling found me that example.

23:35 I think I could brute force the whole think with just keystroke listeners, but...

23:36 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 yea, it's a pain how GUIs pull you into their OO frameworks.

23:39 and I don't know anything about abstract classes

23:45 I think I'll try to implement this in terms of defrecord, defprotocol and extend-protocol.

23:58 brweber2: hey technomancy

Logging service provided by n01se.net