#clojure log - Jun 28 2008

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

2:42 spacebat_: forgive yet another newb question, but how do you make a seq non-lazy?

2:43 what I mean is, say I have a seq s, and try to concat it with (str s)

2:43 and print that out, I get clojure.lang.LazySeq@cd4cae45

2:44 perhaps I've asked the wrong question, if str is n-ary, how do I pass s to it such that its expanded as a normal argument list?

2:45 and I know that answer, apply

2:45 lol thanks for listening

3:06 slava: convert it to a string, i guess

3:06 oh, you figured it out :)

3:09 spacebat_: yes, (println (apply str s))

3:10 I just set up ilisp-clojure.el

3:10 but clj files load in lisp-mode, and slime seems to rebind some of the keys that ilisp expects

3:10 is there slime support for clojure I wonder

3:12 * spacebat_ googles ilisp vs slime to the death

3:19 spacebat_: looks like this could be the ticket: http://clojure.codestuffs.com/

3:19 so I don't need ilisp, or even lisp-mode for clojure

10:36 gomer-nyc: hello

10:37 Chouser: hi

10:39 gomer-nyc: I'm struggling with something; I have read just enough in a few postings to put me on a trajectory but am now stumped

10:39 summary: gen-and-save-calss; servlet; tomcat

10:41 I guess my Q is this: how to configure my webapp in tomcat to load my servlet that I'm defining in a clj file under WEB-INF/classes?

10:43 Chouser: My servlet knowledge is pretty shallow. I was actually trying that myself a couple weeks ago.

10:43 You might want to look at webjure and see how it does this.

10:44 gomer-nyc: right

10:44 Chouser: I think the lastest version of webjure is still from before there was gen-and-save-class, but it may help point the right direction.

10:44 rhickey: You've got a servlet .class file from gen-and-save-class?

10:46 fomr something like:

10:46 (clojure/gen-and-save-class "/Users/rich/dev/clojure/gen/"

10:46 'org.myns.MyServlet

10:46 :extends javax.servlet.http.HttpServlet)

10:47 gomer-nyc: yes, I've done that

10:47 rhickey: and a corresponding MyServlet.clj?

10:48 gomer-nyc: hmmm, I think my .clj is named differently

10:48 rhickey: than your servlet?

10:49 put both in WEB-INF/classes/org/myns/

10:50 gomer-nyc: ok

10:50 rhickey: and entries like this in web.xml:

10:50 <servlet>

10:50 <servlet-name>MyServlet</servlet-name>

10:50 <servlet-class>org.myns.MyServlett</servlet-class>

10:50 </servlet>

10:50 <servlet-mapping>

10:50 <servlet-name>MyServlet</servlet-name>

