#clojure logs

2008-05-30

07:02cgrandozzilee: http://code.google.com/p/clj-stuff/wiki/TemplatingExamples#Javascript_HTML_templating_examples -- I'm not quite happy with the current version but it works for my actual needs
09:19ozzileecgrand: I'm going to have to download that and take a look, looks quite cool.
09:20ozzileeI played with a templating system in Scheme that has some ideas I haven't seen elsewhere, you might be interested.
09:20ozzileeLook under "Templates": http://ozzilee.com/mettle/documentation/
09:21cgrandozzilee: thanks, I'll look at it!
09:22ozzileeI also wrote some url-dispatching stuff in Clojure that's something like the Scheme code, but I don't have anything up anywhere.
09:23ozzileeBasically it lets you do (defpage ["foo" bar] (str "bar: " bar))
09:23ozzileeWhich would print plaintext "bar: baz" at /foo/baz
09:26cgrandyour templating system reminds me (because of the querying capabilities) of Genshi
09:30ozzileeI've never looked into Genshi, I'll take a look. Thanks!
09:30cgrandand I took the same road concerning url dispatch, see:
09:30lisppaste8cgrand pasted "defresource" at http://paste.lisp.org/display/61461
09:31lisppaste8blackdog pasted "help with macro pls?" at http://paste.lisp.org/display/61462
09:31blackdogcan't get my first macro to work :/
09:32ozzileeblackdog: Does the code the macro expands to work by itself?
09:32blackdog:/ didnt try that
09:33ozzileeThat'd be your first stop.
09:34blackdogk
09:34ozzileecgrand: What does :filters do?
09:34ozzileeIs that like middleware?
09:35blackdogsame error, and i don't know why the string is expanded unquoted
09:35lisppaste8cgrand annotated #61462 with "actionPerformed" at http://paste.lisp.org/display/61462#1
09:37rhickeyblackdog: does it work if you say: ~'actionPerformed
09:38cgrandsimilar to an around advice in AOP, here it allows me to set up the connection to the db
09:38ozzileecgrand: Ah, ok.
09:39ozzileecgrand: Do you use the jdk6 xmlwriter stuff?
09:40blackdogrhickey, thanks rich that works
09:40rhickeyblackdog: great - I'll look into making that not necessary
09:40blackdogok, so what i had should have workedt then?
09:40blackdogi'm new to macros
09:41rhickeyit has to do with how the proxy finds the matching names
09:42cgrandozzilee: I had bad experiences with xmlwriter/reader for XHTML gen -- not enough control on the output (eg you have to hack around it to get to write a preamble which will trigger standard mode in most browsers)
09:43ozzileecgrand: That's fine by me, I just don't have JDK6 :-)
09:56Chousercgrand: you're referring to Java's own xml read/writer, or the code in clojure-contrib?
09:57cgrandchouser: java's Stax
10:10ozzileeChart of Clojure's performance on a naive fibonacci function over last 70 or so revisions: http://groups.google.com/group/clojure/web/Fib.pdf
10:12ozzileeSingle pass, so accuracy is probably crap, but it's a proof-of-concept.
10:14rsynnottnot necessarily the best benchmark, as it's not a terribly optimisable problem
10:15ozzileersynnott: Again, proof-of-concept :-) The goal is an automated test that will alert us when a revision does something bad to performance.
10:16ozzileeNot so much for a benchmark. I intend to have a number of different performance tests.
10:16ozzileeContributions weclome...
10:18rsynnottsbcl does something of this sort; you could steal their one :)
10:18cgrandchouser: I see xml-stream-writer.clj uses StAX. I'm trying to gather memories of what bit me: I think that is what related to round tripping the DTD.
10:18ozzileersynnott: I'll look into it, thanks.
10:21cgrandozzilee: interesting! Do you plan to include the benchmarks of the languages shootout?
10:23Chousercgrand:
10:23Chousercgrand: ok. I don't know much about xml-stream-writer.clj
10:24ChouserBut I've been kicking around some ideas for xml representation, and thought it would be good to build on Java's libs
10:24Chouserso if that's not true, I wanted to take note.
10:33cgrandchouser: ok. To back my claims: http://stax.codehaus.org/Extensions#Extensions-Rationale
10:40rhickeyozzilee: what's the time for this on your benchmark machine? :
10:40rhickey(defn fib [n]
10:40rhickey (if (int/< n 2) n (int/+ (fib (int/- n 1)) (fib (int/- n 2)))))
10:41rhickeymake sure you pass -server to Java for benchmarks of Clojure
10:49ozzilee1020.345 msecs
10:49ozzileefor 35
10:50rhickeyyour chart was for 30, what's the apples-to-apples?
10:50ozzilee30 is 490.813
10:50ozzileeSorry, misremembered what the chart was for.
10:50rhickeyif you run it a couple of times?
10:50rhickeyhotspot needs to warm up
10:51rhickeyon my machine the type-hinted version is 4x faster
10:52rhickey51ms
10:52drewr229, 236, 233 for me.
10:53rhickeydrewr: vs what for the unhinted version (just drop the int/s)
10:53ozzileeYeesh, yeah it gets down to 88.
10:53ozzileeMakes a big difference if you (defn fib ...) rather than ((fn fib ...) 30)
10:54rhickeyyes, that's a must
10:54jteobigints slow things down eh.
10:55drewrrhickey: 620 unhinted.
10:55rhickeypolymorphic dispatch slows things down, and boxing
10:55rhickeynormally you shouldn't care, but having the hinted versions gives you tuning options when it matters
10:56rhickeylike on benchmarks :)
10:59ozzileeHmm, actually it looks like I lied.
10:59ozzilee(defn fib [n]), then calling fib inside is the slowest.
10:59ozzilee(defn fib this [n]), then calling this inside is the same as (fn this [n])
11:00ozzileeThose both get down to 70, (defn fib [n]) stays at 382.
11:30drewrjava.text.ParseException: Unparseable date: "2008-04-09 17:00:07.403"
11:30drewrAre you kidding me? DateFormat doesn't understand a SQL Server timestamp?
11:30drewrNo wonder people use .NET.
11:32drewrI'd love to write Clojure versions of these libraries and remove teh suck.
11:33rhickeyhttp://www.swa.hpi.uni-potsdam.de/dls/dls08/
11:34drewrNice!
11:35rsynnottI'm surprised SQL server doesn't just use standard SQL dates...
11:35drewrrsynnott: Is that not standard? That's the same as pgsql and mysql too.
11:36drewrrhickey: Impressive program committee.
11:36rhickeyyeah
11:37rhickeyIt's a very nice invite
11:46rsynnottmysql's one looks like '2008-05-30 17:15:04'
11:48drewrrsynnott: I wouldn't consider fractional seconds non-standard. Besides, there are no standards in RDBMSes. :-)
11:48drewrjava.text.ParseException: Unparseable date: "2008-04-09 17:00:07"
11:49drewrjava.text.ParseException: Unparseable date: "2008-04-09"
11:49drewrWhat alternate universe do they live in??
11:53rhickeydrewr: are you using SimpleDateFormat?
11:54drewrrhickey: java.text.SimpleDateFormat@7945516e
11:54rhickeyIt has a ctor that takes a pattern
11:55drewrOK, I used the getDateTimeInstance factory.
11:55drewrBut without a style.
11:57drewrAh, I was using DateFormat.getDateTimeInstance() which apparently created my a SimpleDateFormat with no pattern.
12:12rhickeyhttp://elw.bknr.net/2008/html/home.html
14:56jteodumb qns: is there an equivalent to 'progn', or is there another way of doing things?
14:56Chouser(do ..) ?
14:58jteoah. must have missed that in the documentation.
14:58Chousernp
16:33Zilaticaanyone active in this page?
16:34rhickeyyes
16:34jgracinsure
16:34ZilaticaI'm taking a gander at clojure
16:34Zilaticaand I just downloaded the ants.clj
16:34Zilaticatrying to run it from the java command line
16:34Zilaticajava -cp clojure.jar clojure.lang.Script ants.clj
16:35Zilaticais what I run
16:35Zilaticaand for a split second, I see what looks like a pane pop up
16:35Zilaticaand then immediately die
16:35Zilaticano logged exceptions to the prompt (that I see)
16:36Chousertry Repl instead of Script?
16:36Zilaticaalright, will do
16:36Zilaticathanks!
16:36rhickeyyes, and then run the commands in the comment section at the bottom
16:42Zilaticawhen running in Windows, what is the proper way to load a file from a fully qualified path? I've tried D:\research\ants.clj, which reported invalid token for \r, and I've tried D:/research/ants.clj, which reported invalid token, and I've tried just using a relative path from my command line call to invoke the reple (load-file "ants.clj")
16:43jgracindouble prefix \\r
16:43jgracin?
16:43jgracinguessing
16:43Zilaticajust gave me an invalid token : D:
16:43Zilaticaoddly enough
16:43Chouserfile:// ?
16:43Chouseralso guessing.
16:43Chouserwhat is this "Windows" of which you speak? ;-)
16:43Zilaticalol
16:44rhickeyare you putting this inside " "?
16:44Zilaticaone of the main reasons I got tired of dealing with lisp was I have to use windows at work and couldn't find a good way to involve it in the workplace
16:44Zilaticachecking out clojure
16:44Zilaticacause I can get the repl to work on windows
16:44Zilaticayes
16:45rhickeyI'd expect "D:\\research\\ants.clj" to work
16:45rhickeyalso guessing
16:45Zilaticathe full things I've tried: (load-file "D:/Development/Research/Clojure/ants.clj"), (load-file "D:\Development\Research\Clojure\ants.clj"), and (load-file "D:\\Development\\Research\\Clojure\\ants.clj")
16:45Zilaticasadly, none of those worked
16:45Chouserdo you need the drive letter? If you're already on D: you could try "\\Development..."
16:46jgracinZilatica: what does it report on using the "D:\\Devel..." variant?
16:47Zilaticauser=> (load-file "D:\\Development\\Research\\Clojure\\ants.clj")
16:47Zilatica")\n(load-file "
16:47Zilaticauser=> java.lang.Exception: Invalid token: D:
16:47Zilaticajava.lang.Exception: ReaderError:(5,1) Invalid token: D:
16:47Zilatica at clojure.lang.LispReader.read(LispReader.java:158)
16:47Zilatica at clojure.lang.Repl.main(Repl.java:68)
16:47ZilaticaCaused by: java.lang.Exception: Invalid token: D:
16:47Zilatica at clojure.lang.LispReader.interpretToken(LispReader.java:224)
16:47Zilatica at clojure.lang.LispReader.read(LispReader.java:150)
16:47Zilatica ... 1 more
16:47Zilaticaany ideas?
16:48Zilaticaeveryone hate windows? ;-)
16:48rhickeyyou may have cruft left from \\r, if you could, try restarting the repl and using the "D:\\research\\ants.clj" variant
16:48Zilaticaas a side note, what is the command to quit the repl?
16:48Zilaticayes yes yes, total noob. I know.
16:49Zilaticatried quit, (quit), (exit), exit, sayoonara, (sayoonara)
16:49Zilaticaand a handful of others
16:49jgracintry pressing CTRL-D
16:49Zilaticajust get a ^D
16:49Zilaticahitting enter gets me nothing, repl still expecting input
16:49rhickeyI think most of use do some variant of ^C on unix variants - there's no exit command, send whatever was EOF for DOS
16:50rhickey^Z ?
16:50Zilaticactrl z works for the repl
16:50Zilaticauntil you run it in jline
16:50Zilaticathen no bueno
16:51Zilaticarhickey, you were right, the D:\\ variant worked after I quit the repl.
16:52jgracin(. System (exit 0)) should work.
16:52rhickey(. System exit 0)
16:52ZilaticaThe pane that showed up looks a bit funny though
16:52Zilaticajust a pane with a blue square in the pane
16:52Zilaticanot filled
16:52Zilaticalooks like a width of 1 or 2
16:52Zilaticanothing really going in it
16:52Zilaticaoh wait, hah, more commands to run
16:52rhickeythat's right
16:52Zilaticasry, I'll read on!
16:53rhickeynp
16:55Chouserhm, I can't even get "java" to work on Windows, so you're way ahead of me, Zilatica.
16:56Zilaticayou're my new best friend.
16:56Zilatica:-)
16:56Zilaticanah, I just spent so much time trying to get lisp running on my mac that I gave up
16:56Zilaticacouldn't get the emacs repl to work after 10 hours of investigation
16:57Zilaticaand add to that the fact that work requires windows
16:57Zilaticajust wasn't useful
16:57Zilaticanow I have ants filling a pane with pheremones
16:57Zilaticavery exciting
16:57Zilaticaand all under 2 hours of investigation.
16:57Chouser:-)
16:58ChouserDo I need to download my own JVM? Windows XP doesn't come with one?
16:58Zilaticayep
16:58Zilaticayou checked out Eclipse.org?
16:59Zilaticathat's where the action is for Java
17:01rhickeymore perf boosts!
17:01rhickey static public float[] vmul(float[] x, float[] ys){
17:01rhickey final float[] xs = x.clone();
17:01rhickey for(int i=0;i<xs.length;i++)
17:01rhickey xs[i] *= ys[i];
17:01rhickey return xs;
17:01rhickey }
17:01rhickeyThat's the Java for float/a*a
17:01rhickey(defn amul2 [v1 v2]
17:01rhickey (let [ret (float/aclone v1)]
17:02rhickey (doidx i (float/alength v1)
17:02rhickey (float/aset! ret (.get i)
17:02rhickey (float/* (float/aget ret (.get i)) (float/aget v2 (.get i)))))
17:02rhickey ret))
17:02rhickeyThat Clojure runs at exactly the same speed
17:03rhickeystill working on making it easier, but the net result is no need to go to Java for low-level primitive array stuff
17:03Zilaticacongrats?
17:03Chouserdoidx is new?
17:04rhickeythat's part of what I;m working on - it looks like I might need something like CL's symbol-macrolet
17:04rhickeyto get rid of the (.get i)
17:05Chousersymbol-macrolet provides a simple alternative to a code-walker or something?
17:05rhickeylets you bind a symbol to a replacement form
17:06rhickeybut yes, trying to do the same thing with a code walker is perilous
17:07rhickeyHotSpot is amazing - it turns all those function calls into the same code that uses primitives directly
17:07Chouseroh, so symbol-macrolet isn't itself just a code-walking macro? Where would such functionality be located -- the reader?
17:08rhickeyI made several enhancements today to eliminate extra boxing to/from host calls
17:08Chouserah, cool.
17:08rhickeyCompiler, it's another form, like let
17:08Chouseroh, ok.
17:08rhickeynot fun
17:09rhickeyit interacts (shadows/is shadowed by) with let
17:12Chouseryikes
17:13rhickeythe other alternative is typed lets, but a much bigger can of worms
17:14rhickeysince Clojure still won't have primitive types or operations
17:14rhickeyand I don't want it to turn into Java
17:18rhickeyin a namespace, and with symbol-macrolet, it could look like:
17:18rhickey(defn a*a [v1 v2]
17:18rhickey (let [ret (aclone v1)]
17:18rhickey (doidx i (alength v1)
17:18rhickey (aset! ret i (* (aget ret i) (aget v2 i))))
17:18rhickey ret))
17:20Chouserit would be trivial for i to be a fn, right? (aget ret (i)) isn't too bad
17:21rhickeyto get these optimizations, it has to be a macro, not a fn
17:22Chouserand couldn't aget expect a fn instead of whatever it wants now, such that you'd be down to (aget ret i) without that sacry compiler work?
17:22Chouseroh, ok.
17:23rhickeyThe ultimate goal:
17:23rhickey(defn a*a [a1 a2]
17:23rhickey (amap [i ret a1 a2]
17:23rhickey (* (aget ret i) (aget v2 i))))
17:26rhickeyamap would be a macro that takes care of cloning and stepping
17:26Chouserand then you could rewrite float/a*a and all his friends in Clojure instead of Java?
17:27rhickeyyup, and so could you or anyone write their own similar things, with performance the same as Java
17:27Chouserright
17:43Chouserso hotspot doesn't inline functions well enough to rely on that instead of macros?
17:44rhickeyIt does, that's how this is all getting so fast - BUT, Clojure fns all take and return Object, and it doesn't eliminate the boxing
17:49Chouserdoes that mean (.get i) isn't a function call?
17:50rhickeyIt's a Java call, to a method on a type known to Clojure - those calls are all already as fast as Java and strongly typed
17:50rhickeyClojure calls to Java methods are the same bytecode as Java calls to Java methods
17:51rhickeySo when I make a call to a Java function that does primitive math, Hotspot inlines it
17:51Chouserclojure calls to clojure functions don't require a method lookup, but do get all args boxed?
17:52rhickeyyes, but they travel boxed all the time in Clojure, so no box/unbox except to go to the other side
17:52Chouserhm, ok.
17:53rhickeyA clojure call is a call to a Java method that takes and returns Objects
17:53rhickeyBut you can't define a fn that takes or returns an int, say
17:54Chouserthus ... symbol-macrolet.
17:54rhickeythe last mile...
17:55rhickeySo, that's why there's Numbers.F.add etc
17:56Chouserwould you be unhappy with special syntax for splicing a list, to simplify the interaction with let?
17:56rhickey?
17:56ChouserI'm probably confusing the stages of evaluation.
17:57Chouser(let [i '(.get 5)] (aget ret *i))
17:59rhickeyyes, stages of evaluation is key
18:00Chouserbye
18:09Zilaticais there a way to get closure to compile a clj into a jar?
18:09ZilaticaI know it runs in a VM
18:10Zilaticabut how about compiling clj into jars, does that work?
18:12Chouseryou can include a .clj in a jar and load and run it from there
18:13Chouserthe clojure.jar itself includes several .clj files whose code is available at runtime.
18:14Zilaticaok, but if I inlcuded clojure.jar in an existing java project, could I run something in a Java class against a function defined in a clj?
18:15Chouseryes, though it requires a bit of setup, and then the call to the clojure function isn't just a "regular" Java call.
18:15Zilaticaso cljs are interpreted, not compiled then?
18:15Chouserthere are actually several options here, depending on what exactly you're trying to do.
18:15Chousercljs are compiled at runtime. Or something.
18:16Zilaticathat "Or something." scares me. ;-)
18:16Zilaticabasically, I'm just wanting to find out its capabilities
18:16Chouserthat's just my ignorance. rhickey knows exactly what it does.
18:18ericthorsenif you define a user.clj in your application, the 1st call to a clojure RT function will look for that file and execute it
18:18ericthorsenI use this for boot-strapping enclojure
18:18ericthorsenThis is built in to clojure
18:18Chouserericthorsen: is that in the relased version?
18:19ericthorsennot sure...it is definitely up in svn and has been for a while now
18:19Chousersvn!?! I need to get that.
18:19ericthorsenit's very handy
18:20ChouserI'm trying to patch encojure to control the repl a bit differently, so that (hopefully) jVi will work with it. But I'm in over my head.
18:20ZilaticaChouser, what OS you running?
18:20ChouserZilatica: there are several options. You can define clojure functions in a .clj and then call them by name from Java using a clojure library call.
18:21ChouserZilatica: Linux
18:21ericthorsenchouser: can you send me some details as to what you are up against there? We are doing quite a bit of work on enclojure and I'd like to see what happening there
18:21Chouserericthorsen: absolutely! enclojure google group?
18:22ZilaticaChouser: I think I'm going to have to continue my investigation tonight, possibly tomorrow. About to head out of the office and into the wild. ;-)
18:22Zilaticathanks for the help!
18:22Zilaticaand insight
18:28ericthorsenchouser: yes