#clojure logs

2008-04-07

06:49lnostdalhello .. err, weird question maybe .. but how mature is clojure now? .. i'm a common lisp'er, but a client insists that i am to "use java" (well, maybe using the jvm is close enough) .. i guess i need some sort of http server .. (jetty) .. and maybe it would be possible to hook clojure into this somewhere?
06:49lnostdali know java as a language .. but don't know anything about the platform options
09:43Chouserlnostdal: there are a couple implementations of Java servlet stubs that can then hand off control to Clojure code.
09:43ChouserThat's probably the recommended route for Clojure on a web server.
09:44lnostdalok
09:45ChouserOne is "webjure", which is a sort of integrated framework, but may not be up to date with the latest version of Clojure.
09:46ChouserThe other is just ClojureServlet.war. You can download it from here: http://groups.google.com/group/clojure/files
09:56cgrandWhy these two lines throws an exception?
09:56cgrand(defmacro bar [s] `(~print ~s))
09:56cgrand(defn foo [x] (bar x))
09:57cgrands/throws/throw/
09:59cgrand(I try to capture the value of a var at compile time)
10:01rhickey_you end up with an expansion whose head is a fn object
10:02rhickey_there are no evaluation semantics for that
10:04cgrandrich: thanks... I was fearing that answer. How can I work around ? By calling invoke on the fn object?
10:05rhickey_what's wrong with `(print ~s)?
10:11cgrandThis was just an example to succintly shows my problem. This is not the real code. I've got a var named *escaping* which holds the current string-escaping function (the value of *escaping* changes during macro expansion, that's why I try to capture it)
10:11cgrand(s/shows/show/)
10:11rhickey_ok
10:18rhickey_cgrand: actually this should work, seems to be a classname visibility thing - looking into it
10:20cgrandrhickey: thank you!
10:26rhickey_cgrand: fixed
10:26cgrandyou're amazing!
11:27MarkJP�Man, being able to do things like this is awesome: (seq (.. cb (getClass) (getMethods)))
11:28rhickey_especially when you can do it like: (seq (.. cb getClass getMethods))
11:28MarkJPhaven
11:28MarkJPhaven't caught up on my google group reading yet :)
11:29jteoumm..what's ".."?
11:29MarkJPjteo: chaining method calls
11:30MarkJPin java it would be: MyClass.getClass().getMethods()
11:31jteoah.
11:32jteoah okie found the documentation/example
11:32jteo:)
16:21MarkJP_interesting
16:22MarkJP_(def foo "asdf")
16:22MarkJP_(.. foo (getClass) (getDeclaredMethod "getBytes" nil) (getReturnType) (getName))
16:22MarkJP_I get "[B"
16:22MarkJP_same with character array types
16:24MarkJP_don't think its a printing problem:
16:24MarkJP_(str "START " (.. foo (getClass) (getDeclaredMethod "getBytes" nil) (getReturnType) (getName)) "END")
16:24MarkJP_I get "START [BEND"
16:42ChouserYeah, I've seen that for all kinds of Java arrays.
16:42Chouser(into-array ["a"]) --> [Ljava.lang.String;@8fbecf
16:42MarkJPoh
16:43ChouserI wonder if it's some Java-internal naming to indicate an array?
16:43Chouserhm, maybe I'd only ever seen [L, not [B
16:44MarkJP[C for char arrays
16:44MarkJPoh so its not Clojure doing that?
17:01MarkJPyep, its java
17:02MarkJPgetSimpleName work much better
19:46rhickey_new numbers (svn rev 802) - please report any anomalies
21:06rhickey_BigDecimal literals - use M as suffix
21:51Chouserrhickey_: cool re: BigDecimal
22:03rhickey_should be useful
22:06abrooksrhickey_: How do you feel about a polymorphic "load" which takes a file (like "load-file") or a reader? (as a substitute for "load-file")
22:07abrooksThe next question following this would ask the same think of "line-seq" which has no file equivalent (but it would be handy to have one).
22:13rhickey_abrooks: there is load that takes a reader
22:14abrooksrhickey_: Right. I'm asking if you think it would be okay for load to take a reader or a file.
22:14abrooksI would like to call "load" with either a reader or a file name.
22:15abrooksWould you rather be explicit about which one you're calling (load/load-file) or would a polymorphic load be okay?
22:15rhickey_seems better to make a rdr function
22:15rhickey_else everything will have to be overloaded
22:16rhickey_but might be good candidate for multimethod...
22:16abrooksOkay. This suggests that line-seq should have a line-seq-file complement. Would you take a patch for that?
22:17abrooksOr wait... you're considering polymorphic versions. :)
22:17rhickey_definitely not line-seq-file, (line-seq (rdr file))
22:17rhickey_making stream/reader construction easier would be generally useful
22:18abrooksThis brings up another question: I haven't seen any examples of multimethods based on different types (only the keyword style tags) on the site. How would I do that? Are there examples?
22:19abrooksi.e. if I wanted to construct an abrooks-load multimethod which takes either a string (filename) or reader, how would I express the matching?
22:19rhickey_no examples, just use getClass as the dispatch function, and classes as the dispatch values
22:20abrooks"(rdr file)" doesn't curently exist, right?
22:20abrooksgetClass: okay. Thanks.
22:20rhickey_no rdr yet, the trick is all of the different reader/stream combos
22:21abrooksI haven't found a good use for line-seq that isn't shorter than slurp'ing the file and re-seq'ing on top of it.
22:21abrooks^isn't^is
22:23rhickey_abrooks: use class rather than getClass
22:23abrooksOkay.
22:27abrooksrhickey_: Thanks for your help, BTW.
22:27rhickey_sure
22:31abrooksrhickey_: Here's an odd thought (it's Chouser's really with some minor modifications). Print debugging (yes, yes, bad me) has always been a pain for me in lisps since you often can't drop a form in the middle of another without (A) wrapping it in a
22:31abrookser...
22:31abrooksNot done. Fat fingers.
22:32abrooksrhickey_: Here's an odd thought (it's Chouser's really with some minor modifications). Print debugging (yes, yes, bad me) has always been a pain for me in lisps since you often can't drop a form in the middle of another without (A) wrapping it in a "do" and (B) making the nesting of the "do" parens happen at the right spot.
22:33abrooksChouser's idea was a reader macro or macros that could have a left or right associativity and wrap two adjacent forms in a "do". I'll nopaste an example in a sec.
22:39abrooksOkay, that was 7 minutes... http://n01se.net/paste/5ae?pretty=yes
22:41abrooksWith a macro like that, debug lines could be added essentially anywhere, only needing to change the <<</>>> to associate with the preceeding/following form.
22:41rhickey_following is easy, preceding not
22:42abrooksI think following is the common case. That would be cool enough. :)
22:43rhickey_I'm not promising anything yet, let me think about how generally useful this is
22:44abrooksrhickey_: Thanks for considering it.