10:50 <url-pattern>/*</url-pattern>

10:50 </servlet-mapping>

10:50 Chouser: since we're on the topic, this something I've been wondering about gen-class...

10:51 gomer-nyc: bloody awesome

10:51 it works

10:51 rhickey: and clojure.jar in WEB-INF/lib/

10:51 gomer-nyc: beautiful

10:51 rhickey: great!

10:51 Chouser: gen-and-load-class seems to be to act like a runtime definition, just like proxy or any function def. But gen-and-save-class seems like it would be used at something like build or install time.

10:52 gomer-nyc: chouser: yes, that is a little confusing

10:52 I was under the impression that a bootstrapper would call my XServlet.clj, which includes the gen-and-save-class

10:54 rhickey: gen-and-save-class gets you your static stub, after which you can get on with your dynamic life

10:54 gomer-nyc: but you have to to gen-and-save-class during a build phase, i.e. the .class file must be there before your servlet will be called.

10:56 rhickey: It is anticipated that gen-and-save-class will rarely need to be rerun, only if you change signatures

10:56 it should definitely be separate from the implementation code

10:57 gomer-nyc: yeah, it makes sense. I'm structuring my code in WEB-INF/classes/org/myns/ as genstubs-XServlet.clj and XServlet.clj. Calling genstubs-XServlet.clj only when I'm starting to build out my Servlet implementation. Likelihood of needing to regen the .class file is very low

10:58 rhickey: I know the enclojure guys are struggling with where this (gen-and-save-class) fits in the Java build cycle

10:58 Chouser: it's almost like you want an ant task to run your genstubs at build time.

10:58 rhickey: right, that's why eric wants a different extension

10:59 Chouser: ah, i do remember him mentioning that.

11:00 I think I like the prefix (genstubs-) better. Or at least something that leaves the .clj in place, since it is still Clojure source code.

11:00 rhickey: can you trigger Ant tasks off of file prefixes?

11:01 Chouser: I haven't a clue. I'm not an ant guy. But you certainly could with gnu make.

11:02 gomer-nyc: if not, one could do something like .cljgenstub

11:02 :-)

11:09 follow-up question....

11:10 If I simply modify my servlet implementation contained in the .clj file, when will Tomcat (or other servlet container) start serving that?

11:10 am I now entering the world of server configuration?

11:11 Chouser: I would think you'd have to tell something to re-load your .clj

11:12 you can probably add a feature to your servlet to allow you to tell it to load-file on request.

11:15 gomer-nyc: hmmm, interestin idea -so it reloads itself when called?

11:15 Chouser: Right.

11:16 I think clojure.jar (or maybe you gen'ed .class file?) is loading your .clj the first time. Nothing's going to automatically re-load the .clj when it changes.

11:17 But it would be easy to run (load-file "XServlet.clj") yourself whenever you see fit.

11:41 * Chouser refrains from mentioning servlet features he'd like, for fear of angering the Java gods.

12:29 gomer-nyc: Chouser: I can think of 3 approaches:

12:29 1) whenever a request is made to the servlet, it can check whether the .clj has has been modified, then reload (not every efficient)

12:30 2) servlet allows a socket connection that gives you a REPL (like webjure)

12:31 3) one of the servlet requests could be reload-source, and so you can issue it like you would any other request

12:31 Chouser: I like all three.

12:31 gomer-nyc: I'm gonna try #3 for now, since it seems like the simplest

12:31 rhickey: Also file system watcher looks for changes on predetermined interval

12:31 Chouser: You could adjust (1) to only happen if a *development-mode* was true, and that flag could be set via (2) or (3)

12:32 hm, predetermined interval or by using OS support to get notifications of file changes.

12:33 I know linux and Mac both can provide that sort of notification, and I assume Windows can as well. I dunno how hard it would be to get the JVM to hook into those.

12:33 rhickey: whatever Java lets you does easiest. a 10 sec poll is no big overhead

12:34 do most easily

12:37 gomer-nyc: I wondered about implementing FileListener

14:08 Chouser: fail. "Servlet is not available"

14:09 this has been my general experiance with Servlets. :-/

14:24 gomer-nyc: chouser: so I've done (3); basically just another servlet called ReloadServlet, and which takes the querystring passed to it and does a (load-file) on it - this way I can specify which servlet to refresh from its .clj

14:26 One improvement to this may be to say, if no querystring, then reload everything that has been modified since last reload

14:27 (I'm taking this approach over the auto-reload via a file listener approach, because (a) what refresh time to choose? and (b) more in line with the typical (load-file) during interactive dev)

14:39 Chouser: sounds like it might be a security risk on a production server to be able to name any file to load. But useful for dev.

14:40 what web server are you using?

14:42 gomer-nyc: I'm using tomcat right now

14:43 right, you wouldn't be making code changes like that on a running server anyway

14:43 (production server)

14:46 Chouser: I think Paul Graham might disagree, but that's a whole other thing. ;-)

14:46 do you have to provide a logging.properties file for tomcat?

14:48 gomer-nyc: hehe, yeah, I guess you could "protect" the reload servlet and have it avail.

14:48 I didn't do any tomcat customization

14:48 (I'm only learning servlet/tomcat now, so might be missing some stuff)

14:49 to get my stuff up, just created a folder in the webapps dir under tomcat, and built the web-inf/classes and lib directories with the required .clj and .class files for the servlets

14:49 Chouser: yeah, thought I was following along, but I'm just getting "Servlet is not available"

14:50 I've got a stack trace in the tomcat log whining about being unable to read a logging.properties file in WEB-INF/classes

14:50 gomer-nyc: I have this file structure:

14:51 - web-inf / classes / com / myorg / *.clj and *.class

14:51 - web-inf / web.xml

14:51 - web-inf / lib / clojure.jar

14:51 that's it (make sure web.xml specifies the servlets)

14:52 Chouser: yeah, that's what I've got.

14:52 gomer-nyc: running out now; going to see the olafur eliasson waterfalls in the east river

14:53 Chouser: ok, have fun!

14:53 gomer-nyc: catch you later

22:43 lozzar: can anyone point me to any resources on how i might use sqlite in clojure or just somewhere to dive in?

22:45 spacebat_: hi lozzar, I'm in a similar position

22:45 the clojure google group has been quite useful

22:46 lozzar: thanks ill check it out

22:51 spacebat_: along with the part on the wiki where it maps old function names to new

22:52 people have recommended spending a lot of time reading boot.clj and other files where the clojure environment is built from primitives

22:52 I didn't get very far with that at first but soon I should be able to get more out of it

22:53 still wrestling a bit with getting my emacs environment right for it

22:55 when running with slime the output of (.. System out (println "string")) doesn't make it to the buffer, whereas (println "string") does

22:56 there is another clojure-mode that seems to be set up for ilisp, which I might try again

22:56 I'm curious to know what other people use

23:12 drewr: lozzar: First, find a sqlite Java lib. Then call it from Clojure.

23:13 lozzar: right now i'm just playing around with the sql library in clojure-contrib to get a feel for it but can't get it to work with the example .. something about (lib/use sql) not being a right library

23:40 drewr: I haven't plumbed the depths of clojure-contrib yet. :-/

Logging service provided by n01se.net