#clojure logs

2009-05-31

02:37duck1123_Are there any good libraries for working with namespaced xml? Most of the ones I've seen weren't ns-aware.
06:54cads_is there a limited count function which won't bottom on infinite sequences?
07:01cads_,(defn count-max [coll n] (count (take n coll)))
07:01clojurebotDENIED
07:02cads_,((fn count-max [coll n] (count (take n coll))) (repeat :hat) 1000000)
07:02clojurebot1000000
07:03cads_,((fn count-max [coll n] (count (take n coll))) (repeat :hat 666) 1000000)
07:03clojurebotjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.Number
07:03cads_,((fn count-max [coll n] (count (take n coll))) (repeat 666 :hat) 1000000)
07:03clojurebot666
07:05cads_,((fn safe-count ([coll] safe-count 100000) ([coll n] (count (take n coll))) (repeat:hat)))
07:05clojurebotjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
07:05cads_,((fn safe-count ([coll] (safe-count 100000)) ([coll n] (count (take n coll))) (repeat:hat)))
07:05clojurebotjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
07:05cads_aww man
07:05cads_,((fn safe-count ([coll] (safe-count coll 100000)) ([coll n] (count (take n coll))) (repeat:hat)))
07:05clojurebotjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
07:09cads_,((fn safe-count ([coll] (safe-count coll 100000)) ([coll n] (count (take n coll)))) (repeat :hat))
07:09clojurebot100000
07:55Chouser,((fn safe-count [coll & [limit]] (if (counted? coll) (count coll) (count (take (or limit 100000) coll)))) (repeat :hat))
07:55clojurebot100000
08:08rhickeywhere would Clojure be? - http://gmarceau.qc.ca/blog/2009/05/speed-size-and-dependability-of.html
08:13Chouserfascinating
08:33rhickeyuh oh, new version of Arc on our tail: http://arclanguage.org/item?id=9383 :)
08:34wlrrhickey: wonder if this credible source has anything to offer the future of clojure (esp the bigraphical model): http://www.cl.cam.ac.uk/~rm135/
08:40rhickeywlr: I'll let you know after I read: http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=9780521738330
08:41wlrrhickey: You can preview portions there and also on Amazon
08:41rhickeywlr: ordered already
08:42rhickeyI'm skeptical
08:45wlrI wasn't convinced one way or the other. Just thought you might like to pass it through your gifted filter.
08:46rhickeyMilner is awesome of course
08:46rhickeybound to be interesting
08:46LomonoRobin Milner :3
08:49rysSpeaking of books, is buying the pragprog Clojure book an indirect way to donate to the project?
08:51rhickeyrys: does nothing for me, helps Clojure by rewarding pragprog for taking the risk with it and Stuart for his effort
08:52rysAh, cool
08:53rysI'll coerce paypal into life later on then
08:54rhickeyrys: thanks!
08:54rysAh, thank you for the language :)
08:54Chouserrhickey (theoretically) gets a percentage of revenue from http://www.zazzle.com/clojure
08:55Chousera small percentage. I'd tell you how much if I could find the number...
08:55rysA programmer can always do with some new threads ;)
08:56Chouserah, 10% it looks like
08:56ryslol @ the slogans on the shirts
08:58Lomonoany updates from the people trying to get Clojure into that shootout.alioth.debian.org?
08:58rhickeyLomono: are there people doing that?
08:59Lomonothere're sporadic postings on the mailing list last I checked
09:01LomonoI just read "The speed, size and dependability of programming languages", and I thought it was odd that Clojure was missing from the analysis
09:01Lomonohttp://gmarceau.qc.ca/blog/2009/05/speed-size-and-dependability-of.html
09:25durka42well, we don't have any entries in the shootout
09:25durka42perhaps this should be changed
09:31durka42i wonder who you email to ask for them to include a new language
09:41Lomonodurka42: you would need to register at their forum and create a new topic https://alioth.debian.org/forum/forum.php?forum_id=999
09:42Lomono(one of?) the caveat of participating in the alioth benchmark is [we ask that contributed programs not only give the correct result, but also use the same algorithm to calculate that result.]
09:43LomonoI'd recommend that you give the FAQ a quick scan http://shootout.alioth.debian.org/u32q/faq.php
09:43durka42i did
09:43durka42i'll create a topic
09:47durka42ok, that would be the first time i've gotten an account verification email with instructions that don't work
09:47Lomono:[
11:29rhickey_whither github?
11:29clojurebotgithub is git://github.com/kevinoneill/clojure.git
11:32Chouserwfm
11:34rysIs that repo considered clojure's master as far as git goes? I've been using svn from googlecode, but I'm more comfortable with git
11:35Chouserrys: I use git-svn with the googlecode repo. That's where rhickey_ commits, so it's always going to be the most up to date.
11:36rysAh, great
11:38rhickey_is there a notion of project members on github?
11:39quidnuncgit svn is going to be much slower than pulling from git mirror.
11:39rysrhickey_: you can add contributors to a repo
11:39rysSo they have commit privileges
11:40Chouser"repository collaborators" in the Admin tab of the project
11:44rysMaybe only kevin can add new collaborators, since it's his repository?
11:45Lomono^
11:45Lomonohttp://github.com/guides/managing-collaborators
11:45rhickey_rys: I'm looking at my repo
11:45quidnuncThere is also gitorious.org which is AGPLv3
11:48rhickey_ah, see it in Safari but not Camino - aargh
11:49rysheh
11:51Chouserif my window is too narrow, scrolling horizontally doesn't show any more tabs -- just blank area (firefox)
11:58Chouserhm, same behavior in chromium.
12:01alinphi
12:01alinpuser=> (use clojure.contrib.server-socket)
12:01alinpjava.lang.ClassNotFoundException: clojure.contrib.server-socket (NO_SOURCE_FILE:1)
12:01alinp 828 s003 Ss+ 0:01.40 /usr/bin/java -cp /Users/alin/apps/clojure-1.0/clojure-1.0.0.jar:/Users/alin/apps/clojure-contrib/clojure-contrib.jar clojure.main
12:01Chouseralinp: you need to quote the arg
12:01Chouser(use 'foo)
12:01alinpso, I started the repl also including the clojure-contrib
12:02alinpthe :require doesn't work in repl ?
12:02Chousernote that's different from when used in the 'ns' macro, where you would say: (ns bar (:use foo))
12:02Chouser'use' and 'require' are plain functions that take symbols as arguments, so you need to quote them.
12:02alinpI see
12:02alinpthanks
12:02Chouserthe 'ns' macro does that quoting for you when used with :use and :require
12:06alinp(ns test)
12:06alinp(defn test [] ())
12:07alinpException in thread "main" java.lang.Exception: Name conflict, can't def test because namespace: test refers to:#'clojure.core/test (server.clj:3)
12:07alinpsame result if I'm doing: (ns my.test)
12:07alinpwhat I'm missing here ?
12:07Chouserby default, the 'ns' macro brings into your new namespace all the names from clojure.core, which includes a function named "test"
12:08Chouserso that you can say + or map instead of clojure.core/+ and clojure.core/map
12:08Chouserbut that also means you can't define your own functions (vars, really) with those same names.
12:09alinpcan I exclude functions from being loaded ?
12:09alinplike haskell for instance
12:09Chouserso you can either exclude certain names from core when you do your 'ns' (see the :refer-clojure option), or name your function differently (which is what I would generally recommend) like (defn my-test [] ())
12:09alinplike you said, + or map ... to make them my own ... but to exclude from core
12:10alinpI see
12:10alinpthanks, I'll look into this
12:13chrizelI wonder what would be the easiest functional way to move an item in a vector to a different position inside the vector - can't find a function for this
12:18chrizelMaybe lists will be better suited for this -- or some combination with subvec
12:40Chouserchrizel: vectors don't shrink or grow in the middle well. swap would be fast, but I suspect that's not what you want.
14:37ChouserIt would be nice if there were a difference between non-private vars and vars that are refer'ed by default.
14:38Chousermainly for functions that I want to call from public macros
16:05rhickey_Chouser: yes
16:06rhickey_Chouser: does xml-> require you create your own zipper?
16:30Chouserrhickey_: yes
16:30Chouserrhickey_: I think zip-filter.xml may have been eclipsed by enlive
16:31ChouserI haven't tried it yet, but cgrand looked at zip-filter, used it some, and then wrote something new. It's reasonable to assume what he created is better. :-)
16:31rhickey_yeah, does its select do everything zip-filter did?
16:34ChouserI don't know. The one feature that was most important for me with zip-filter was the ability to drop in straight clojure filters in the middle, to keep it open
16:35ChouserI wasn't sure if enlive did that or not, but I saw in a blog recently that cgrand had that goal as well.
16:35ChouserAs soon as I try out some enlive stuff, I expect (hope?) to be able to deprecate zip-filter
16:36ChouserI appreciate the effort, but I don't know if there's much I've done that looks that great.
16:36ChouserI still like repl-utils. *shrug*
16:37ChouserI'm doing fun stuff with JNA and libc. I nearly have inotify (linux filesystem change notification thing) working.
16:37Chouserhm, but you can't demo that on a mac.
18:25durka42script bowl?
18:31rhickey_durka42: at java one
18:32durka42~script bowl is http://weblogs.java.net/blog/robc/archive/2009/04/javaone_2009_sc.html
18:32clojurebotRoger.
18:36powr-tocIs it possible to store a mutable java object in an agent? If the cost of refactoring it to be mutable was too high, what would be the best thing to do? Wrap it in a layer that ensures all mutations generate a new object; to enforce identity semantics?? Is there anything else I need do?
18:37rhickey_powr-toc: are you going to mutate it?
18:37powr-tocrhickey_: yeah
18:37powr-tocvia the function to send
18:38rhickey_then people reading the agent will be messed up by that
18:38rhickey_basically a mess
18:38rhickey_mutable things need locks
18:38powr-tocrhickey_: is that because of identity equality?
18:39rhickey_it's just the normal dangers of inconsistency and race conditions
18:39powr-tocok sorry... being stupid... I think I get it
18:40powr-tocyeah, it's all the classic visibility problems etc...
18:43powr-tocare there any clojure idioms for sane locking? Is it typically best to use the java5 java.util.concurrent.lock's or the synchronized key word?
18:43hiredman,(doc locking)
18:44clojurebot"([x & body]); Executes exprs in an implicit do, while holding the monitor of x. Will release the monitor of x in all circumstances."
18:44hiredmandunno how sane t hat is
18:44powr-tocooo cool
18:44powr-tocthough it assumes the monitor is the object right?
18:45hiredmaneh?
18:45rhickey_http://www.amazon.com/gp/product/0321349601?ie=UTF8&tag=none0b69&linkCode=as2&camp=1789&creative=9325&creativeASIN=0321349601
18:45powr-tochiredman: In java monitor's are implemented in Object... so it's common to synchronize on the object itself... though that's not always what you want... particularly if you want finer grained locking
18:45clojurebot?
18:46stuhoodpowr-toc: it is exactly like a synchronized block.
18:46Chousukeclojurebot has a caffeine addiction it seems.
18:46stuhoodwhatever object you choose to synchronize on provides the monitor
18:46powr-tocstuhood: ok... so it takes the monitor...
18:46hiredmanyes
18:46powr-toccool
18:48powr-tocI'm being very slow today... asking lots of stupid questions I'd know the answer to if I just engaged my brain...
19:51ataggart(#(+ %&) 123)
19:51ataggart,(#(+ %&) 123)
19:51clojurebotjava.lang.ClassCastException
19:52ataggart,(#(+ 5 %&) 1 2 3)
19:52clojurebotjava.lang.ClassCastException: clojure.lang.ArraySeq cannot be cast to java.lang.Number
19:53ataggart((partial + 5) 1 2 3)
19:53Chousukeneed apply
19:53ataggartah
19:53ataggartthx
19:53Chousukethough with partial it ought to work
19:53ataggart,((partial + 5) 1 2 3)
19:53clojurebot11
19:53ataggarthmm
19:53Chousukebut partial isn't the same as #() with a %&
19:54ataggartpartial returns a fn, and #() returns a fn, so why do they behave differently?
19:54Chousukepartial probably uses apply internaly.
19:54Chousuke+l
19:55ataggart,(map #(+ 5 %&) 1 2 3)
19:55clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer
19:55ataggart,(map #(+ 5 %&) [1 2 3])
19:55clojurebotjava.lang.ClassCastException: clojure.lang.ArraySeq cannot be cast to java.lang.Number
19:55Chousuke%& is a seq
19:55Chousuke,(#(do %&) 1)
19:55clojurebot(1)
19:55rhickey_,(+ 5 '(1 2 3))
19:55clojurebotjava.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.Number
19:56ataggartso then #() with &% really isn't a good substitute for patial
19:56ataggart*partial
19:56rhickey_that's what you are saying with %&
19:56Chousukepartial is (fn [x] #(apply + x %&))
19:56Chousukeor something similar
19:56Chousuke(#(apply + 1 %&) 1 2 3 4)
19:56rhickey_partial knows the consumer of the args, with #() they could go anywhere - a consumer might want the seq, not applied
19:56Chousuke,(#(apply + 1 %&) 1 2 3 4)
19:56clojurebot11
19:57ataggartinteresting
19:57rhickey_,(#(count %&) 1 2 3)
19:57clojurebot3
20:38Chouseroh, vars still have :line 0 in their metadata
20:43slashus2Chouser: When do they have :line 0 in their metadata?
20:43Chouser,(:line ^#'map)
20:43clojurebot1494
20:44Chouserhm.
20:44slashus2They seem to have the correct line when I tried it in some code.
20:45Chouserah, I forgot my clojure working copy regressed.
20:45Chousersvn 1382 is a-okay.
20:45slashus2Is that broken for 1.0?
20:45Chouserno
20:47Chouserit was broken and fixed post-1.0
22:01jomofoIn the API doc, add-watcher says that it's "Experimental". I think it is a good solution for a small problem I'm trying to solve. What are the risks of using an Experimental API in clojure?
22:07durka42watchers have been there for a while
22:07durka42i think they should be fine
22:07durka42not sure if their implementation has changed recently
22:07durka42on the other hand, you have to be prepared for bugs since it is experimental
22:12ChouserI think your greater risk is the api changing more than bugs.
22:12jomofoOk, thanks. I can deal with bugs and API changes, just wanted to make sure it wasn't more like "don't use this at all right now"
22:21jomofoJust curious, why does add-watcher require send-type?
22:22durka42i guess, so you can decide whether whoever calls the watcher needs to block
22:22jomofoOh, wait... I think I get it
22:22durka42if you give :send for send-type, will the agent itself block?
22:24durka42unrelated question: can you recur through lazy-seq?
22:26jomofodurka42: Gotcha, when I first saw that I thought it referred to what triggered the state change on the 'observed' reference but I was clearly reading it wrong
22:26durka42oh dear, i seem to have crashed the JVM again
22:38durka42so is it true in general that if i have a bunch of functions that loop over a list doing something, and return a list, and then i convert them all to use lazy-seq and compose them all, then the list should be traversed only once?
22:47cmvkkin general, that sounds right. every time you grab a new element, all of the composed functions run for just that element.
22:49durka42cool
22:50durka42will do some benchmarks when i finish lazifying the functions
23:09technomancyhow do you control the amount of whitespace in the output of clojure.xml/emit?
23:09technomancyI've just been binding println to print, but that's lame. =)
23:10durka42~def clojure.xml/exmit
23:10durka42whoops
23:10durka42~def clojure.xml/emit
23:11durka42it doesn't look like there is any other way, with that implementation
23:12technomancyseems like quite an oversight.