#clojure logs

2008-02-13

04:21jgracinguys, I have a Java class whose ctor is: public Conf(String... args). How can I call this from Clojure? The problem is the argument, which is an array of Strings.
15:41jgracinhi! I'm trying (meta vector), (meta clojure/vector), (meta 'clojure/test), (meta test) and other stuff in the HEAD and I'm getting nil's. How do I get the metadata?
15:42rhickey(meta (var vector)) or ^#'vector
15:43jgracinOh, of course. Vars have meta-data. Thanks!
15:44rhickeysure
16:06rhickeyChouser: Thanks for the nice article on your blog
16:07rhickeyhttp://n01senet.blogspot.com/2008/02/clojure-is-best-lisp-yet.html for those who haven't seen it
16:08Chouserrhickey: heh. sure! how'd you find that?
16:08Chouseroh, I bet a standing Google search for "clojure".
16:08rhickeyyup
16:11Chouserwell, you're quite welcome, though I'm not sure it's worth much. I'm not exactly an opinion leader. :-)
16:11ChouserI should be, but I'm not.
16:14jgracinChouser: would you mind if I "reddit"-ed your blog? :-)
16:14jgracinI think Clojure needs advertising now.
16:15Chouserjgracin: I can't think of why I'd mind, so go right ahead.
16:16Chouserany obvious factual errors I should fix first? rhickey?
16:17rhickeyno, I thought it was ok
16:21jgracindone.
16:22rhickeynew release today, so good timing. Lots of updated docs on the site
16:25ChouserThe "lisp worth talking about" from reddit a couple months ago is a better article. oh well.
16:27jgracinrhickey: yeah. I am amazed how things in and around Clojure keep fitting perfectly.
16:27jgracinyou've struck gold. :-)
16:28rhickey:)
16:31ChouserI seem to pretty often want (filter (fn [x] x) (map A B)) for various A and B. Is there a better way to do that?
16:32rhickeyidentity == (fn [x] x)
17:45Chouserany handy way to go from '((1 2) (3 4) (5 6)) to '((1 3 5) (2 4 6)) ?
17:45Chousersome languages call this "zip"
17:52Chouser(defn zip [& args] (if (first args) (cons (map first args) (apply zip (map rest args))) nil))
17:58ChouserThat's not what I wanted. This is closer: (defn zip [seq] (if (first seq) (cons (map first seq) (zip (map rest seq))) nil))
18:05rhickeyneat. I think going that direction it's unzip
18:06rhickeyhmmm, maybe they're the same once they are variadic...
18:07ChouserI have a tail-recursive version, but it has to call reverse at the end. Is that any better?
18:08rhickeyI don't think there's anything wrong with the map version
18:10Chouseroh, this one still uses map, but it uses recur instead of creating a stack as deep as (count (first seq))
18:13rhickey(def zip (partial apply map list))
18:13Chouserhttp://n01se.net/paste/ijK
18:13Chouserwhoa, what?
18:13rhickeytry it
18:14ChouserI don't have partial. Is my clojure too old?
18:14rhickeyyes, was appl then
18:15Chouseragain, "whoa".
18:15ChouserOk, I need to get food, but I'll have to look at that def.
18:24rhickeyit's lazy: (take 5 (zip (list (iterate inc 1) (iterate inc 2) (iterate inc 3))))
18:24rhickey((1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7))
19:01ChouserI'm still not fully there. I don't yet understand what apply is doing with the 3rd arg.
19:17rhickeyyou mean mapping the list function?
19:18rhickeyuser=> (map list [1 2 3] [4 5 6] [7 8 9])
19:18rhickey((1 4 7) (2 5 8) (3 6 9))
19:19rhickeywhich is almost what you want, but your lists are in a sequence
19:19rhickeyuser=> (apply map list [[1 2 3] [4 5 6] [7 8 9]])
19:19rhickey((1 4 7) (2 5 8) (3 6 9))
19:47Chouseroh, it's the multiple sequences to map that's doing it.
19:54Chouserthe multiple args to apply was throwing me as well, though.
19:56ChouserI didn't realize (apply + 1 2 '(3 4)) was like (apply + (list* 1 2 '(3 4)))
20:00rhickeyright
20:23Chouserso between multi-param apply and multi-seq map, one hardly needs zip at all.
20:25rhickeyright
23:11ChouserIt's even better than that. I wanted zip so I could do this: (def prod (map (fn [seq] (apply * seq)) (zip fracs)))
23:12ChouserBut of course I get the same result with: (def prod (apply map * fracs))
23:12rhickeyfun
23:21Chouserany way to get the denominator of a RatioNum?
23:23rhickeyfor now: (. 22/7 denominator)
23:34Chouserthanks
23:36albinodid the proggit article bring some newbies to the channel today?