#clojure logs

2008-08-02

08:04rhickeyanyone want to take a crack at multimethodizing RT.print? I've made (class nil) -> nil
12:52mathiasevening!
12:53madadoes anyone know if there is some equivalent of CL's ASSOC in clojure?
12:53madaI have a list of two-element lists and want to find one who's first element is X
12:54madaright now I am looping through the list, which seems a bit ugly
12:55kotarakmada: maybe you can something like: (filter (fn [[x _]] (= x X)) two-element-list)
12:56madayes, I thought abt using filter but that seemed almost as ugly :) thanks for the hint though
12:56kotarakmada: why not using a map in the first place?
12:56madaI don't understand
12:57madalet me show u the data I got
12:57mada{:columns (("TITLE_ID" "java.lang.Integer") ("ENTRY_DATE" "java.sql.Timestamp") ("NAME" "java.lang.String"))}
12:57madathat is meta data from a db query
12:57kotarakoh ok.
12:57madaand I want to want to find out...
12:57kotarakNever mind. So the form of the data is not for discussion
12:57madahmm... no I don't :)
12:58madacorrect
12:58madaI cannot control it (actualy I am lying but I am too lazy to change that piece of code that returns the meta data :)
12:59madakotarak: what's that strange syntax with the underscore?
13:00mada(I haven't read the full docs)
13:00kotarakmada: no syntax at all, I use it for things like function arguments which can be ignored. (Relic from my ML experiments)
13:01madaah
13:01madanow I grokked it :)
13:01kotarakmada: (fn [x _] x) <- a function taking two arguments, but I don't use the second one
13:01madayes
13:01madaclever
13:02kotarakThat is not enforced by Clojure. Just a matter of taste.
13:02madaic
13:04kotarakmada: for your original question: you could transform the list into a map: (apply hash-map (apply concat two-element-list))
13:05kotarakthen you access: (map-variable "TITLE_ID")
13:05madacool!
13:05madaworks too :)
13:06madaso hash-map works on pairs of element
13:06madas
13:06kotarakThen also the assoc, dissoc, get etc. stuff of Clojure works for your data.
13:07madaok. I don't need those in this case though.
13:07kotarakhash-map creates the equivalent of associated-lists. But probably faster and easier to use, etc.
13:07madayes, I would guess so.
13:08madaI wonder, would it be a good idea to convert each row I get from a db query into a map instead of using a list with no key names?
13:08madathe rows I get currently are just plain lists with data
13:08madauntagged, so to speak
13:08madaI get the column names as meta data on the result set
13:09madamaking each row into a map would make the rows easy to use when I want to pick out values from them
13:10madaright now I have a function that does that for me, looking at the result set metadata to know what each value in the list is
13:11madaI will experiment with it and see.
13:11kotarakI don't know. I have no clue about DBs. As long as it is fast enough... Who cares? I would probably go for the map, since you get some support in assoc, dissoc etc. and check for something else of this is too slow.
13:13madawill look into it and do some experiments. thanks for the ideas!
14:10madahaha!
14:11kotarakhihi?
14:11madakotarak: I succeeded in doing what I wanted only to discover it was already in clojure as `resultset-seq' :)
14:11kotarakmada: nice :)
17:31ozzileeHey all, I've come across what I think might be common code pattern, but I'm not sure what it would be called, I was wondering if someone knows.
17:31ozzileeI've got a function, foo, that relies on an object (Java, in this case), bar.
17:32ozzileebar isn't available all of the time. When I call (foo x y z) and bar is available, I'd like to to go ahead and run, but if I call it when bar is not available, I'd like it to just remember what I called it with for when bar becomes available again.
17:33ozzileeDoes anyone know what that would be called? Perhaps common lisp has a macro for it?
17:46drewrWhat do you mean by availability?
17:47drewrWhether it's defined or not?
17:50ozzileedrewr: Well, the case I'm working on now is a Bayeux object, that's not around until after Jetty is initialized.
17:50ozzileeBayeux is an Ajax/Comet thing.
17:51ozzileeI want to be able to subscribe to channels before Jetty is initialized, which means I need to remember what channels I tried to subscribe to and then subscribe after initialization.
17:53ozzileeIt could work on whether or not a variable is defined, I suppose. I could just define it after Jetty initializes.