#clojure logs

2008-08-22

10:36Chouserdrewr: did you solve your XML problem?
11:00drewrChouser: Yeah, I used the PullParser. It's awesome!
11:00Chouseroh, good!
11:03drewrThanks for pointing me in that direction.
11:03Chouseryou're quite welcome. Once you've used that, it's a bit amazing what a mess the SAX API is, isn't it?
11:15drewrI haven't done any SAX in a while, but I remember it taking me much longer to do something useful.
11:15drewrThis time it might have been the parser, or just Clojure. :-)
11:30Chouser:-)
11:31ChouserYeah, using Clojure and proxy is by far the most pleasant SAX experience I've had.
13:42drewrCan you not destructure a map into its k/v pair?
13:42drewrI thought something like this would work:
13:42drewr(let [{k v} {:foo :bar}] [k v]) => [:foo :bar]
13:43drewrI should say a map *entry*.
13:53shoover1map binding forms are intended to pull out values when you specify the keys. to get keys you would have to call seq on the map and then use vector binding forms like (let [[pair] (seq {:foo :bar})] pair)
14:02drewrIn this case, I don't know what the keys are.
14:03drewr(map (fn [{k v}] v) {:foo 1 :bar 2 :baz 3}) => [1 2 3]
14:03drewrThat's the behavior I want to mimic.
14:03drewrObviously, there I could use (vals ...), but I'm focusing on the destructuring in the fn.
14:11shooverDo you care what the keys are? If so it seems like you can get the pairs pretty cleanly with (seq {...}). If not, (vals ...) supports first, second, nth, rest, and so on.
14:11shooverEither of those cases would support the sequence functions or further vector destructuring
14:13Chouseryes, you can destructure maps.
14:14Chouser(let [{f1 :foo, b1 :bar} {:foo 1, :bar 2}] (list f1 b1))
14:14drewrChouser: I don't know the keys are :foo and :bar.
14:14Chouseroh ... you want all the values?
14:15drewrI really want the key and value out of a map entry.
14:15Chouserhow would you know which value goes with which key?
14:15Chouserout of a single entry?
14:15drewrYes.
14:16ChouserSo like (def e (first {:foo 1})), and you want to destructure e?
14:16drewrYes.
14:16Chouser(let [[k v] e] (list k v))
14:17drewrI was trying that on a map, not a map entry. Whoops.
14:17drewrThanks.
14:18drewrI was wondering why I wasn't getting a vec.
14:19Chouser:-) np.
14:20drewrIs there a built-in function which recursively takes a PersistentMap and will convert them to java.util.HashMaps?
14:21drewrI'd give an example but I'm not sure how to express a HashMap symbolically.
14:21ChouserI don't even think there's one that does it for the first level.
14:22drewrI've built up a database record which ends up being a map that can have other maps as values.
14:22ChouserI think that came up on the forum recently -- a couple examples of copying into a java Map, and one that wrapped the PersistentMap in a proxy.
14:22drewrI need to normalize that to standard Java collections so I can talk to some other APIs.
14:22drewrOK, I'll check the list.
14:23Chousersounds like you're in for some "reduce" fun, or maybe into+recur or something.
14:24drewrYup :-)
16:05lisppaste8DrewR pasted "PersistentHashMap to HashMap" at http://paste.lisp.org/display/65710
16:07Chouser(instance? clojure.lang.PersistentArrayMap v)
16:08Chouserlooks good, though.
16:09Chouseryou get a call stack as deep as your maps are nested.
16:14drewrI'm assuming the nesting won't be but 2 or 3 levels.
16:14Chousersure
16:15ChouserThe maps would have to be nested to a pretty masachistic depth for it to be a problem.
16:16drewrI'm doing this to get stuff into JSON. It seems to be working well.
16:17Chouserusing some stock Java JSON writer?
16:17ChouserI think someone mentioned writing a JSON writer on the forum, but I don't remember seeing any code.
16:20drewrThe lib I'm using on top of net.sf.json.JSONObject can take a java.util.Map to populate the record.
17:46ozzileeCan someone tell me why I get an UnsupportedOperationError: foo with this genclass code?
17:46ozzileeSorry, "UnsupportedOperationError: bar".
17:47ozzileeEr, rather: "Exception in thread "main" java.lang.UnsupportedOperationException: bar"
17:47ozzileeThere :-)
17:48Chousercan you paste your genclass code?
17:48lisppaste8ozzilee pasted "genclass problem" at http://paste.lisp.org/display/65714
17:49ozzileeHeh sorry, forgot to hit the paste button.
17:49ozzileeIt's friday.
17:50lisppaste8ozzilee annotated #65714 with "Should take [this], no help though" at http://paste.lisp.org/display/65714#1
17:51Chouseryeah, that was my first attempt. :-/
17:52ozzileeWhat did I do wrong?
17:53ozzileeOh, nm, you meant adding [this] was your first attempt.
17:53Chouseryeah, sorry.
17:54ChouserWell, bar is definitly a method of the class, as indicated both by the error and reflection.
17:55ozzileeYeah. I looked in the genclass source, but it throws the same exception in a few different places, so I'd have to make some changes to figure out exactly where it comes from.
17:55ozzileeAlso, 200-line functions hurt my brain.
17:59ChouserIt's acting like Foo-bar is misnamed.
18:01ozzileeAh, found it.
18:01ozzilee(in-ns 'com.ozzilee.Foo) should be (in-ns 'com.ozzilee)
18:03ozzileeThanks for the help.
18:03Chouserah -- beat me
18:03Chouserby 2 minutes.
18:03Chouser:-)
18:03ozzileeHeh. I copied the example from the source and started working backwards.
18:04ChouserI started adding debugging output to genclass and worked forward. Inferior.
18:05ozzileeHeh. Well it's 5:00 and I'm already overtime for the week, I'm going to take off. Thanks again.
21:07ozzileeIs there a way to define a function when you don't know the name of the function until run-time?
21:11drewrWhy can't you use an anonymous fn?
21:12ozzileeI'm using genclass to create a class with a gensym'd name.
21:13ozzileeFrom what I understand the only way to create the methods for the class are with defn's.
21:13drewrI haven't used genclass enough.
21:17ozzileeHmm, I'll have to rethink my approach.
22:07ozzileeAnyone know how to call a super method from a genclass'd method?