#clojure log - Jan 17 2009

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

0:29 blbrown: are there any clojure oriented helpers for working with Java collections, e.g. is there a less verbose way of iterating over the key/values in a java hashtable

0:33 johan1: I'm trying to create an XmlRpc server using apache xmlrpc, but its addHandler method takes an object with public method that will be the callbacks, and proxy only seems suitable for instantiating an already defined class or interface. Anyone here who has tried xmlrcp with clojure?

0:36 or could tell me how to create an anonymous object without first having a class or interface in a jar file

0:37 Cark: isn't there an abstract class you could derive from ?

0:39 something like (proxy [org.apache.xmlrpc.XmlRpcHandler] [] (execute [pname, pvector] ....

0:39 johan1: perhaps I could find something with the arguments I need, but it doesn't feel very flexible. I think apache xmlrpc is using reflection to check if there is a method in the supplied object which has the same name as the method defined in the xmlrpc message, and calls it if it can be found

0:39 perhaps... I will check the API

0:40 danlarkin: Should I use (symbol (str (first (all-ns)))) or can I use (.getName (first (all-ns)))?

0:41 I suppose the line is that I can't trust that getName will be there in the future eh

0:41 Cark: (ns-name (first (all-ns)))

0:42 (doc ns-name)

0:42 clojurebot: Returns the name of the namespace, a symbol.; arglists ([ns])

0:42 danlarkin: :) perfect

0:42 thanks, Cark!

0:42 Cark: =)

2:36 danlarkin: Yesss, auto-reloading based purely on (all-ns) working!

9:12 edw: OK, after watching the Clojure videos, I'm way convinced that there's a there there.

9:14 Chouser: as in Clojure's not just a fad language?

9:15 edw: Yeah. Rich Hickey is not a 2nd year CS student.

9:30 The transaction management stuff is very nice.

9:46 Oh! I thought I was on #scheme!

10:03 Is here a SLIME for Clojure for idiots guide somewhere?

10:03 I use SLIME for Scheme48 for a while...

10:03 leafw: edw: google is your friend.

10:04 Cark: bill clementson has a couple blog articles on the subject

10:04 (morning)

10:05 edw: Yes, it is, but I'm going through a lot of pages that provide...incomplete information.

10:06 It's sort of like reading posts by PHP programmers talking about Ruby on Rails. Or football players talking about feelings.

10:06 Thanks Cark.

10:17 leafw: Thanks for the sage advice. Finally found something usable that, after following a bunch of URLs, I discovered was actually somewhere in Google's result list. Now I realize that there all human knowledge is discoverable in principle through Google and I should therefore never ask any question if it takes less than an hour of random clicking through the web.

10:17 s/there all/all/

10:18 Cark: tss, it's never a bad thing to ask a question

10:20 hum and btw did you check the getting started section on the wikibook ?

10:21 edw: Wikibook?

10:22 Cark: from the clojure official site, click on the wiki link

10:22 clojurebot : wiki

10:22 lisppaste8: edw pasted "A useful IRC topic" at http://paste.lisp.org/display/73757

10:22 Cark: clojurebot : wikibook

10:22 hum =/

10:22 edw: leafw: Over is #scheme, we try to be helpful.

10:23 Cark: I heard there's a beta Clojure book that can be bought.

10:24 Cark: yes there is, i don't know where to find it though

10:24 arbscht_: clojurebot: book

10:24 clojurebot: book is http://www.pragprog.com/titles/shcloj/programming-clojure

10:24 arbscht_: clojurebot: wiki

10:24 clojurebot: wiki is http://en.wikibooks.org/wiki/Clojure_Programming

10:24 Cark: hey why is clojurenot answering to you ?

10:25 oh i know

10:25 edw: I figured it was Pragmatic: they did the same thing with the DHH Rails book.

10:25 Cark: clojurebot: wiki

10:25 clojurebot: wiki is http://en.wikibooks.org/wiki/Clojure_Programming

10:25 Chousuke: Cark: you have a space between clojurebot and :

10:25 Cark: clojurebot : wiki

10:25 yes

10:25 Chousuke: it's very strict about that.

10:26 you're not even allowed to use , or any other delimiter

10:26 has to be : :)

10:26 edw: Colons are so formal.

10:28 Cark: clojurebot: you're too formal

10:28 clojurebot: Excuse me?

11:45 edw: Hmm. Strings should be callable. E.g. ("012" 1) -> 1

11:46 rhickey: edw: unlikely, for perf reasons

11:46 edw: And sliceable, along with vectors. E.g. ([0 1 2] 0 1) -> [0 1]

11:47 Ah. Just doing an OCD generality audit.

