#clojure logs

2008-04-04

03:17cgrandchouser: I put ClojureServlet.war in the group's file section.
09:45Chousercgrand: thanks!
10:00cgrandchouser: rich was right about minimalism, even binding *out* to the response's writer is bad (it commits the encoding...)
10:00ChouserHm.
10:01rhickeycgrand: thanks for posting that, perhaps a message in the group too...
10:01rhickeyI was just looking at the source, yes, it could do a lot less. The easy-mode stuff could happen in Clojure
10:02cgrandrhickey: easy-mode was added as an efter-thought (when I realized that I had already paint myself in a corner with binding *out*)
10:03rhickeyeasy-dispatch?
10:05cgrandrhickey: checking which of easy-dispatch or dispatch is set to reduce the need to modifiy web.xml?
10:10rhickeywhat I imagine is that people take Clojure (once it has the stub), modify web.xml to point to their dispatch function, and go. easy-dispatch is something they can use in their dispatch function. A library supplying stream binding, url decoding and dispatch could come with a web.xml pre-configured?
10:11ChouserWhat does "Bad version number in .class file" mean?
10:12cgrandchouser: I compiled with JDK 6...
10:12rhickeyusing something built for one version of Java with a different (previous) version
10:12Chouserok
10:13rhickeycgrand: you could still target Java 1.5 with that
10:16cgrandrhickey: I know I had set them but apparently to no avail. Still, the project properties page says: "Compiler compliance level 5.0" and "generated .class files compatibility: 5.0". ..
10:17cgrandrhickey: ok I remove features from ClojureServlet
10:20rhickeycgrand: A minimal version would be a welcome addition to Clojure. I think the one question I have is about where scripts go - hardwiring to / (e.g. loadResourceScript) seems rigid
10:23cgrandrhichey: it's juste the "boot" script of the webapp whose location is somewhat rigid. Once in the webapp's bootscript the user can call load to source any script. No ?
10:23rhickeycgrand: if you do Symbol.intern(dispatchFunctionName) it will pluck out the ns/name for you
10:25cgrandrhickey: thanks
10:26rhickeycgrand: yeah, I see, that's fine, as long as they don't have to rebuild clojure.jar, but I see the boot clj is in the war/classes
10:27rhickeyi.e. web boot script
10:28Chousercgrand: I have it running in my tomcat server. Thanks!
10:29cgrandchouser: you're welcome
10:30Chousernot yet!
10:30Chouser;-)
10:31ChouserWhen I can run them on my DreamHost server, then I can start thinkging about liking them.
10:33ChouserI used that class inheritence chart yesterday to determine that I wanted to be using sequential? instead of coll?
11:19nsinghal_rich i am trying to do the remote repl and getting parse error from read
11:19nsinghal_java.lang.Exception: ReaderError:(22,1) No value supplied for key: Equality. Returns true if obj1 equals obj2, false if not. Same as
11:19nsinghal_ Java obj1.equals(obj2) except it also works for nil, and compares
11:19nsinghal_ numbers in a type-independent manner. Clojure's immutable data
11:19nsinghal_ structures define equals() (and thus =) as a value, not an identity,
11:19nsinghal_ comparison.
11:19nsinghal_ at clojure.lang.LispReader.read(LispReader.java:158)
11:20nsinghal_ at clojure.fns.clojure.read__425.invoke(boot.clj:1371)
11:36rhickey_nsinghal: you are reading a mal-formed map
11:43nsinghal_I have this functions
11:43nsinghal_defn get-syms [ns]
11:43nsinghal_ (loop [syms (sort-by key (ns-publics ns))
11:43nsinghal_ ret (sorted-map)]
11:43nsinghal_ (let [sym (first syms)]
11:43nsinghal_ (if sym
11:43nsinghal_ (recur (rest syms)
11:43nsinghal_ (assoc ret (str (key sym)) (dissoc ^(val sym) :arglists :name :ns)))
11:43nsinghal_ ret))))
11:43nsinghal_(defn get-tree []
11:43nsinghal_ (loop [nss (sort-by ns-name (all-ns))
11:43nsinghal_ ret (sorted-map)]
11:43nsinghal_ (let [ns (first nss)]
11:44nsinghal_ (if ns
11:44nsinghal_ (recur (rest nss)
11:44nsinghal_ (assoc ret (str (ns-name ns)) (get-syms ns)))
11:44nsinghal_ ret))))
11:44nsinghal_f i change the (get-tree) function to use (take 2 (all-ns)) instead of (all-ns) then it works and i get back an object from the read. In the (take 2 ), I am not getting the clojure namespace and hence it must be working.
11:44nsinghal_when i read after the parsing error i am getting the rest of the string as follows
11:45nsinghal_, "==" {:file "boot.clj", :line 530, :doc "Returns non-nil if nums all have the same value, otherwise false"}, ">" {:file "boot.clj", :line 506, :doc "Returns non-nil if nums are in monotonically decreasing order,\n otherwise false."}, ">=" {:file "boot.clj", :line 518, :doc "Returns non-nil if nums are in monotonically non-increasing order,\n otherwise false."}, "accessor" {:file "boot.clj", :line 1643, :doc "Returns a fn that, give
11:45rhickey_ns: this is too much code for here, use http://paste.lisp.org/ or something
11:46nsinghal_let me try that - sorry i knew this is too much code - but didnt know how to create a link or something
11:48nsinghal_what channel should i put it on - i dont see #clojure channel there
11:49rhickey_just paste with no channel and put the link here manually
11:50nsinghal_http://paste.lisp.org/display/58600
11:50nsinghal_this is a very nice way top do it.
11:53rhickey_ns: can't you just run the commands locally, or using a straight repl to the remote instance, look at the output and determine it's readability?
11:53rhickey_its
11:54rhickey_ns: the 'map' has "Equality. Returns true ...'" in a key position, if that helps
11:56nsinghal_i run locally and i get a clojure.lang.PersistentTreeMap - and its working. I will check may be because of some doc string, i might be getting this
11:56rhickey_ns: it is a doc string, search for it in boot.clj
12:13cgrandrhickey_, chouser: new war uploaded.
12:16cgrandchouser: your "Bad version number in .class file" was caused by the clojure.jar being compiled with jdk 6 (fixed now)...
12:42Chousercgrand: oh, ok, thanks.
12:43Chouseractually, I don't know why I was using 1.5. I have 1.6 installed, and it seems to work fine.
14:48Chouserdrat. I've got an error in the design of the zip-filter API.
14:52abrooksChouser: What's the issue?
14:53Chouserabrooks: thanks for caring... ;-)
14:54ChouserThe problem is I want [:table :tr] to match a <tr> inside a <table>. This implies navigating "down" either before or after a matching tag.
14:54ericthorsenrich: Is there a way to query clojure for a version?
14:54Chouser..as in either after :table, or before :tr
14:56rhickeyeric: no
14:56ericthorsenany plans for this?
14:56rhickeynot sure - what's a version
14:57ericthorsencould just be a change list id as far as i need....a point in time
14:58ericthorsenlike a build number
14:59rhickeyit could be the svn rev, but I'd need a really convenient way to capture that and embed it in the build, not interested in manually doing anything
14:59ericthorsentotally...that would be expected and desired
14:59abrooksPerhaps the command "svnversion" could be used to show (for svn checkouts) the working copy version and state (including modifications).
15:00abrooksThe "perhaps" is somewhat conditional on what ant/maven can do at build time (I've never really used either) and what you would do for the case where the build tree is not an svn working copy (i.e. a tarball or svn export).
15:02abrooksAn svn exported tree could provide an svn:keywords "Id" in some file (which would cover the tarball case).
15:02abrooksActualy, probably "Rev" not "Id"... habbit caught me there.
15:06Chouserabrooks: but I also want [:table #(attr % :id)] to match the id of the table, which means I can't navigate down *after* the :table. Therefore I must navigate down before.
15:06abrooksFricking stupid Subversion. I forgot again. "Rev" is always the revision of the file modification. It only gets updated when you update that file.
15:07Chouserthis is what I've been doing, and it's been fine.
15:08ChouserBut now I'm adding predicates for navigating up or sideways, so I can do, for example [:div ancestors :table]
15:10abrooksChouser: Does "ancestors" have a recognizable type?
15:10ChouserIn that case I mean I want to find every <table> that is an ancestor of a <div>. But since I'm auto-navigating down before tags, I get all <table>s that are children of anything with <div> as a descendent.
15:10Chouserabrooks: it's just a function.
15:11Chouserso one solution would be to get rid of auto-nav, and use something like / to mean "expand down" (like xpath does)
15:12Chouserbut then you get [:table / :tr / :td / :div]
15:12abrooksEw.
15:12abrooksIs it the case that not auto-nav is the common case?
15:13Chouserright. ew. But at least [:div ancestors :table] and [:table #(attr % :id)] to work as expected
15:13abrooksWhat about a "here" designator
15:13abrooks[:table :tr :td . :div]
15:13Chouserwell, I think with chains of tag names, auto-nav down is common. Everywhere else, you probably want no auto-nav.
15:14ChouserIf that's true, I could try to allow a function to return something that means "nav down if the next function also tells you too"
15:15ChouserThe implementation would be problematic (use meta-data??) and I'm worried it would be to "magical" and hard to understand.
15:15abrooksI really need to play with zip-filter. I've only glanced at it as I've been tearing through Project Euler problems. :)
15:15Chouseryeah, it won't help you much there, probably.
15:15abrooksHeh. No, likely not.
15:15Chouserdon't worry, nobody else has looked at it either. Well, rhickey did, but he was just humoring me.
15:16Chouserok, well, I'll go away and ponder this, and stop spamming the channel.
15:31MarkJPwhat part of the following is the actual java class name:
15:31MarkJP#<Var: user/foo>
15:31MarkJPuser=> foo
15:31MarkJPclojure.fns.user.foo__1292@1145cc
15:32MarkJPsorry: (defn foo [] "asdf")
15:32MarkJPwhat part of clojure.fns.user.foo__1292@1145cc
15:32rhickeyclojure.fns.user is the package, foo__1292 is the class name
15:32MarkJPthx
16:45MarkJP(defn char? [x] (instance? java.lang.Character x))
16:49rhickeymarkjp: ok?
16:49MarkJPoh, just something I thought might be usefull in boot.clj?
16:50rhickeyok
17:28ericthorsenericthorsen: Rich: if i have a list of 2 item vectors what is the idomatic way to make that a hash-map?
17:28ericthorsen[5:27pm] ericthorsen: (apply hash-map (apply concat '([] [] [] [] [])))
17:28ericthorsen?
17:34Chouserericthorsen: I've been doing that some recently.
17:34ericthorsenthe same solution?
17:34ChouserThis is the best I've got: (reduce (fn [m [k v]] (assoc m k v)) {} '([] [] []))
17:35Chouserhm, I think yours is better.
17:35Chouseroh, mine used to doctor the key on it's way through.
17:36Chouser(reduce (fn [m [k v]] (assoc m (keyword k) v)) {} '([] [] []))
17:44ericthorsenthx...i'll take a look
17:49Chouserwell, I didn't really answer your question. Seems like a common case for which there should be a succinct solution.
18:07abrooksericthorsen, Chouser: Funny, I've been stumbling around trying to find a good way to do the same. At least now I don't feel so dumb. I used ericthorsen's approach but felt like I was still missing something.
18:13ericthorsensince this is how map entries print it does seem too much typing for that
18:14ericthorsenof-course there is always (defn to-map [v] (apply hash-map (apply concat v)))
18:14ericthorsenmaybe i'm just getting too lazy?
18:18abrooksThis excercise did make me think about "flatten" and "fold" functions. (flatten ((1 2) (3 4) (5 6)) -> (1 2 3 4 5 6), (fold 3 (1 2 3 4 5 6)) -> ((1 2 3) (4 5 6)). Both functions could be generally useful I think.
18:19Chouserfold is called reduce
18:19ericthorsenyup
18:19abrooks(flatten looks like concat but it would recurse to depth -- my example didn't show that.)
18:19Chouseroh, what?
18:19ChouserScala's fold is called reduce.
18:20ericthorsenthinking the same...although it's hard for me to believe Rich did not have that on his radar....might be a simple thing we are missing?
18:20abrooksAh. Clojure's reduce only operates on two items, right?
18:21Chouserno, 2 or 3
18:21abrooksOh?
18:21Chouserwhat does the 3 in your foold example mean?
18:21abrookstake 3 items.
18:22ericthorsen(reduce concat [] [[1 2] [1 2]])
18:22ericthorsentold you it was probably there
18:22ericthorsennow that can be applied to a hash-map
18:23ericthorsenfeels cleaner
18:23ericthorsenwhat do you think?
18:23abrooksericthorsen: Much better. :)
18:23Chouser(split-at 3 '(1 2 3 4 5 6))
18:24Chouserhow is that reduce better than apply concat?
18:25ericthorsengood question
18:25ericthorsen(apply hash-map (reduce concat [] [[1 2] [5 2]]))
18:25ericthorsennot much less typing is it?
18:26ericthorseni gotta run...catch up with you guys later...thx
18:26abrooksChouser: split-at only splits once. I'd want (fold 3 '(1 2 3 4 5 6 7 8 9)) -> ((1 2 3)(4 5 6)(7 8 9)). I'd tried split-at before.
18:32rhickeyuser=> (reduce conj {} '([:a 1] [:b 2] [:c 3]))
18:32rhickey{:a 1, :c 3, :b 2}
18:32abrooksNow that "!" is reclaimed perhaps it could be an alias for "apply".
18:32abrooksAh, there is a better way. Thanks, rhickey.
18:36abrooksI'm not sure how I missed the optional reduce val.
18:38rhickeyit's a key data-structure-building idiom for Clojure, needs to be better known
18:44drewrI'm trying a simple contrived example to try and get my head around lazy sequences. http://paste.lisp.org/display/58623
18:44drewrHow do I lazy-cons something up that wraps (matches m) in a seq?
18:44drewrI'd like to do something like:
18:45rhickey(re-seq #"a+" "foo bar baaz baaaz baaaaz")
18:45rhickey("a" "aa" "aaa" "aaaa")
18:45drewr(reduce conj [] (.... matches of m ... ))
18:46drewrHaha. Well, it's builtin.
18:46rhickeylook at the def of re-seq to see how to do it yourself
18:46rhickey4 lines
18:47drewrOK.
18:47rhickeylazy-cons is the key to writing your own seqs
18:48drewrGlad I picked an experiment for which there was a canonical implementation already.
19:13drewrrhickey: In re-seq, why do you type-hint re as Pattern when it'll be a string coming in?
21:07gomer-nycHi
21:08ChouserHi!
21:08gomer-nycI see there's an emacs mode for Clojure by Mathias Dahl; wondering whether anybody has managed to darcs get it recently - I'm trying now but my machine cannot connect to the host
21:10gomer-nycOR, is anybody else maybe using a different hook for Emacs?
21:12drewrgomer-nyc: Just set up slime today with http://clojure.codestuffs.com/ and it's really good.
21:15gomer-nyccool, great - I'm gonna give it a whirl
21:17drewrNot as full-featured as CL, but it's a good start.
21:17gomer-nycI'm just getting started with Clojure so I figured I better have SOME editor support :-)
22:34Chouserdrewr: hey, congrats!
22:38drewrIs there any way to suppress most of the stacktrace when an error occurs?
22:38drewrReally just the top line is what I need.
22:43drewrrhickey: Is there a way to suppress all but the first line of a stacktrace?
22:44drewrAll that's really relevant to me is "java.lang.IllegalStateException: Var x is unbound."
22:44rhickeynot yet, there should be
22:44rhickeywith the option to grab the exception after the fact
22:45rhickeydrewr: as to you question re: pattern - #"blah" is a regex pattern
22:45rhickeyyou/your
22:45drewrAlso, and this may be impossible with the JVM, but do you have plans for conditions/restarts.
22:45drewr(Thanks, I saw that in reader.html later.)
22:45rhickeydrewr: no need for conditions/restarts - can build with dynamic function binding
22:46drewrOK.