#clojure logs

2009-01-17

00:29blbrownare 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
00:33johan1I'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?
00:36johan1or could tell me how to create an anonymous object without first having a class or interface in a jar file
00:37Carkisn't there an abstract class you could derive from ?
00:39Carksomething like (proxy [org.apache.xmlrpc.XmlRpcHandler] [] (execute [pname, pvector] ....
00:39johan1perhaps 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
00:39johan1perhaps... I will check the API
00:40danlarkinShould I use (symbol (str (first (all-ns)))) or can I use (.getName (first (all-ns)))?
00:41danlarkinI suppose the line is that I can't trust that getName will be there in the future eh
00:41Cark(ns-name (first (all-ns)))
00:42Cark(doc ns-name)
00:42clojurebotReturns the name of the namespace, a symbol.; arglists ([ns])
00:42danlarkin:) perfect
00:42danlarkinthanks, Cark!
00:42Cark=)
02:36danlarkinYesss, auto-reloading based purely on (all-ns) working!
09:12edwOK, after watching the Clojure videos, I'm way convinced that there's a there there.
09:14Chouseras in Clojure's not just a fad language?
09:15edwYeah. Rich Hickey is not a 2nd year CS student.
09:30edwThe transaction management stuff is very nice.
09:46edwOh! I thought I was on #scheme!
10:03edwIs here a SLIME for Clojure for idiots guide somewhere?
10:03edwI use SLIME for Scheme48 for a while...
10:03leafwedw: google is your friend.
10:04Carkbill clementson has a couple blog articles on the subject
10:04Cark(morning)
10:05edwYes, it is, but I'm going through a lot of pages that provide...incomplete information.
10:06edwIt's sort of like reading posts by PHP programmers talking about Ruby on Rails. Or football players talking about feelings.
10:06edwThanks Cark.
10:17edwleafw: 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:17edws/there all/all/
10:18Carktss, it's never a bad thing to ask a question
10:20Carkhum and btw did you check the getting started section on the wikibook ?
10:21edwWikibook?
10:22Carkfrom the clojure official site, click on the wiki link
10:22Carkclojurebot : wiki
10:22lisppaste8edw pasted "A useful IRC topic" at http://paste.lisp.org/display/73757
10:22Carkclojurebot : wikibook
10:22Carkhum =/
10:22edwleafw: Over is #scheme, we try to be helpful.
10:23edwCark: I heard there's a beta Clojure book that can be bought.
10:24Carkyes there is, i don't know where to find it though
10:24arbscht_clojurebot: book
10:24clojurebotbook is http://www.pragprog.com/titles/shcloj/programming-clojure
10:24arbscht_clojurebot: wiki
10:24clojurebotwiki is http://en.wikibooks.org/wiki/Clojure_Programming
10:24Carkhey why is clojurenot answering to you ?
10:25Carkoh i know
10:25edwI figured it was Pragmatic: they did the same thing with the DHH Rails book.
10:25Carkclojurebot: wiki
10:25clojurebotwiki is http://en.wikibooks.org/wiki/Clojure_Programming
10:25ChousukeCark: you have a space between clojurebot and :
10:25Carkclojurebot : wiki
10:25Carkyes
10:25Chousukeit's very strict about that.
10:26Chousukeyou're not even allowed to use , or any other delimiter
10:26Chousukehas to be : :)
10:26edwColons are so formal.
10:28Carkclojurebot: you're too formal
10:28clojurebotExcuse me?
11:45edwHmm. Strings should be callable. E.g. ("012" 1) -> 1
11:46rhickeyedw: unlikely, for perf reasons
11:46edwAnd sliceable, along with vectors. E.g. ([0 1 2] 0 1) -> [0 1]
11:47edwAh. Just doing an OCD generality audit.
11:47rhickeyClojure strives to be as general as is practical
11:48edwI'll try to restrain my some of my more Scheme-like personality traits. ;)
11:49rhickeyedw: it's a fair question
11:49edwSo how about the splicing? (Since you've emboldened me...)
11:50rhickeyedw: saving those additional args for multiple dimension indexing
11:51rhickeythere's subvec already
11:52edwAh. OK. Just finished watching the two part video. I was thinking about the treating-a-vector-as-if-it-were-multi-dimensional feature.
11:52rhickeyI don't think splicing is that important an operation
11:54edwI agree. But for a single-dimensional data structure, it's the most obvious use of a second argument. To me.
11:55edwAnd 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:57Chouseredw: that's an interesting experiment, but the results will surely be highly dependent on your particular background, don't you think?
11:58edwYes. I didn't mean to imply that a proper language should validate my intuition.
11:58edwIntuit is a plastic thing.
11:59edwIntuition, even. It's cold in this coffee shop.
11:59ChouserIt'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:03edwI'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:05ChouserYes, I'm sure He has no trouble keeping track of all His mutable state.
12:06kotarak_I was also a Scheme fan before (and still am). But Clojure replaced it almost immediately as my favourite.
12:07blbrownjust wanted to say, clojure is really cool... I am having a blast with it
12:07blbrownfunny that it is a lisp, but doesn't seem like it
12:08Carkblbrown : what do you mean ?
12:09blbrownCark, 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:09edwGetting 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:10kotarak_blbrown: Or the changes rhickey did to "Lisp", were just the right things?
12:10Carkblbrown, CL was my first exposure to lisp so i guess it'll always have a place in my heart
12:10blbrownkarmazilla, possibly that too
12:11edwClojure represents to me a nice blend of the MIT and New Jersey schools.
12:11gnuvince_Better is the New Worse is Better
12:12edwA Better Worse
12:44rhickeyClojure group crossed 10000 messages today!
12:45rhickeyGoogle still says "low activity" :(
12:46antifuchsbah, google
12:47antifuchsif it's below a hundred billion, they don't even take notice.
12:48gnuvince_Give it time; the rise of Clojure is pretty impressie
12:48gnuvince_*impressive
12:48gnuvince_We're regularly at 100+ users connected to this channel
12:50danlarkinyeah but like only 30 people ever talk
12:50danlarkin70 lurkers freaks me out
12:52antifuchsyou could call them programming language stalkers if that's better (:
13:03blbrownim active, sort of...silence is golden
13:10Chousukean IRC channel is unhealthy without its share of lurkers.
14:12danlarkinlisppaste8: url
14:12lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
14:14lisppaste8danlarkin pasted "suitable for clojure.contrib.ns-utils ?" at http://paste.lisp.org/display/73772
14:15danlarkinthat takes a string, although it could be modified to take a symbol too
14:16danlarkinso you pass it like "my.app.foo/bar"
14:17danlarkinand if my.app.foo is on your classpath it'll require it and resolve bar in that context and return it
14:37Chouserseems reasonable to me.
14:38danlarkincool
14:39ChouserYou might use 'symbol' to split the namespace from the name, rather than a regex
14:40danlarkin,(symbol "my.app.foo/bar")
14:40clojurebotmy.app.foo/bar
14:40Chouser,(namespace (symbol "clojure.contrib.mmap/slurp"))
14:40clojurebot"clojure.contrib.mmap"
14:41danlarkinah
14:41Chouser,(name (symbol "clojure.contrib.mmap/slurp"))
14:41clojurebot"slurp"
14:41danlarkinahh ha
14:41danlarkinyes that is probably better
14:50lisppaste8danlarkin annotated #73772 with "dropped regex" at http://paste.lisp.org/display/73772#1
14:50danlarkinso that one takes a string or symbol
14:52kotarakA 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:56Chousukesounds like a pipe
14:57Chousukejava.nio has it it seems. http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/Pipe.html
14:57kotarakExactly. I feed it on one end with characters, and the other end can read them as from a normal InputStream
14:57kotarakoh
14:58Chousukeit doesn't seem to use *Streams though.
14:58kotarakYeah. :/ and it talks about "bytes"...
14:59kotarakBut there is java.nio.channels.Channels! Hah!
14:59Chousukehttp://java.sun.com/j2se/1.4.2/docs/api/java/io/PipedInputStream.html this if you don't want to use nio
15:00Chousukebut apparently nio is better... it wouldn't be "new io" if it weren't I guess
15:01kotarakChousuke: thanks! Good pointers!
15:18rowththis 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:19rowthalso, 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:20rowthdamn, I meant "use a closure"
15:22apage43rowth: could it be implemented quickly enough as a macro? I don't see why not.
15:22apage43or wait, no
15:22apage43i see what you mean
15:29rowthI 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:32rowthI like the idea of being able to do (.addActionListener button #(.setText label "you clicked zee button!")) or whatever
15:33rowthand 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:33rhickeyrowth: 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:35rowthyeah...if the interface declares more than one method you have to use a closure that takes an array of objects
15:35kotarak(defn add-action-listener [widget callback] (.addActionListener widget (proxy [ActionThingyClassIDontRemember] []�(actionPerformed [e] (callback e))))) (add-action-listener button #(..)), not general though...
15:36rowthbut (IMHO) groovy tries too hard to make things (supposedly) easy with a whole slew of random syntax / conventions
15:36rowthI was thinking of something a bit more clean cut
15:39rowthkotarak: 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:48gnuvince_,(some even? [1 2 3])
15:48clojurebottrue
15:48gnuvince_,(some identity [nil 2 3])
15:48clojurebot2
16:04LARefugeeclojurebot: logs?
16:04clojurebotlogs is http://clojure-log.n01se.net/
16:13lisppaste8fanda pasted "Error in partition?" at http://paste.lisp.org/display/73778
16:14fanda(partition 0 [1 2 3]) returns infinite seq of nil
16:14fandawould you consider that an error?
16:15fandasee the above paste for all test cases
16:16hiredmaninteresting
16:17hiredmanyou'd think it would be (cycle `())
16:17fanda,(cycle ())
16:17clojurebotnil
16:18fandayes, that's what I am suggesting - plain old nil :-)
16:18hiredmanno, not (cycle ()), (cycle '())
16:18hiredman"Returns a lazy sequence of lists of n items each"
16:18hiredmanfrom the partition doc string
16:19hiredmanif n is 0, '()
16:19fandai see... sequence of lists
16:19hiredmanweird
16:19rhickeyhiredman: you mean (repeat ())
16:20hiredmanrhickey: I am sure I do
16:21rhickeyor just change doc to: "Returns a lazy sequence of sequences of n items each", and leave behavior as is
16:21fanda(partition 0 [1 2 3]) => (() () ()) ??
16:21fanda(partition 0 [1 2 3]) => (nil nil nil) ??
16:22rhickeyfanda: it will be infinite, as you never consume the input
16:24hiredmanyou win
16:26fandaok, fine with me then
16:30fandait is hard to break Clojure, I tell you :-)
16:30fandait looks that people use it so much that many bugs are gone at this point
16:35fanda,(+ 1.1 2)
16:35clojurebot3.1
16:35fanda,(+ 1.1 2.2)
16:35clojurebot3.3000000000000003
16:36danlarkinfanda: bugs are never gone
16:36danlarkinthat is to say, there will always be more
16:36fandayes, but I have to say I have not had any luck finding them :-)
16:37fandaI am writing some function tests for clojure.core - none so far...
16:37fanda,(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:37clojurebot(3.1 3.2 3.3000000000000003 3.4 3.5 3.6)
16:38fandathis is consistent with numbers in Java, but strange anyway
16:38Chousukeyou can use ratios if you don't want to lose precision
16:38karmazilla,(+ 1.1M 2.2M)
16:38clojurebotHuh?
16:39karmazillaI wonder why that didn't work
16:40fanda,(+ (bigdec 1.1) (bigdec 2.2))
16:40clojurebot3.3M
16:52lpetitHello 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:53kotaraklpetit: some combination of make-array with Byte/TYPE
16:54lpetitwill this create a java.lang.Byte[] , or a byte[] ?
16:54lpetitI'm in the quest of performance
16:55kotarakI would expect byte.
16:55lpetit,(class (make-array Byte 3))
16:55clojurebot[Ljava.lang.Byte;
16:55lpetit,(class (make-array Byte/TYPE 3))
16:55clojurebot[B
16:56lpetitIs it this, the difference ?
16:56lpetitI'm not sure how to interpret [B . But I'm sure it's different from [Ljava.lang.Byte; ?
16:56dreish,(make-array Byte/TYPE 3)
16:56clojurebot#<byte[] [B@16095fc>
16:56dreishif that's any clearer.
16:56lpetitok, thank you guys !
16:57dreishJust don't prematurely optimize.
16:58lpetitYeah, 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:59dreishInteresting.
16:59lpetitAnd 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:00lpetitI've seen the code of the JDK, I can see where the exception is thrown :-(
17:37alex_____apparently durka is taken
17:39danlarkingotta register with nickserv
18:24TDare there any docs comparing the space complexity of clojure programs vs the equivalent java progams?
18:36TDactually space/time complexity
18:36TDi want to know what the efficiency hit of using clojure is, but the website doesn't seem to discuss it
18:43hiredmanTD: what is your exact use case?
18:43TDjust 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:44hiredmanthe general consesus is clojure is a. good enough b. can be optimized to spit out almost/the exact same bytecode as java
18:44TDi'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:45hiredmansounds like you're doing premature optimization :P
18:45TDbytecode 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:46hiredmanif you are looking for "future" projects, in the future phones will have a gig or more of ram
18:46TDno, 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:46hiredmancurrently, most phones have j2me, which really blows
18:46ChousukeTD: you could do the community a favour and find out.
18:48Chousukespace 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:49hiredmanand stuff that is not referenced is GC'ed
18:51hiredmanwhoops
18:53TD_did i miss an answer? looks like i got disconnected
23:18danlarkinInteresting, java crashed with a Bus Error when I rebuilt clojure.jar while it was running
23:20ChouserI think that's my most common java crash. Perhaps the only one, actually.
23:26gnuvince_*sigh*