11:47 rhickey: Clojure strives to be as general as is practical

11:48 edw: I'll try to restrain my some of my more Scheme-like personality traits. ;)

11:49 rhickey: edw: it's a fair question

11:49 edw: So how about the splicing? (Since you've emboldened me...)

11:50 rhickey: edw: saving those additional args for multiple dimension indexing

11:51 there's subvec already

11:52 edw: Ah. OK. Just finished watching the two part video. I was thinking about the treating-a-vector-as-if-it-were-multi-dimensional feature.

11:52 rhickey: I don't think splicing is that important an operation

11:54 edw: I agree. But for a single-dimensional data structure, it's the most obvious use of a second argument. To me.

11:55 And so that's where my mind went. I'm trying things and seeing if they do what I intuitively think they should and then looking them up when they don't work that way.

11:57 Chouser: edw: that's an interesting experiment, but the results will surely be highly dependent on your particular background, don't you think?

11:58 edw: Yes. I didn't mean to imply that a proper language should validate my intuition.

11:58 Intuit is a plastic thing.

11:59 Intuition, even. It's cold in this coffee shop.

11:59 Chouser: It's a very intruiging way to introduce yourself to a new language. Unfortunately, I'm in too deep already -- my intuition has now been almost entirely overtaken by what Clojure actually does.

12:03 edw: I've been doing little but Scheme for several years, but have gone from 6502 assembly to C to Perl to Java to Python previously. I'm sort of stuck thinking that Scheme is the programming language that God wrote the universe in, but I'd like something for practically-minded mortals.

12:05 Chouser: Yes, I'm sure He has no trouble keeping track of all His mutable state.

12:06 kotarak_: I was also a Scheme fan before (and still am). But Clojure replaced it almost immediately as my favourite.

12:07 blbrown: just wanted to say, clojure is really cool... I am having a blast with it

12:07 funny that it is a lisp, but doesn't seem like it

12:08 Cark: blbrown : what do you mean ?

12:09 blbrown: Cark, well, I been using Common Lisp off and on for years, but it seemed a little cumbersome, but I seem to work better with Clojure. I think it is because I also work with Java

12:09 edw: Getting over the lack of TCO was the big stumbling block for me to get over, because I'm habituated to think of the procedure call as the only "real" looping construct.

12:10 kotarak_: blbrown: Or the changes rhickey did to "Lisp", were just the right things?

12:10 Cark: blbrown, CL was my first exposure to lisp so i guess it'll always have a place in my heart

12:10 blbrown: karmazilla, possibly that too

12:11 edw: Clojure represents to me a nice blend of the MIT and New Jersey schools.

12:11 gnuvince_: Better is the New Worse is Better

12:12 edw: A Better Worse

12:44 rhickey: Clojure group crossed 10000 messages today!

12:45 Google still says "low activity" :(

12:46 antifuchs: bah, google

12:47 if it's below a hundred billion, they don't even take notice.

12:48 gnuvince_: Give it time; the rise of Clojure is pretty impressie

12:48 *impressive

12:48 We're regularly at 100+ users connected to this channel

12:50 danlarkin: yeah but like only 30 people ever talk

12:50 70 lurkers freaks me out

12:52 antifuchs: you could call them programming language stalkers if that's better (:

12:53 * apage43 is a creep.

13:03 blbrown: im active, sort of...silence is golden

13:10 Chousuke: an IRC channel is unhealthy without its share of lurkers.

14:12 danlarkin: lisppaste8: url

14:12 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

14:14 danlarkin pasted "suitable for clojure.contrib.ns-utils ?" at http://paste.lisp.org/display/73772

14:15 danlarkin: that takes a string, although it could be modified to take a symbol too

14:16 so you pass it like "my.app.foo/bar"

14:17 and if my.app.foo is on your classpath it'll require it and resolve bar in that context and return it

14:37 Chouser: seems reasonable to me.

14:38 danlarkin: cool

14:39 Chouser: You might use 'symbol' to split the namespace from the name, rather than a regex

14:40 danlarkin: ,(symbol "my.app.foo/bar")

14:40 clojurebot: my.app.foo/bar

14:40 Chouser: ,(namespace (symbol "clojure.contrib.mmap/slurp"))

14:40 clojurebot: "clojure.contrib.mmap"

14:41 danlarkin: ah

14:41 Chouser: ,(name (symbol "clojure.contrib.mmap/slurp"))

14:41 clojurebot: "slurp"

14:41 danlarkin: ahh ha

14:41 yes that is probably better

14:50 lisppaste8: danlarkin annotated #73772 with "dropped regex" at http://paste.lisp.org/display/73772#1

14:50 danlarkin: so that one takes a string or symbol

14:52 kotarak: A Java question: Is there a way to have a InputStream, that can be feed with additional input? So something like a Queue but in form of a InputStream?

14:56 Chousuke: sounds like a pipe

14:57 java.nio has it it seems. http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/Pipe.html

14:57 kotarak: Exactly. I feed it on one end with characters, and the other end can read them as from a normal InputStream

14:57 oh

14:58 Chousuke: it doesn't seem to use *Streams though.

14:58 kotarak: Yeah. :/ and it talks about "bytes"...

14:59 But there is java.nio.channels.Channels! Hah!

14:59 Chousuke: http://java.sun.com/j2se/1.4.2/docs/api/java/io/PipedInputStream.html this if you don't want to use nio

15:00 but apparently nio is better... it wouldn't be "new io" if it weren't I guess

15:01 kotarak: Chousuke: thanks! Good pointers!

15:18 rowth: this may be a _really_ stupid idea, but...in some other jvm languages like groovy, you can use a clojure to implement a single method interface (i.e. if you're calling addActionListener etc.), would it be complete madness to ask if we could do something similar with clojure? Don't get me wrong, the (proxy ...) form is already much more terse than java, I'm just wondering...

15:19 also, since this is the first time I've actually said something to clojure folk, I might as well take the opportunity to say that Clojure rocks...thanks Rich!

15:20 damn, I meant "use a closure"

15:22 apage43: rowth: could it be implemented quickly enough as a macro? I don't see why not.

15:22 or wait, no

15:22 i see what you mean

15:29 rowth: I suppose you could try and do something like that, but then you end up with extra stuff wrapping the method you're calling and the closure you're passing in, which would defeat the point since the (proxy) syntax is already pretty terse. I suppose it may not be worth the potential extra complexity in the compiler, it's just that single method interfaces in java are basically the languages way of implementing a poor mans closure, so it would be nice if we coul

15:32 I like the idea of being able to do (.addActionListener button #(.setText label "you clicked zee button!")) or whatever

15:33 and if you use frameworks like Spring, there are an absolute shedload of methods that take single line Callback interfaces (doWithMethods, RowMapper, validators and all that caper)

15:33 rhickey: rowth: that would require compiler support, yes. I remember hearing about the Groovy feature and thinking there was some wart in it, but can't recall - something with overloading?

15:35 rowth: yeah...if the interface declares more than one method you have to use a closure that takes an array of objects

15:35 kotarak: (defn add-action-listener [widget callback] (.addActionListener widget (proxy [ActionThingyClassIDontRemember] []�(actionPerformed [e] (callback e))))) (add-action-listener button #(..)), not general though...

15:36 rowth: but (IMHO) groovy tries too hard to make things (supposedly) easy with a whole slew of random syntax / conventions

15:36 I was thinking of something a bit more clean cut

15:39 kotarak: yes it's easy to deal with individual cases; I suppose that might be the best way to deal with it rather than overcomplicating the core language

15:48 gnuvince_: ,(some even? [1 2 3])

15:48 clojurebot: true

15:48 gnuvince_: ,(some identity [nil 2 3])

15:48 clojurebot: 2

16:04 LARefugee: clojurebot: logs?

16:04 clojurebot: logs is http://clojure-log.n01se.net/

16:13 lisppaste8: fanda pasted "Error in partition?" at http://paste.lisp.org/display/73778

16:14 fanda: (partition 0 [1 2 3]) returns infinite seq of nil

16:14 would you consider that an error?

16:15 see the above paste for all test cases

16:16 hiredman: interesting

16:17 you'd think it would be (cycle `())

16:17 fanda: ,(cycle ())

16:17 clojurebot: nil

16:18 fanda: yes, that's what I am suggesting - plain old nil :-)

16:18 hiredman: no, not (cycle ()), (cycle '())

16:18 "Returns a lazy sequence of lists of n items each"

16:18 from the partition doc string

16:19 if n is 0, '()

16:19 fanda: i see... sequence of lists

16:19 hiredman: weird

16:19 rhickey: hiredman: you mean (repeat ())

16:20 hiredman: rhickey: I am sure I do

16:21 rhickey: or just change doc to: "Returns a lazy sequence of sequences of n items each", and leave behavior as is

16:21 fanda: (partition 0 [1 2 3]) => (() () ()) ??

16:21 (partition 0 [1 2 3]) => (nil nil nil) ??

16:22 rhickey: fanda: it will be infinite, as you never consume the input

16:22 * rhickey thinks the only thing wrong is the doc

16:24 hiredman: you win

16:26 fanda: ok, fine with me then

16:30 it is hard to break Clojure, I tell you :-)

16:30 it looks that people use it so much that many bugs are gone at this point

16:35 ,(+ 1.1 2)

16:35 clojurebot: 3.1

16:35 fanda: ,(+ 1.1 2.2)

16:35 clojurebot: 3.3000000000000003

16:36 danlarkin: fanda: bugs are never gone

16:36 that is to say, there will always be more

16:36 fanda: yes, but I have to say I have not had any luck finding them :-)

16:37 I am writing some function tests for clojure.core - none so far...

16:37 ,(list (+ 1.1 2) (+ 1.1 2.1) (+ 1.1 2.2) (+ 1.1 2.3) (+ 1.1 2.4) (+ 1.1 2.5))

16:37 clojurebot: (3.1 3.2 3.3000000000000003 3.4 3.5 3.6)

16:38 fanda: this is consistent with numbers in Java, but strange anyway

16:38 Chousuke: you can use ratios if you don't want to lose precision

16:38 karmazilla: ,(+ 1.1M 2.2M)

16:38 clojurebot: Huh?

16:39 karmazilla: I wonder why that didn't work

16:40 fanda: ,(+ (bigdec 1.1) (bigdec 2.2))

16:40 clojurebot: 3.3M

16:52 lpetit: Hello all. Is it possible to create from clojure an array of primitive bytes ? I've seen function int-array, float-array, ... but there does not seem to be an byte-array ?

16:53 kotarak: lpetit: some combination of make-array with Byte/TYPE

16:54 lpetit: will this create a java.lang.Byte[] , or a byte[] ?

16:54 I'm in the quest of performance

16:55 kotarak: I would expect byte.

16:55 lpetit: ,(class (make-array Byte 3))

16:55 clojurebot: [Ljava.lang.Byte;

16:55 lpetit: ,(class (make-array Byte/TYPE 3))

16:55 clojurebot: [B

16:56 lpetit: Is it this, the difference ?

16:56 I'm not sure how to interpret [B . But I'm sure it's different from [Ljava.lang.Byte; ?

16:56 dreish: ,(make-array Byte/TYPE 3)

16:56 clojurebot: #<byte[] [B@16095fc>

16:56 dreish: if that's any clearer.

16:56 lpetit: ok, thank you guys !

16:57 dreish: Just don't prematurely optimize.

16:58 lpetit: Yeah, I know. I've encountered a weird bug with the implementation of the JDK. Using a more "high-level" inputstream : DataInputStream, I've used writeUTF , but it does not work if your String representation as UTF-8 is bigger than 65535 bytes !

16:59 dreish: Interesting.

16:59 lpetit: And for the communication between a client and a server, I needed to pass big Strings ... so I have to make my hands dirty and use the old way : write(byte [] bytes, int offset, int length)

17:00 I've seen the code of the JDK, I can see where the exception is thrown :-(

17:37 alex_____: apparently durka is taken

17:39 danlarkin: gotta register with nickserv

18:24 TD: are there any docs comparing the space complexity of clojure programs vs the equivalent java progams?

18:36 actually space/time complexity

18:36 i want to know what the efficiency hit of using clojure is, but the website doesn't seem to discuss it

18:43 hiredman: TD: what is your exact use case?

18:43 TD: just resource-constrained environments in general. desktop use or mobile. java has very poor memory usage, but i at least understand the cost of what i do.

18:44 hiredman: the general consesus is clojure is a. good enough b. can be optimized to spit out almost/the exact same bytecode as java

18:44 TD: i'm looking at JVM compatible languages for future projects, and see scala and clojure. but the problem is the costs of the features are never spelled out.

18:45 hiredman: sounds like you're doing premature optimization :P

18:45 TD: bytecode is only part of the story right. for instance the website says, use an immutable/persistant map instead of an object. fine. what is the cost of that, in bytes.

18:46 hiredman: if you are looking for "future" projects, in the future phones will have a gig or more of ram

18:46 TD: no, understanding the cost of your constructs is fundamental. people who don't write software that is unpleasant to use (or, on the server side, just expensive)

18:46 hiredman: currently, most phones have j2me, which really blows

18:46 Chousuke: TD: you could do the community a favour and find out.

18:48 space complexity for the immutable structures is not an issue for most clojure users I think, because they're used for things where the cost, whatever it is, is dwarfed by the benefits.

18:49 hiredman: and stuff that is not referenced is GC'ed

18:51 whoops

18:53 TD_: did i miss an answer? looks like i got disconnected

23:18 danlarkin: Interesting, java crashed with a Bus Error when I rebuilt clojure.jar while it was running

23:20 Chouser: I think that's my most common java crash. Perhaps the only one, actually.

23:26 gnuvince_: *sigh*

Logging service provided by n01se.net