#clojure logs

2008-08-13

06:31StartsWithKwhat should *use-context-classloader* do?
06:49ChouserStartsWithK: http://groups.google.com/group/clojure/msg/7d4fee85f7fc4cd4
06:50StartsWithKi did set it to true, nothing happened, but i am not using proxy
06:51StartsWithKmy osgi activator is scala (java) and i call clojure from it
06:52StartsWithKfor now i have to do RT.loadResourceScript(getClass, "file.clj") for this to work from inside Activator class
09:10roblally_I'm a little confused about macro's and how they handle literal parameters. Can anyone recommend a good resource?
09:10roblally_Why I wrote "macro's" rather than "macros" is also confusing, I admit.
09:11roblally_(defmacro boink [actual]
09:11roblally_ '(println ~actual))
09:11roblally_
09:11roblally_(println (macroexpand
09:11roblally_ '(boink 2)))
09:11roblally_
09:11drewrroblally_: This is a good intro to the concept of macros: http://gigamonkeys.com/book/macros-defining-your-own.html
09:11roblally_(boink 32)
09:11drewrlisppaste8: url
09:11lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
09:11roblally_Cool
09:12drewrroblally_: Use ^^^^^^^ to paste code.
09:12lisppaste8roblally pasted "Problem macro" at http://paste.lisp.org/display/65263
09:13roblally_Thanks, that's a neat resource.
09:13roblally_I'm confused as to why when I execute that code I see clojure.lang.LispReader objects and not numbers.
09:14drewrroblally_: Switch that quote to a backtick.
09:14drewruser> (defmacro boink [actual] `(println ~actual))
09:14drewrnil
09:14drewruser> (macroexpand-1 '(boink 32))
09:14drewr(clojure/println 32)
09:16roblally_Thank-you so much. I've been banging my head off that for 3 days.
09:16roblally_I shall read the article you linked to.
09:18drewrNote that it's a chapter from a book on Common Lisp, so it's not in any way a tutorial for Clojure macros. It will however give you an idea of how macros differ from functions.
09:19roblally_This explains why I found that I could copy code and edit it and it would be fine, but when I typed it in from scratch ... things didn't work out so well.
09:22drewr:-)
11:43madaevening!
11:44madaTo concat with a space strings in a list, I am doing this: (apply str (map (fn [x] (str x " ")) '("foo" "bar")))
11:45kotarakmada: (apply str (interpose " " (list "foo" "bar"))) is also possible, though I don't know the argument limit things like str.
11:48ChouserI think there is no argument limit
11:49madait seems to work
11:49madaso there is nothing like `mapconcat' in clojure?
11:49madaI had a look at `mapcat' but did not understand how to use it.
11:51Chousermapcat is good when your map function always returns a seq, and you want to flatten tham out
11:51kotarakThere was a question on the list about reversing the keys and values of map. This can be done with mapcat: (apply hash-map (mapcat (fn [[k v]] [v k]) m). The anonymous fn return a list of vectors. mapcat flattens this into list.
11:52Chouseruser=> (map #(range 0 %) [3 1 4])
11:52Chouser((0 1 2) (0) (0 1 2 3))
11:52Chouseruser=> (mapcat #(range 0 %) [3 1 4])
11:52Chouser(0 1 2 0 0 1 2 3)
11:52Chouserkotarak: ah, a much more useful example.
11:54kotarakChouser: :) Rich did this with reduce, so I wondered whether there is some limit for apply or some other issue (eg. with performance)
11:55ChouserI've not ever heard him speak badly of apply for large arg lists.
11:57madareduce worked as well for me: (reduce (fn [x y] (str x " " y)) '("foo" "bar"))
11:57madafirst time I used reduce :)
11:58kotarakmany ways to Rome I guess. :)
11:58madayes, which is good I guess
11:58madaI am fiddling with webjure and doing some small web apps
11:59kotarakah. Sometimes yes, sometimes no... I depends on the situation.
12:01Chouser(defn arg1 [a & r] a)
12:01Chouser(apply arg1 \a \b \c (repeatedly \x))
12:02Chouserargument lists are a lazy seq, so there shouldn't be any limit.
12:28madaChouser: haha, I just got use for `mapcat' :)
12:28madareplaced some ugly workaround with it
12:30madaif I am mapping over a list, is there anyway to know when the last item is being processed so that I can handle it differently?
12:30madaI have this code:
12:30mada~@(mapcat (fn [x] `((:a {:href ~(str (url "/list") "tag=" x)} ~x) ", "))
12:30mada (get-file-tags name))
12:31madaand I don't want the ", " to be generated for the last item in the list
12:32madaI assume it is not possible and that I need another approach if I want to do this. Now I am using " " instead, and the extra space is not visible to the user, so it works.
12:38kotarakmada: (apply concat (interpose (list ",") (map (fn [x] (list :a {:href (str (url "/list") "tag=" x)} x)), does this help?
12:41madaah, interpose only puts stuff inbetween... clever!
12:42mada(interpose "x" "APA")
12:42madaoops, not the REPL :)
12:43madait worked on a string as well though
12:44drewrChouser: I remember when you and rhickey were talking a lot about xml support. I need to parse a large document and I'm wondering if startparse-sax is good for production use.
12:46Chouserdrewr: I assume Java's SAX parser is good enough, but the existing xml.clj will load the whole document into memory as a tree of hashes and vectors before returning it to you.
12:46drewrOK, that's what the code was leading me to believe but I thought I was missing something.
12:47ChouserI've got a lazy-xml.clj thing going, but for you use it has a couple problems:
12:47Chouser1. not quite perfect -- I haven't released it because it's got a couple problems with namespace handling
12:48Chouser2. not well tested yet -- since only I've been beating on it, it would stretch anyone's definition of "good for production use".
12:48drewrI can just wrap SAXParser for my needs, unless you'd like me to pound on your code.
12:48ChouserIt's really close though. It uses a 3rd party pull parser when available, which fits very nicely with Clojure's lazy seqs.
12:50Chouserdrewr: well, I guess it's up to you. I can show you what I've got. If you think it's close enough to what you want, I can patch up the known holes and we can see how it goes.
12:50Chouserwhat kind of "processing" do you plan? have you looked at all at my zip-filter query stuff?
12:51drewrNo I haven't. Basically just taking a large feed, munging the data a little, and stuffing it into a db.
12:53Chouseroh, ok. Well...
12:53Chouserseems likely using sax directly would be a good bet. Although I really would recommend a pull parser.
12:54Chouserhttp://www.extreme.indiana.edu/xgws/xsoap/xpp/
12:54ChouserThe API is so much better than SAX
12:54drewrInteresting.
12:59Chouseryep. No need for a subclass of anything (proxy), and it's easy to wrap in such a way that you can return a lazy seq.
12:59Chouserplus it may be faster at runtime.
13:00Chouserthe lazy seq thing is huge for me -- doing that with SAX is impossible as far as I can tell, without resorting to coordinating threads.
17:56arohnergrr.
17:56arohner(. clojure.lang.RT (loadResourceScript "clojure-contrib/lib/lib.clj"))
17:56arohnernil
17:56arohneruser=> (clojure/refer 'clojure-contrib.lib)
17:56arohnerjava.lang.Exception: No namespace: clojure-contrib.lib
17:57Chouserclojure.contrib.lib
17:57arohnerser=> (. clojure.lang.RT (loadResourceScript "clojure.contrib/lib/lib.clj"))
17:57arohnerjava.io.FileNotFoundException: Could not locate Clojure resource on classpath: clojure.contrib/lib/lib.clj
17:58arohnermy clojure-contrib directory is in ./lib/clojure-contrib
17:58Chouserheh
17:58arohnerbut since the loadResourceScript worked, why did the refer fail?
17:58Chouserthe load was correct. the namespace as given to refer should use . not -
17:59ChouserIt'll be good when lib.clj is builtin.
17:59arohneroh, ok
17:59arohnerthanks for the help :-)
17:59Chouser:-) sure. It's confusing, I know.
17:59arohneryeah, it will be nice when that's built in
18:46arohnerdoes anyone here have svn access to clojure-contrib?
18:46arohnerI'd like to fix the library namespace thing for seq-utils
18:47Chouserit looks like it already is.
18:47Chouserseq_utils/seq_utils.clj
18:48arohneroh, I'm blind
18:48Chouserno, it's confusing -- there are two versions of several of the libs there.
20:06arohnerdoes loadResourceScript screw with your line numbers?
20:06Chouserno
20:06arohnermacros?
20:06Chousermacros sometime report bad line numbers in stack traces.
20:07arohnermaybe that's it
20:07Chouseror I think perhaps the right line number of the wrong file
20:07arohnerI have a file that's about 10 lines long. the stack trace says line 364
20:07Chouseryeah, macros
20:07arohneris there a way to macroexpand a file?
20:08Chouserthat's a great question -- I'm not sure
20:09arohnerI'm googling now to see if CL has that
20:09arohnerit seems like it should be useful, but i don't remember hearing about it before
20:11arohneremacs has macroexpand-all which recursively expands everything in a form (rather than just the top level)
20:15Chouseryeah, that'd be instructive in itself, and then pretty trivial to apply to a whole file.
20:20arohnerthe other question I have is, why doesn't anyone else have this?
20:20arohneris there something about their environment that makes it not necessary?
20:21arohneri.e. their stack traces don't present weird numbers?
20:21Chouserthat makes what not necessary?
20:21Chouseroh, no, everybody sees those weird numbers.
20:21ChouserI just use the rest of the stack trace to figure out what's going wrong.
20:22arohnerI mean other lisps
20:22arohneris this not an issue in CL?
20:23Chouseroh! yeah, I think this is a specific interaction between the way Clojure implements macros and the way Java annotates bytecode to indicate file and line numbers.
20:23ChouserI haven't gotten the impression from Rich that it would necessarily be impossible to fix, but maybe pretty hard and not worth it just yet.
20:25slavayou need an s-exp data type distinct from a cons which stores file and line number information
20:25Chouserthe file and line numbers are already stored in each var
20:26arohnerbut they're stored after macroexpansion
20:28arohnerok, here's another one
20:28arohnermy exception is getting cut off
20:28arohneris there a way to make java print the whole thing?
20:28arohnerCaused by: java.lang.Exception: No such namespace: compojure
20:28arohner at clojure.lang.Compiler.resolveIn(Compiler.java:3950)
20:28arohner at clojure.lang.Compiler.resolve(Compiler.java:3928)
20:28arohner at clojure.lang.Compiler.analyzeSymbol(Compiler.java:3911)
20:28arohner at clojure.lang.Compiler.analyze(Compiler.java:3642)
20:28arohner ... 60 more
20:28arohnerClojure
20:29arohnerwhen I grep for .clj, the only reference is after my 10 line file is at line 164
20:29arohnerI think there might be something useful in that 60 more
20:29Chouseroh, that's a compiler exception -- not runtime.
20:29Chouserit suggests an exception is being thrown from inside a macro
20:39arohnergrr. why does java just decide "oh, you don't need the rest of that stack trace"?
20:39arohnerI don't see a method to change that either
20:39ChouserI think there's a command-line option
20:40Chouserhm, maybe not.
20:41Chouserarohner: want to paste your whole .clj and whole stack trace?
20:41arohnersure
20:41Chousernot inline here of course.
20:42arohnerI'm just modifying compojure to work with recent clojure and clojure-contrib versions
20:42Chouseroh. ouch.
20:42arohnerwhat's the paste url?
20:42Chouserlisppaste8: url
20:42lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
20:43Chouserthere's a more recent framework mentioned on the forum. dunno if it would match your taste or not
20:43arohnerAFAIK, compojure was the recent one
20:43arohnerwebjure was the older one
20:43lisppaste8arohner pasted "stacktrace" at http://paste.lisp.org/display/65294
20:44Chouseroh, of course you're right. sorry.
20:44arohnercompojure shipped its own clojure.jar and clojure-contrib, and hadn't updated since the new source organization post
20:46Chouserwhat SVN version of clojure are you using?
20:46arohner996
20:47arohner999 now
20:49Chouserstill boot.clj:147: No such namespace: compojure ?
20:50arohneryup
20:50arohnerstack trace looks the same
20:51Chousermaybe try :verbose on the use call, so you can then try each of its steps manually?
20:53arohnerah, that helped a lot
20:53arohner(clojure/in-ns 'user)
20:53arohner(clojure/refer 'compojure.json)
20:53arohner(clojure.contrib.lib/load-resource "file:/Users/arohner/Programming/clojure/compojure/lib/compojure/persist/persist.clj")
20:53arohner2008-08-14 00:01:42.166::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
20:53arohnerclojure.lang.Compiler$CompilerException: boot.clj:147: No such namespace: compojure
20:53arohner at clojure.lang.Compiler.analyze(Compiler.java:3669)
20:53arohner at clojure.lang.Compiler.analyze(Compiler.java:3627)
20:53arohner at clojure.lang.Compiler.access$100(Compiler.java:37)
20:53arohner at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2626)
20:53arohnersorry, I need to get used to using paste
21:02arohnertime for bed
21:02Chouserindeed. later!
21:02arohnerthanks for the help Chouser