#clojure logs

2009-04-05

14:25AWizzArdwb Chouser
14:25hiredmanChouser: welcome back
14:25ChouserAWizzArd: thanks!
14:26clojurebotChouser might make night
14:26hiredman~botsnack
14:26clojurebotthanks; that was delicious. (nom nom nom)
14:26Chouserlooks like my poor machine has been failing to log for a few days. :-(
14:26AWizzArdjsankey and hiredman: thanks for these introductions into jetty, tomcat, jboss, j2ee and java beans.
14:26jsankeynp
14:27jsankeyfwiw, i'm a happy Jetty user - I would recommend it if you need a servlet container
14:36duck1123can jetty be run as a service?
14:36duck1123that's why I use tomcat
14:36jsankeysure
14:36jsankeybut any java program can using something like java service wrapper
14:37jsankeywe embed jetty in our app so we use our own startup script which uses the service wrapper
14:38duck1123are you using jetty with clojure, or just plain java?
14:38duck1123I just updated my compojure app to the post-ring version, I think I'm liking it
14:38jsankeythis is a java app i'm referring to, so java
14:39dreish,(- Integer/MIN_VALUE)
14:39clojurebotjava.lang.ArithmeticException: integer overflow
14:39dreish,(#(- %) Integer/MIN_VALUE)
14:39clojurebot2147483648
14:39Chousernice!
14:39dreishFirst one compiles to a call to static public int Numbers.minus(int x). Second one doesn't.
15:46Sebbohhey. Fix your damned bot.
15:46SebbohChannel notices beep!
16:10duck1123does anyone know if it's possible to get compojure to output well-formed xhtml?
16:33duck1123or does anyone recommend a different library for easily creating xml
16:34Chouserthere are many xml-emitting libs
16:35duck1123I need to do xforms, so good namespace support is important
16:35Chouserah. well, that should help you narrow the field a bit
16:35duck1123clojure.xml is a little too verbose for my tastes
16:35Chouserpossibly to zero. :-(
16:37hiredmanyay!
16:42danlarkinHow do I create a pattern with re-pattern that has the same escaping done on it that a #"" regex literal does?
16:43replacadanlarkin: ?, you mean on the source string? I don't think you do...
16:43Chouser,(re-pattern (str #"\woo" "bar"))
16:43hiredmanI don't think you can
16:43clojurebot#"\woobar"
16:43hiredmanheh
16:44replacaChouser, FTW!
16:44Chouserdanlarkin: is that what you meant?
16:44Chouserit's not terribly efficient, of course. One of the benefits of #"" is the Pattern is compiled at readtime, and the above example loses that benefit.
16:45replacabut if you're constructing patterns at run-time, what can you do?
16:45replacaregex's don't have sql-like prepared statements, do they?
16:45danlarkinwell I have a series of complicated regexes that I kinda want to re-use in subsequent regexes
16:46Chouserdanlarkin: I think the Right Solution for that kind of thing will be a clojure-sexp-based DSL for string processing.
16:47Chouserbut until that exists, using #"" to build escaped Patterns, and then str to print them in a form that can be combinded, re-parsed, and re-compiled at runtime will have to do.
16:47replacaChouser: I've heard you say that before (and I have also thought about it). Do you know if anyone has ever tried such a thing in Lisp?
16:48Chouserreplaca: I haven't looked. Is there something that does for reading what cl-format does for writing?
16:48hiredmanChouser: I think it's called fnparse
16:48Chouserheh
16:48Chousercould be
16:48hiredman:P
16:48hiredmanman
16:48replacawell, cl-format is kind of the inverse of regex
16:49Chouserright
16:49hiredmanI completely forgot to get better at using fnparse
16:49replacacryptic, but compact and powerful
16:49Chouseroh, I see what you mean. yeah, that's not what I'm talking about then, is it.
16:49Chouserbut maybe it points to regex being a better alternative than I'm giving it credit for.
16:50replacaChouser: yeah, of thought of the same thing for output - a real dsl for describing output
16:50pstickneis there a really simple way to tell if a list contains a given item?
16:50Chouserdo people ever want to programmatically create cl-format directive strings like they want to with regexes?
16:50psticknee.g. (list-contains :a [:a :b :c]) ?
16:50replacathe problem is that typically, you want to keep those things small to get them out of the way of your algorithm
16:51hiredman,(.contains [1 2 3] 2)
16:51clojurebottrue
16:51hiredman,(.contains [1 2 3] 4)
16:51clojurebotfalse
16:51Chouserpstickne: maybe you want a set instead of a list?
16:51replacaChouser: not so much, but they do complain about the write-only nature
16:51pstickneChouser: a set is fine too, still with the .contains method?
16:51hiredman,(#{1 2 3} 2)
16:51clojurebot2
16:51Chouserpstickne: you can just "call" a set, like you would a function.
16:51hiredman,(#{1 2 3} 4)
16:51clojurebotnil
16:52pstickneohh
16:52psticknesweet
16:52psticknelike a map :p
16:52hiredmanbut sets also have .contains
16:52pstickne,([1 2 3] 0)
16:52clojurebot1
16:52hiredman.contains is part of the java collections api
16:52pstickneneat, thanks :)
16:53Chouserreplaca: conversely, regexes sometimes *are* your algorithm.
16:55hiredman~literal [5] clojure
16:55clojurebotlike life: you make trade-offs
16:55hiredmanthat uses regexs
17:15slashus2Is there an equivalent to prog1 in clojure?
17:16cmvkkwhat's the difference between prog1 and progn again?
17:16slashus2prog1 returns the first
17:17cmvkkthere's nothing built in for that, to my knowledge. seems like it wouldn't be hard to make a macro for that though
18:17replacaChouser: (sorry, I was eating & putting my kid to bed): Yes, you are right. My only point would be that once people learn to do regex, they seem uninterested in less compact ways of expressing the same thing
18:18replacabut I'd emphasize "seem" since I don't have any counter experience
18:21gnuvince_replaca: I know that some people I talk with think that regexes are better than other alternatives (such as having a real parser)
18:22replacagnuvince_: one nice thing is that a regex is "in the form of" the data on which it's operating (i.e. a string)
18:23danlarkinparsers and regexes each have a legitimate domain
18:23danlarkinIMO
18:23replacabut there's obviously some crossover point where you've got the wrong hmmer for the nail
18:23replacadanlarkin: agree 100%, though there can be overlap
18:23durka42replaca: i don't know about that. simple regexes can look like their text, but they get unreadable really fast
18:23replacaesp, if the parser is really accessible, which usually isn't true
18:26replacadurka42: yeah, that's where you get into the grey area
18:26replacabut usually, bringing in a parser is really heavy artillery (think yacc/lex) so peopel will ride the regex train as far as they can
18:27replaca(mixed metaphors, our specialty)
18:29Raynes-The Twitter team has switched to Scala. They are now using Scala along with existing RoR code.
18:30Raynes-Would be moar awesome if it was Clojure, but it's a start.
18:36replacaTHey were desparate for something that scaled and "Scala" sounds like it would, just from the name :-)
18:59dakrone_hbhi all, I'm attempting to get use a jar from Clojure and having some trouble importing it, the java line works as "import estraier.*;" and then a Database() object is available, however clojure won't let me do (import '(estraier Database)), even though estraier.jar is in the classpath
18:59dakrone_hbI apologize for the long question
18:59dakrone_hbI apologize for the long question
19:00dakrone_hbis this the right way to be importing from a 3rd-party jar?
19:00hiredmanwhat happens when you try the import?
19:00dakrone_hbjava.lang.ClassNotFoundException: estraier.Database (NO_SOURCE_FILE:0)
19:01hiredmanare you sure it is on the classpath?
19:01dakrone_hb(import '(estraier)) returns nil, but I'm not sure that's the right way to import it
19:01hiredman(System/getProperty "java.class.path")
19:01dakrone_hbyea, command-line is java -cp /home/hinmanm/src/clojure/trunk/estraier.jar:/home/hinmanm/src/clojure/trunk/jline-0.9.94.jar:/home/hinmanm/src/clojure/trunk/clojure.jar jline.ConsoleRunner clojure.lang.Repl
19:01hiredmandakrone_hb: that is not
19:02dakrone_hbthe getProperty command has the estraier.jar in it
19:02hiredmanwhat is Database?
19:03cmvkkso does import estraier.Database; work from java?
19:03dakrone_hbhttp://hyperestraier.sourceforge.net/javanativeapi/
19:03dakrone_hbyep, an example of a short java file is here: http://hyperestraier.sourceforge.net/javanativeapi/
19:04dakrone_hbcmvkk, It's used as import estraier.*; in Java
19:04cmvkkright, but does it work to do estraier.Database; ?
19:04cmvkkbecause it ought to, right?
19:05dakrone_hbit should, I haven't tried it explicitly, should I?
19:05cmvkkI don't know...it can't hurt I guess
19:05dakrone_hbI'll give it a shot
19:05cmvkkyour syntax is right, for clojure, there's no reason why your clojure code shouldn't work when the java code does. that's the only difference between them.
19:12dakrone_hbhmm...I think there might be a library installation problem.
19:13dakrone_hbbut it's good that I know the clojure syntax is right, thanks cmvkk
19:13cmvkki wonder what's wrong that .* would work but not .Database though
19:13cmvkkI am not very familiar with how packages and importing work in java
19:23cp2,'1/0
19:23clojurebotDivide by zero
19:23cp2lame
19:24cmvkkwhat do you want it to return?
19:24hiredman,'1/3
19:24clojurebot1/3
19:24hiredman,(class '1/3)
19:24clojurebotclojure.lang.Ratio
19:25hiredmango figure
19:25cmvkkwhat...what's surprising about that?
19:25hiredman,(symbol "1/3")
19:25clojurebot1/3
19:25hiredman,(class (symbol "1/3"))
19:25clojurebotclojure.lang.Symbol
19:27cmvkkbecause getting a ratio out of 1/3 is a reader trick.
19:27cmvkk,(namespace (symbol "1/3"))
19:27clojurebot"1"
19:50slashus2Hypothetically could clojure's STM be implemented in clojure?
19:51hiredmanyes
19:51hiredmanrhickey has talked about self hosting clojure somewhere post 1.0
19:51hiredman(which would imply the stm written in clojure)
19:52slashus2One would use the class generator?
19:53hiredmanthe stm is bascially a system of locks
19:54slashus2right
19:54hiredmanand clojue has acess to locks
19:54slashus2(locking ?
19:54hiredmanyeah
19:56slashus2To implement Ref Atom Agent etc. the class generator would have to be used?
19:56hiredmanyeah, gen-interface at least
19:56hiredmanI assume the asm library would not be rewritten in clojure
19:58slashus2hmm... I don't think it could if clojure was to self boot-strap.
19:58slashus2Unless you had a clojure implementation there to begin with.
19:58slashus2I guess that is how gcc works.
19:58hiredmanthe asm lib is some third party thing anyway
19:59slashus2It was first written in asm, compiled, then the compiler was written in C. The process is probably slightly different.
20:04cmvkkthe thing about self-hosting clojure is that you wouldn't be able to just supply the source and expect people to build it
20:04cmvkksince you would need a compiled version of clojure to compile clojure
20:07slashus2cmvkk: Right.
20:08slashus2That was probably the problem with gcc to begin with too?
20:09cmvkkyeah. well all you need is one compiled C compiler, then after that, you just use the immediately previous version to compile the next version.
20:09slashus2yup
22:05slashus2In a transaction, if you both both an alter and a commute, what sort of retry behavior should be expected?
22:10slashus2I guess if the alter value changes, the whole transaction will retry, but it keeps it from retrying if the commute value changes.
22:12cmvkkthe commute never goes through unless the transaction actually commits.
22:12cmvkkand then it goes through on commit, regardless of what else happened.
22:13slashus2So the alter value is the only thing holding it back.
22:13slashus2alter I should say
22:13cmvkkyeah, if you alter the ref inside a transaction, it will retry.
22:13cmvkkif something else alters it first, anyway
22:14cmvkkwhat i want to know is, if you commute a ref inside a transaction and then alter it, the actual behavior of the ref is reversed in the real world, from how it looks inside the ref
22:14cmvkkis that right?
22:16slashus2Well since the commute won't succeed unless the alter succeeds, I think it will fail if the ref is altered elsewhere. I don't think the world is touched until the transaction succeeds?
22:16cmvkkright, i mean if the transaction goes through.
22:16cmvkkinside the transaction, the ref is commuted then altered. but in the real world, the ref is altered first then commuted.
22:16cmvkkor so the commute docs seem to suggest.
22:17slashus2(dosync (commute r + 1) (ref-set r 20))
22:17slashus2If that succeeds I wouldn't the ref be commuted first?
22:18cmvkkinteresting.
22:18orerohi. quick question: why do I need the quote before the map form in this (-> [1 2 3] '(map inc) first - dec (+ 3) (min 5)) ?
22:18cmvkk,(let [foo (ref 0)] (dosync (commute foo inc) (ref-set foo 20)))
22:18clojurebotjava.lang.IllegalStateException: Can't set after commute
22:18slashus2ooo
22:18slashus2..
22:19oreroanyone knows?
22:19cmvkkhold on
22:20cmvkkthat's odd behavior, orero, but
22:21orerois that a bug or is it me?
22:21cmvkkbased on the expected behavior of ->, that map form would be wrong...since it inserts the object as the first argument
22:21cmvkki.e. #(map % inc), when what you want is #(map inc %)
22:21oreroright.
22:21cmvkkusing the quote somehow fixes that
22:21cmvkkapparently
22:21oreroso how did it manage to work anyway?
22:22cmvkkoh wait.
22:22cmvkk,(-> [1 2 3] '(map inc))
22:22slashus2,(macroexpand '(-> [1 2 3] '(map inc) first - dec (+ 3) (min 5)))
22:22clojurebot[1 2 3]
22:22clojurebot(min (clojure.core/-> (clojure.core/-> (clojure.core/-> (clojure.core/-> (clojure.core/-> [1 2 3] (quote (map inc))) first) -) dec) (+ 3)) 5)
22:22cmvkkit doesn't do anything.
22:22cmvkkit puts the vector in as an argument to quote.
22:23cmvkkwhich returns it like normal.
22:23cmvkkso it doesn't give an error, but the answer isn't correct either.
22:23orerooh.
22:23orerogot it. thanks, man.
22:24slashus2cmvkk: I am guessing that the alters and commutes are commited in order?
22:24cmvkkwell, they are, but only because that order is enforced in-transaction.
22:25slashus2right
22:25cmvkkthe commute docs say that the in-transaction value of the ref will be commuted when you call commute,
22:25cmvkkbut the actual commute won't happen in the real world until the point of commit
22:25cmvkkwhich would be after the alter, if you did it that way.
22:25slashus2yeah
22:25cmvkkrather than having weird behavior, it seems it's just not allowed at all.
22:31cmvkk,(-> [1 2 3] (#(map inc %)))
22:31clojurebot(2 3 4)
22:31cmvkkis there a better way to do that i wonder
22:36slashus2,(let [a-fn (fn [x] (map inc x))] (-> [1 2 3] a-fn))
22:36clojurebot(2 3 4)