#clojure log - Feb 13 2008

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

4:21 jgracin: guys, 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:41 hi! 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:42 rhickey: (meta (var vector)) or ^#'vector

15:43 jgracin: Oh, of course. Vars have meta-data. Thanks!

15:44 rhickey: sure

16:06 Chouser: Thanks for the nice article on your blog

16:07 http://n01senet.blogspot.com/2008/02/clojure-is-best-lisp-yet.html for those who haven't seen it

16:08 Chouser: rhickey: heh. sure! how'd you find that?

16:08 oh, I bet a standing Google search for "clojure".

16:08 rhickey: yup

16:11 Chouser: well, you're quite welcome, though I'm not sure it's worth much. I'm not exactly an opinion leader. :-)

16:11 I should be, but I'm not.

16:14 jgracin: Chouser: would you mind if I "reddit"-ed your blog? :-)

16:14 I think Clojure needs advertising now.

16:15 Chouser: jgracin: I can't think of why I'd mind, so go right ahead.

16:16 any obvious factual errors I should fix first? rhickey?

16:17 rhickey: no, I thought it was ok

16:21 jgracin: done.

16:22 rhickey: new release today, so good timing. Lots of updated docs on the site

16:25 Chouser: The "lisp worth talking about" from reddit a couple months ago is a better article. oh well.

16:27 jgracin: rhickey: yeah. I am amazed how things in and around Clojure keep fitting perfectly.

16:27 you've struck gold. :-)

16:28 rhickey: :)

16:31 Chouser: I 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:32 rhickey: identity == (fn [x] x)

16:39 * Chouser inserts (defn filtermap [f s] (filter identity (map f s)))

17:45 Chouser: any handy way to go from '((1 2) (3 4) (5 6)) to '((1 3 5) (2 4 6)) ?

17:45 some languages call this "zip"

17:52 (defn zip [& args] (if (first args) (cons (map first args) (apply zip (map rest args))) nil))

17:58 That's not what I wanted. This is closer: (defn zip [seq] (if (first seq) (cons (map first seq) (zip (map rest seq))) nil))

18:05 rhickey: neat. I think going that direction it's unzip

18:06 hmmm, maybe they're the same once they are variadic...

18:07 Chouser: I have a tail-recursive version, but it has to call reverse at the end. Is that any better?

18:08 rhickey: I don't think there's anything wrong with the map version

18:10 Chouser: oh, this one still uses map, but it uses recur instead of creating a stack as deep as (count (first seq))

18:13 rhickey: (def zip (partial apply map list))

18:13 Chouser: http://n01se.net/paste/ijK

18:13 whoa, what?

18:13 rhickey: try it

18:14 Chouser: I don't have partial. Is my clojure too old?

18:14 rhickey: yes, was appl then

18:15 Chouser: again, "whoa".

18:15 Ok, I need to get food, but I'll have to look at that def.

18:24 rhickey: it's lazy: (take 5 (zip (list (iterate inc 1) (iterate inc 2) (iterate inc 3))))

18:24 ((1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7))

19:01 Chouser: I'm still not fully there. I don't yet understand what apply is doing with the 3rd arg.

19:17 rhickey: you mean mapping the list function?

19:18 user=> (map list [1 2 3] [4 5 6] [7 8 9])

19:18 ((1 4 7) (2 5 8) (3 6 9))

19:19 which is almost what you want, but your lists are in a sequence

19:19 user=> (apply map list [[1 2 3] [4 5 6] [7 8 9]])

19:19 ((1 4 7) (2 5 8) (3 6 9))

19:47 Chouser: oh, it's the multiple sequences to map that's doing it.

19:54 the multiple args to apply was throwing me as well, though.

19:56 I didn't realize (apply + 1 2 '(3 4)) was like (apply + (list* 1 2 '(3 4)))

20:00 rhickey: right

20:23 Chouser: so between multi-param apply and multi-seq map, one hardly needs zip at all.

20:25 rhickey: right

23:11 Chouser: It's even better than that. I wanted zip so I could do this: (def prod (map (fn [seq] (apply * seq)) (zip fracs)))

23:12 But of course I get the same result with: (def prod (apply map * fracs))

23:12 rhickey: fun

23:21 Chouser: any way to get the denominator of a RatioNum?

23:23 rhickey: for now: (. 22/7 denominator)

23:34 Chouser: thanks

23:36 albino: did the proggit article bring some newbies to the channel today?

Logging service provided by n01se.net