#clojure logs

2009-09-07

03:50joha1I cannot find any example of connecting clojure.contrib.sql to an Oracle DB. Can anyone help?
03:51joha1Is it possible/tested at all?
04:00joha1nm, it works now
04:07joha1added the Oracle DB info in http://en.wikibooks.org/wiki/Clojure_Programming/Examples/JDBC_Examples#Connection_Examples, in case someone else has a similar problem in the future
04:37joha1From a DB I get strings like "(aaa bbb ccc)" which I want to convert to list/vectors or symbols, in this case (aaa bbb ccc) or similar. I tried variations of eval and apply but no luck. Any suggestions?
04:39Chousukeuse read-string first
04:39Chousuke,(doc read-string)
04:39clojurebot"([s]); Reads one object from the string s"
04:39joha1ah, thanks
04:39Chousukebeware of #=() though
04:40Chousuke,'#=(println "foo") ; read-time evaluation
04:40clojurebotfoo
04:40joha1ok, will keep it in mind. Should be enough for my needs anyway, so thanks again
04:50jdzor bind *read-eval* to false
04:51jdz,(binding [*read-eval* false] (read-string "#=(println foo)"))
04:51clojurebotjava.lang.RuntimeException: java.lang.Exception: EvalReader not allowed when *read-eval* is false.
05:12LauJensenGents, can I have some thoughts? http://bestinclass.wordpress.com/2009/09/07/java-vs-clojure-lets-talk-ceremony/
05:22liwpLauJensen: I just started reading, but just a quick comment: I don't think you should assert that "most functionality for the least amount of code" is always good. I think you mean that you don't want boiler plate code if you can avoid that, but that's not the same thing. E.g. J will give you very succint code, but no one will be able to read it after it's been written. Also, Haskell will give you very succint code,
05:22liwpbut it takes a longer time to write that code.
05:23LauJensenOk I see your point
05:23LauJensenIt was meant in the context of ceremony
05:24liwpyeah, and it makes sense if you read it that way and I agree with the sentiment :-)
05:24LauJensenBut if you can get to the bottom without strong grievances I'll post it on DZone :)
05:25liwpOk, I'll get back to you when I'm done with it (might be a while, I'm at work)
05:25LauJensenFair enough - Dont get in any trouble on my account :)
05:26jdz"since is a functional language"
05:26LauJensenthx
05:26LauJensenVery succint text
05:26jdzand the sentence should end with "in the core" i think
05:27LauJensenk
05:27jdzbut i'm not native english speaker
05:27LauJensenMe neither :)
05:27jdz"not wanting win" -> "not wanting to win"
05:28LauJensengood catch
05:28jdzi wouldn't call let a macro
05:28jdzmaybe just form
05:28LauJensenA true, its a special form
05:29jdz"it's" :)
05:30liwpLauJensen: I think you'll end up getting a lot of hatemail from Java developers!-)
05:30jdz"if i wanted ... I needed" -> "if i wanted ... I would need", but not completely sure
05:30LauJensenI certainly hope so
05:30liwpLauJensen: but more seriously, I think you're example has some holes in it
05:30jdz"your"
05:30LauJensenliwp: Like what?
05:30liwpLauJensen: e.g. the import list can be reaplaced with "import java.util.*"
05:31LauJensenliwp but to a different effect
05:31liwpLauJensen: I agree with you, but this is what the Java devs are going to say
05:31LauJensenTrue - Maybe I should prepare my defences
05:32liwpLauJensen: also the iterator creation is unnecessary with the new for syntax: for (String s : list) { ... }
05:32liwpwhich reduces a whole bunch of lines from your example
05:32LauJensenliwp: Spell it out for me
05:32liwp~paste
05:32clojurebotlisppaste8, url
05:32lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
05:33liwpLauJensen: urgh, you're code is an image rather than text so I can't copy paste it!
05:33LauJensensec
05:33lisppaste8Lau pasted "for liwp" at http://paste.lisp.org/display/86700
05:33LauJensenYou can annote that
05:34liwpLauJensen: ok, give me a minute
05:34LauJensenyou got it
05:35lisppaste8liwp annotated #86700 "untitled" at http://paste.lisp.org/display/86700#1
05:37LauJensenIf you were to completely mimic the first one, you'd be down from 28 to 22. Thanks alot for the input - I didnt know :)
05:37miha,(+ 1 2)
05:37clojurebot3
05:37liwpAnd the last thing is that you can probably use something like java.util.Arrays.asList() to create the original list from an array of literal Strings which will make your point about adding a new element to the list a bit moot
05:37liwpso that would take another ~5 lines away from the java example
05:39liwpLauJensen: so I do agree with you that Java forces a lot of ceremony on you, especially since everything must be in a class, but I think you should come up with a stronger example
05:40LauJensenliwp -I will dig into Java more in the coming weeks. Mainly what I was going for was something which had grounds for comparison in the approach itself - otherwise I could have stuck with my one-liner :)
05:41lisppaste8liwp annotated #86700 "untitled" at http://paste.lisp.org/display/86700#2
05:41liwpLauJensen: I think your java hatemail will include something like the last annotation
05:41LauJensenhehe, nice
05:42liwpthat's 14 lines I think, so still longer than your clojure version
05:42Chousukethe java-like clojure code is not very idiomatic either I think. hmm.
05:42LauJensen17
05:43liwpbut you can also fiddle with the formatting to make the Java shorter / clojure longer
05:43liwpLauJensen: Oh, one final thing is that your class name should be Capitalised
05:44LauJensenI think if I wanted to do a succint vs succint version, I would put your latest in the post liwp. But the point is not wether or not you can write succint java code, I think you can. Its on ceremony. And at the end of the day, you can do functional programming in QBasic if you want, but what does your language default to ? thats primarily the questions I want to raise
05:44liwpsomeone's going to point that out in your comments and call you a Java newby ;)
05:45liwpLauJensen: sure, and I agree with you, but I don't think you're going to convince a Java head of that with your current example
05:45LauJensenliwp: Dont ever get me wrong: I dont want converts :)
05:46Chousuke,(reduce (fn [acc item] (if (some (partial = item) acc) acc (conj acc item))) [] ["foo" "bar" "zonk" "foo"]) ; explicit loops are ugly
05:46clojurebot["foo" "bar" "zonk"]
05:46jdzcomparing languages using small examples like that will inevitably turn into language flamewars
05:46liwpjdz: exactly
05:47LauJensenliwp: I'm extending the conclusion as we speak
05:47Chousukereduce is something that's a basic functional tool so it's rather like the for loop special syntax in the java code :P
05:47Chousukeand you can't write a reduce in Java without even more ceremony.
05:48LauJensenIts updated, I think that'll discourage the first few haters
05:48liwpChousuke: do you use partial and comp a lot? I love them in Haskell, but I don't like the look of them in Clojure at all. Plus the #() form is a good replacement for partial in most cases
05:48ChousukeI use #() most of the time I think
05:49Chousuke#(= item %) just looks a bit noisy
05:49LauJensenChousuke: Your example is very nice for me, but for an uknowing crowd its perlishly nasty
05:49ChousukeLauJensen: the loop code is even worse though :P
05:49liwpheh, I'd prefer that, I think, to (partial = item)...
05:49LauJensenIts readable for people coming from imperative languages
05:50ChousukeLauJensen: but it looks noisy compared to the java loop :/
05:50Chousuke(because it's denser)
05:50eevar2LauJensen: why use a loop at all?
05:50LauJensenHmm, yes... I'm reconsidering
05:50LauJensenIts not bad actually
05:51Chousukeinclude both, just to show that explicit loops are often not needed.
05:51eevar2the Java approach would be something like Set uniques = new HashSet( arrayListOfStrings );
05:51liwpeevar2: true!
05:51Chousukeeevar2: you mean like (vec (set arraylist))?
05:51ol3,(doc slurp)
05:51clojurebot"([f] [f enc]); Reads the file named by f using the encoding enc into a string and returns it."
05:51liwplike jdz said, these thing will inevitably end up in flame wars
05:52LauJensenChousuke: I think I'll go with yours, I assume thats okay
05:52Chousukesure.
05:53eevar2Chousuke: yup. writing convoluted code for simple stuff like this makes both languages look bad ;)
05:54eevar2s/convoluted/naive/
05:57ol3hello, clojure-bot supports an encoding for slurp my clojure did not. I have clojure 1.0, what is its default encoding?
05:57jdzdepends on your JVM
05:57jdzand environment
05:58jdzbut you can specify one with -Dfile.encoding when starting JVM
05:58LauJensenI updated the post. I think its good now :)
05:59jdzol3: but relying on system supplied defaults will get you into trouble sooner or later, anyway
05:59ol3I want to specify the encoding at runtime, so i don't use slurp, right?
06:00jdzi guess so
06:00jdzi have written a utility function for myself
06:00jdzshould be somewhere on lisppaste
06:01jdzothers also have provided their versions
06:01jdzdunno why the encoding stuff is not in the core
06:02ol3maybe it will
06:02ol3,(doc slurp)
06:02clojurebot"([f] [f enc]); Reads the file named by f using the encoding enc into a string and returns it."
06:02jdzoh, see, you can specify the encoding :)
06:02jdzi still use my own version
06:02jdzhttp://paste.lisp.org/display/80970
06:03jdzbecause i want to read compressed files
06:04ol3but encoding is not in the 1.0 version
06:04ChousukeWhy are you not using BufferedReader or something? :/
06:05jdzbecause my Java-fu is lacking maybe
06:05Chousuke(BufferedReader. (InputStreamReader. (SomeInputStream. ...)))
06:08LauJensenok guys, its live: http://www.dzone.com/links/java_vs_clojure_lets_talk_ceremony.html
06:08LauJensenThanks a lot everybody for taking the time
06:08ol3Chousuke: thanks, looks good
06:09ChousukeThere might be more specialised readers than InputStreamReader though.
06:09Chousukecheck the docs :)
06:10jdzye, i use FileInputStream
06:11jdzbut thanks for pointing this out
06:11jdzthe buffering exercise was fun, anyway
06:11ChousukeLauJensen: your idiomatic clojure code is missing a [
06:12ChousukeLauJensen: (let [lst "foo" "bar" ...
06:12jdzi was just learning Clojure at that time
06:12LauJensenthanks for staying awake Chousuke
06:12eevar2LauJensen: why do you import java.util.List when you never use the interface?
06:12LauJenseneevar2: artifact, thanks for pointing it out
06:15jdzalso, the indentation of clojure code is very un-ideomatic
06:15jdzand why is the code in images, anyway?
06:16LauJensenwordpress.com doesnt to very nice code highlighting
06:16jdzdoes it accept html?
06:16LauJensenyep
06:17ChousukeSVG images!
06:17jdzLauJensen: what editor are you using?
06:17LauJensenFor?
06:17jdzmaking the code images
06:18LauJensengnome-text
06:18ol3you code use the <pre> tag, highlighting is overrated
06:18LauJensenol3 alright, I'll try that the next time
06:18LauJensenimages arent optimal
06:19ol3if you really need highlighting, there is an htmlize package for emacs
06:19ol3http://www.emacswiki.org/emacs/Htmlize
06:20LauJensenSweeet :)
06:21lisppaste8jdz pasted "ideomatic clojure code in emacs" at http://paste.lisp.org/display/86702
06:21jdzusing htmlize :)
06:23jdzand the let error is even preserved :)
06:24ol3most of the time i do not use font-lock anymore...
06:25jdzpretty colors are essential for things published on the interwebs
06:30ol3really? IMHO people only think there is an advantage in highlighting, because it looks nice/cool, but where is the real benefit?
06:30LauJensenspeed
06:30ol3speed?
06:31LauJensenyea, your eyes dont need to read everything, they bounce of the colors to the places you need to go, its grooooovy man :)
06:32ol3I think this is an illusion, are there tests about this?
06:32LauJensenDont need tests, its evident
06:32jdzi'm pretty sure having colors helps with navigation
06:32Chousukethe colours help make the structure clearer to me.
06:33Chousukeprocessing colour takes less mental effort than processing the actual text
06:33Chousukeso if I can ignore parts of code based on its colour, I am more efficient :)
06:34Chousukeand on the other hand, I might focus better on parts with an "important" colour
06:34hiredmanat the very least rainbow parens are a must
06:34jdznot
06:34Chousukenot to me
06:34hiredman:/
06:34hiredmanthey are great
06:34ChousukeI don't even look at parens much nowadays.
06:34jdzproper indentation is a must
06:35ChousukeI don't need to care which paren ends which expression because I know paredit takes care of that :)
06:35ol3nope, the defn/defun is not important, it's at the beginning of the line anyway
06:36ol3but nevermind, people are different
06:36jdzwell, i'm more concerned with colorization of strings
06:37Chousukethe other thing is that colours are much more pleasant than just grey text
06:37Chousukeat least, when they have purpose.
06:37_mstthe differences are interesting... I've always turned my syntax highlighting back to bold or not bold :)
07:49ol3is there a standard way to update a map in a map?
07:50ol3(dosync (alter map assoc :other-map (assoc (:other-map @map) :key :new-value)))
07:50ol3
07:51ol3@r
08:00cgrand(doc assoc-in)
08:00clojurebot"([m [k & ks] v]); Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created."
08:00cgrand(doc update-in)
08:00clojurebot"([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created."
08:01cgrandol3: (dosync (alter map assoc-in [:other-map :key] :new-value))
08:04ol3cgrand: thank you
08:06ol3this is really cool!
08:07ol3,(assoc-in nil [:this :is :a :deep :structure] :value)
08:07clojurebot{:this {:is {:a {:deep {:structure :value}}}}}
08:08cgrandupdate-in and dissoc-in are cool too
08:09ol3(doc dissoc-in)
08:09clojurebot"clojure.contrib.core/dissoc-in;[[m [k & ks as keys]]]; Dissociates an entry from a nested associative structure returning a new nested structure. keys is a sequence of keys. Any empty maps that result will not be present in the new structure."
08:11ol3(doc dissoc-in)
08:11clojurebot"clojure.contrib.core/dissoc-in;[[m [k & ks as keys]]]; Dissociates an entry from a nested associative structure returning a new nested structure. keys is a sequence of keys. Any empty maps that result will not be present in the new structure."
08:11ol3works even if keys are string
08:13Chousukeworks with vectors too
08:13Chousukeat least, IIRC.
08:14Chousuke,(update-in [2 [1 2 3]] [1 2] inc)
08:14clojurebot[2 [1 2 4]]
08:19ol3why are references funcallable?
08:20ol3just curious
08:21cgrandlast time I asked, Rich told me to not rely on that -- it's undocumented
08:22cgrandI guess it may be some legacy from the time where refs and vars were the same thing
08:23ol3so always use the @, ok
08:57hamza(doto frame (..) (.pack) (...)), pack call causes classcastexception?
08:58hiredmanlisppaste8: url
08:58lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
08:58hiredman
08:59lisppaste8hamza pasted "snake" at http://paste.lisp.org/display/86708
08:59hamzait's the example from programming clojure..
09:01hiredmanwhat page?
09:01jdzthe .pack call is commented out, though
09:02hiredmandid you copy it out of the book, or have you tried from the source repo?
09:02hamzai copied from the book, i was testing if setSize would work thats why its commented out, with setSize it works but .pack causes exception
09:04hiredmanah
09:04hiredmanyou miscopied
09:05hiredmanyou are missing two * in game-panel
09:05hiredmanhand copying a large chunk of code like can be troublesome
09:06hamzawhat am i missing?
09:06hiredmanyou are missing two calls to *
09:06hiredmanthe parens are there
09:07hiredmanso you have two numbers there
09:07hiredman,(1 2)
09:07clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
09:07emacsenWhat's the proper way to overload a function name that's used in the core?
09:07hiredman^-
09:07hiredman,(doc refer-clojure)
09:07clojurebot"([& filters]); Same as (refer 'clojure.core <filters>)"
09:07hiredman,(doc refer)
09:07clojurebot"([ns-sym & filters]); refers to all public vars of ns, subject to filters. filters can include at most one each of: :exclude list-of-symbols :only list-of-symbols :rename map-of-fromsymbol-tosymbol For each public interned var in the namespace named by the symbol, adds a mapping from the name of the var to the var to the current namespace. Throws an exception if name is already mapped to something else in the current nam
09:08emacsenthx
09:08hiredmanrefer-clojure has a corresponding :refer-clojure for the ns for
09:08hiredmanform
09:08emacsen"name" fits my problemset too well
09:09JomyootHow to define a function that takes variable number of inputs [a b] and [a b c]
09:09JomyootI cannot (defn) twice
09:09Jomyootit erases the first (defn)
09:09emacsenJomyoot, read the section on multiple arity
09:09Jomyootin Java, I would just define the function twice with different inputs
09:10emacsenJomyoot, functions can take multiple forms
09:10hiredmanJomyoot: there are many ways
09:10emacsenJomyoot: http://clojure.org/functional_programming
09:10achimfor example (defn foo ([a b] ...) ([a b c] ...)), or (defn foo [a b & [c]] ...)
09:10emacsenread the section on multiple arity
09:11Jomyootthanks
09:11hiredman,((fn ([a] a) ([a b] [a b])) 1)
09:11clojurebot1
09:11hiredman,((fn ([a] a) ([a b] [a b])) 1 2)
09:11clojurebot[1 2]
09:13emacsenhiredman, thx for your help
09:15emacsenand what's the current prefered pretty-printer?
09:16hiredman~scala (0 /: List(1,2,3))(_ + _)
09:16clojurebotInt = 6
09:17jdzemacsen: clojure.contrib/pprint
09:18liwphiredman: huh?
09:18liwpis that a reduce?
09:18hiredmanI don't know scala
09:18liwpok then :)
09:18liwp~scala (0 /: List(1,2,3,4))(_ + _)
09:18clojurebotInt = 10
09:19liwpI guess so
09:19emacsenclojure.contrib.pprint.PrettyWriter [Thrown class java.lang.ClassNotFoundException]
09:19liwp~scala (1 /: List(1,2,3,4))(_ * _)
09:19clojurebotInt = 24
09:19ol3is the 'Programming Clojure' book good?
09:19hiredmanyou neeed to compile contrib properly
09:19emacsenhiredman, what do you mean by properly? :)
09:20liwpemacsen: with ant
09:20hiredmanemacsen: run ant, and looking for a line with "Warning" in it, and follow the directions
09:20emacsenhiredman, ah, good point. I didn't compile clojure.contrib at all
09:20emacsenat least not the slime used one
09:20jdzemacsen: clojure.contrib.pprint/pprint i think the function is named
09:20emacsenthx
09:20hiredmanwell there is no clojure.contrib
09:21Chouser~scala ( for( i <- 1 to 100 ) yield i * i ).foldLeft(0) ( _ + _ )
09:21clojurebotInt = 338350
09:30AWizzArdThe class http://java.sun.com/products/javamail/javadocs/javax/mail/Flags.html has a field "Flag" which is a static inner class. This class has static fields, for example "SEEN". How can I name Flags.Flag.SEEN in Clojure?
09:30ChousukeAWizzArd: Flags§Flag/SEEN
09:30Chousukeer
09:30Chousuke$*
09:30hiredmanhaha
09:31AWizzArdChousuke: unfortunately not
09:31AWizzArdah
09:32AWizzArdwhat works is javax.mail.Flags$Flag/SEEN
09:32AWizzArdbut Flags$Flag/SEEN not, although I imported Flags
09:33AWizzArdI get at java.lang.Exception: No such namespace: Flags$Flag when I do Flags$Flag/SEEN
09:33cgrandAWizzArd: you need to import Flags$Flag
09:33AWizzArdoh nice :)
09:34AWizzArdyes, that works
09:34AWizzArdthx
09:47ol3is there a prog1 in clojure
09:49hiredmando
09:49jdzumm, not really
09:49hiredmanok
09:49jdz,(doc do)
09:49clojurebotI don't understand.
09:50ol3,(doc 'do)
09:50hiredman~progn
09:50clojurebotjava.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol
09:50clojurebotExcuse me?
09:50hiredmando is a special form
09:50ol3to be more specific, i need a queue , one thread enques values another dequeues values
09:50jdzol3: well you can write a simple macro with a let + do
09:51AWizzArdyou could try a clojure.lang.PersistentQueue
09:51jdzol3: then prog1 is completely not the tool for you
09:51hiredman,(conj (clojure.lang.PersistentQueue/empty) 1)
09:51clojurebotjava.lang.NoSuchFieldException: empty
09:51hiredman,(conj (clojure.lang.PersistentQueue/EMPTY) 1)
09:51clojurebot(1)
09:52hiredman,(peek (conj (clojure.lang.PersistentQueue/EMPTY) 1))
09:52clojurebot1
09:52hiredman,(pop (conj (clojure.lang.PersistentQueue/EMPTY) 1))
09:52clojurebot()
09:52hiredman,(pop (conj (clojure.lang.PersistentQueue/EMPTY) 1 2 3))
09:52clojurebot(2 3)
09:53AWizzArdlike lists, but you conj to the end
09:53jdz,(conj (PersistentQueue/EMPTY) 1)
09:53clojurebotjava.lang.Exception: No such namespace: PersistentQueue
09:53ol3ah, this is exactly what i needed, thank you!
09:53AWizzArdright, it is undocumented and a little bit hidden :)
09:54jdzisn't clojure.lang used by default?
09:54hiredmannope
09:54hiredman,(import 'clojure.lang.PersistentQueue)
09:54clojurebotclojure.lang.PersistentQueue
09:54jdz,(conj (PersistentQueue/EMPTY) 1)
09:54clojurebot(1)
09:54jdzhehe, until next reboot i guess :)
09:55AWizzArdyou could (import 'clojure.lang.PersistentQueue) first
09:55AWizzArdoh, hiredman was faster :)
09:57jdzis it possible to blow up clojurebot by importing too many namespaces?
09:58JomyootHow to convert [1 2 3] into Java Array {1, 2, 3}
09:58AWizzArd,(to-array [1 2 3])
09:58clojurebot#<Object[] [Ljava.lang.Object;@57e9bb>
09:59hiredman,(into-array [1 2 3])
09:59clojurebot#<Integer[] [Ljava.lang.Integer;@150ad83>
09:59AWizzArdanother alternative
09:59hiredman,(into-array Integer/TYPE [1 2 3])
09:59clojurebot#<int[] [I@196a671>
09:59AWizzArd,(int-array 3 [1 2 3])
09:59Jomyootwhat's difference?
09:59clojurebot#<int[] [I@419710>
09:59AWizzArdJomyoot: performance
10:00Jomyooti think i need int-array
10:00hiredmanJomyoot: the type of the array
10:00hiredmanthe first one is an array of Objects
10:00hiredmanthe second an array of Integers, the third ints
10:00Jomyoot,(int-array [1 2 3])
10:00clojurebot#<int[] [I@bc03b>
10:24ambientanyone tried Clojure on the CLR? is it usable?
10:32Fossias in .NET?
10:33Fossii thought that was discontinued until new-new is done
10:33ambientoh ok :)
10:33arbschtreally, when?
10:33Fossii thought reimplementing all the persistent datastructures is just a little too painful :)
10:34arbschtlooks active to me http://github.com/richhickey/clojure-clr/
10:34arbschtdon't use the one in contrib, that really is discontinued
10:35dmiller2718ClojureCLR is active. It is usable, but I wouldn't use it for production use yet.
10:35rsynnott_what's wrong with Clojure on the JVM, anyway? :)
10:35dmiller2718Needs more people banging on it.
10:35Fossiah. cool then
10:36arbschtdmiller2718: any plans to support mono?
10:36rsynnott_seems like a hard project to get off the ground, given the limited CLR support on any platform other than Windows
10:36Fossigiven that windows is still 90% of the market, maybe not so much
10:37dmiller2718No reason why it can't be on Mono eventually. It's based on DLR, and that runs on Mono. There is a still a reliance on one class in vjslib (BigDecimal) that needs to be gotten rid of.
10:38rsynnott_Fossi: rather less than 90% of the programmer market, though, and JVM works on 99.9% of the market
10:41Fossiwell, deplying a java desktop app to windows is still a pain though
10:42Fossialthough it is not so important anymore with the ubiquitious internet
10:52AWizzArdI have a big text file, which I currently load via read-lines. I would like to have Clojure compile that data into the .class file, so I don't have to deliver the text file. What is the idiom to do so?
10:53liwpAWizzArd: not exactly an answer to your question, but you could look into packaging the big text file into the jar that you distribute and then accessing it via the java resource methods
10:53liwpAWizzArd: i.e. the file would be 'hidden' from the user in the jar but still readable by the program
10:54jdzAWizzArd: or is it something like reading text file into Clojure (Java) data strutcures and then serializing them?
10:56AWizzArdIt's text data which gets compiled into a regex
10:58AWizzArdwhat liwp suggested sounds doable, although it would be even nicer when during the load of the .class file all needed data is automtically loaded.
10:58AWizzArdIn CL I would compile the regex and then dump an image for very fast load times.
11:00AWizzArdI already tried to make a single .clj file into which I put the long string. But it is too long and causes an exception :)
11:19tomojAWizzArd: java.util.regex.Pattern implements Serializable
11:20tomojoh but looks like they just serialize to the pattern string anyway
11:24ol3"520um_die_ecke_gedacht_03.swf"
11:24ol3(list "520um_die_ecke_gedacht_03.swf")
11:24ol3oops, sry
11:49Jomyoothow do I access an inner java class ?
11:49JomyootA.B
11:49JomyootB is defined inside A
11:50JomyootA.B or (. A B) do not work
11:50JomyootA.B
11:50Jomyoot(. A B ) do not work
11:50cgrandA$B
11:52ChousukeJomyoot: A$B, and you need to explicitly import the class
11:52Chousuke~inner class
11:52clojurebotNo entiendo
11:52Chousukehmm
11:52Jomyootdarn
11:52Jomyootthanks
11:53Chousukeclojurebot: inner class is <reply> To use an inner class Foo.Bar, import it with (import 'Foo$Bar), and you can refer to the class as Foo$Bar
11:53clojurebot'Sea, mhuise.
11:55Jomyoot,(int-array [ ])
11:55clojurebotjava.lang.NullPointerException
11:55Jomyoot,(int-array [1])
11:55clojurebot#<int[] [I@12bf469>
11:55Jomyootnow that's disturbing
11:55Jomyootwhy cannot i have a int[] with size of 0
11:55Chousuke,(into-array Integer/TYPE [])
11:55clojurebot#<int[] [I@74bff8>
11:56Chousukestill, I suppose that is a bug.
11:57ambientis there any way to tab-complete java classes in clojure/emacs and rapidly jump to java classes documentation?
11:57ambientlike (. frame <tab> lists all frame's methods
11:57Jomyoot,(into-array Integer/TYPE [1 2 3])
11:57clojurebot#<int[] [I@df980>
11:58Jomyootis into-array Integer/TYPE the same as int-array?
11:58ambientor (FooJavaClass/<tab> also lists the possible options
12:03Jomyoot,(int-array [1 2 3])
12:03clojurebot#<int[] [I@1059fd6>
12:06Fossidoing something to the leaves of a tree. hints?
12:07Jomyoot#<Timestamp 2009-08-29 22:47:07.0> is a java.sql.TimeStamp, right?
12:44hamzaanyone got etags to index .clj files?
13:06emacsenWe can't escape durka42 ;)
13:07durka42nope
13:08LauJensenJomyoot: Yes
13:14LauJensenGents, I was thinking of doing a follow up on this http://www.dzone.com/links/java_vs_clojure_lets_talk_ceremony.html either sticking with java/c# for a few posts or moving on to PHP/Python - any suggestions? :)
13:30ambientwhat i would be interested in is RoR or Django vs. web dev with Clojure
13:32ambientbtw i think you could do distinct with just putting and getting items out of a set. (referring to that linked article)
13:37LauJensenYea ok. Unfortunately I've only done webdev with C#/ASP, I'm blank on RoR/Django
13:37LauJensen(and ofc w. compojure)
13:38ambienti just think that Clojure being a lisp makes ORM and templating a bit different comparing to the traditional methods in OOP
13:38arbschtis compojure mature enough to warrant comparison? the api is unstable and even compojure.org isn't up yet
13:43rsynnott_ambient: that's a framework issue to an extent
13:43rsynnott_(it's not a language thing per se)
13:43ambientbut with lisp i think there's a more direct connection at least for templating
13:44rsynnott_well, there can be if you want it, I suppose
13:44rsynnott_there doesn't really _have_ to be
13:44rsynnott_(and in some cases it might be desirable to avoid it insofar as is possible)
13:45ambienti can't see the reasons for that
13:49cgrandambient: when you say "but with lisp i think there's a more direct connection at least for templating" do you think of something like cl-who ? http://weitz.de/cl-who/
13:49ambientafaik most frameworks are tightly bound to language features. i don't see the merit of abstracting to the level where frameworks become language independent
13:50ambientcgrand yes
13:52rsynnott_ambient: many people might like to avoid using cl-who or an analagous clojure thing (does one exist?)
13:52rsynnott_it's often desirable to have non-programmers edit templates, for instance
13:53arbschtcompojure uses nested structures like cl-who
13:53rsynnott_ah
13:54cgrandrsynnott_: several, eg http://github.com/mmcgrana/clj-html/tree/master and compojure.html
13:54arbschtbut you're not limited to it, as with cl-who on hunchentoot
13:55rsynnott_you're not limited to cl-who on hunchentoot
13:55arbschtright
13:55rsynnott_(oh, sorry, I misread that)
13:55snowwhiteping
13:56snowwhiteHow can i check the type of an input in clojure?
13:56arbscht,(class 42)
13:56clojurebotjava.lang.Integer
13:59snowwhiteHow can i check the type of an input in clojure? Anyone?
13:59arbscht,(type 42)
13:59clojurebotjava.lang.Integer
13:59arbschtsnowwhite: use one of those forms. type is more general (checks metadata before class)
14:02cgrandambient: to have designers edit templates was a key design decision for enlive
14:02LauJensenI think making Compojure / ClojureQL the target for a few blog posts is a very good idea
14:02Chouserbah. I'm confused again about where delays are required for finger-trees.
14:03ChouserThe bottom of page 7 says no delay is needed for cons/conj
14:04ChouserThe only other operations discussed at that point are the deques (and the later operations are only O(log n) anyway, I think). So that suggests delays are needed for rest/pop
14:06Chouserrest/pop may recurse on deep-left/deep-right, so I've added a print there so I can see when descents happen -- and without any delays at all, they appear to happen at the pace described earlier on that page as what constitutes amortized O(1) time.
14:06Chouserso ... is delay needed at all? I'm sure I'm missing something...
14:07ambientcgrand it's a lot better than designers just designing static pages and the programmers making them function?
14:07ambienti've only worked in an environment where everyone knew how to code
14:07ambientwho were doing webdev
14:08cgrandambient: yes it's when the design change after you started to code
14:09ambienti see
14:15rsynnott_it's often desirable to be able to have UI people modify templates without help
14:23snowwhiteI am trying to parse the json string. Here is the code snippet. Can anyone through some light?
14:24snowwhiteI am trying to parse the json string. Here is the code snippet http://pastebin.ca/1557501. I Can anyone through some light?
14:24snowwhiteI am trying to parse the json string. Here is the code snippet http://pastebin.ca/1557501. Can anyone through some light?
14:25slashus2snowwhite: Maybe you can refer to the implementation in clojure.contrib
14:25danlarkinsnowwhite: that looks right to me, what's the problem?
14:26slashus2snowwhite: Sorry, I thought you were trying to implement a json parser before I looked at your snippet.
14:27snowwhitedanlarkin: How do i extract the email from that vector. Inside the vector, it's not a map so that i can access it using keys
14:28danlarkin((first v) "email")
14:30snowwhitedanlarkin, ?
14:30danlarkinok, so you have a vector of two items, right? and each item has an "email" key and a "timestamp" key
14:30danlarkinso (first v) will be the first vector
14:31danlarkinand they you want the "email" key from that vector
14:31danlarkins/they/then
14:31danlarkindid I misunderstand what you want?
14:32danlarkinsorry, (first v) will be the first hash-map, not first vector
14:32snowwhiteI think it's not a hash-map any more
14:33snowwhiteother i could have done (filter (fn [map] (get map :email)) data)
14:33snowwhite*otherwise
14:33snowwhitedanlarkin, otherwise i could have done (filter (fn [map] (get map :email)) data)
14:34danlarkinno
14:34danlarkinthe keys in your hash-maps are not keywords
14:34danlarkinthey are strings
14:35danlarkinmaybe that's where you're getting confused
14:42snowwhitedanlarkin, (map (fn [d] (get d "email")) data) This should be the statement
14:42arbscht(map #(% "email") data)
14:42snowwhitedanlarkin, Thanks for helping me in clearing up my doubts. - Cheers
14:43snowwhitearbscht, Exactly. Thanks
14:46LauJensendanlarkin: Now that you're all warmed up. What are the major benefits of using Compojure/Clojure vs Django ?
14:46danlarkinhahah ummmmmm can I defer my response?
14:47LauJensensure
14:48danlarkinthat is a loaded question :)
14:48LauJensenAs always
15:07ambientLauJensen performance? java interop?
15:08LauJensenAny references that speak on performance?
15:09danlarkinLauJensen: is that to me? I had a stupid kernel panic, sorry
15:10LauJensendan, ambient mentioned performance and java-interop
15:10danlarkin:-o
15:13ambientwell nothing much except what can be found from google, http://berlinbrowndev.blogspot.com/2008/08/application-server-benchmarks-including.html
15:14LauJensenVery interesting... and very hard to compare graphs... Wonder why he picked a diffferent layout for each screenshot :)
15:18LauJensenBut to be fair, you really only need one graph when you have something as clear as this: http://1.bp.blogspot.com/_syI_yyzTPG8/SJ5vxo4-qAI/AAAAAAAAAKU/cXblzLJRuAc/s1600-h/graph_django_default.png
15:21ambientyes, that is very clear
15:23LauJensenBut I really dont like the trend of all the graphs, which is that PHP out performs everything else by a factor 10
15:37hiredmanwell php is a very simple language
15:40hiredmanI have a lisp interpreter in php and have been daydreaming^W thinking about a compiler that emits php
15:40hiredmanif you want to target php
15:40LauJensenI dont
15:41LauJensenJust wondering, why a language that got hammered in the language shootout, suddenly wins so big
15:43Fossigreat. i just discovered that emacs does not save back into jar files, even if it seems like it does
15:43Fossiso i can reimplement all those changes i made to the clojure-couchdb client yesterday
15:43danlarkinFossi: what? I believe it does
15:44hiredman:(
15:44hiredmansurely you made the changes to a git checkout, and commited the changes then built a jar :P
15:45Fossididn't do the trick for me. i thought so too
15:45Fossiit said saving yesterday all the time, but today my changes are gone
15:45Fossieven unjar'ed
15:45LauJensenM-x recover-this-file ?
15:45arbschtLauJensen: I'd guess it's optimized for serving dynamic content, not all the things the language shootout tests for
15:46danlarkinmaybe you're looking at a different jar, I've made modifications to a jar in emacs and they've persisted
15:46FossiLauJensen: i save backups to /tmp/ which gets wiped :D
15:46Fossidanlarkin: might be. let me try to open from emacs
15:47LauJensenFossi: Alright, not too bright :)
15:47Fossinope, no luck
15:48Chousukewhat's the point of saving backups to a place that gets deleted? :P
15:48Fossibut let me check if i have another copy around that might be the modified one
15:50LauJensenChousuke: I think if Emacs decided it was best to delete the code, it probably made the right call :)
16:00tomojI don't get it, how could emacs save into a jar?
16:00tomojemacs can open jar files as if they're directories or something?
16:05Chousuketomoj: why not? treating zip files as directories in not exactly a new idea.
16:06tomojoh, archive-mode
16:06tomojthat's kinda neat
16:07tomojseems like it would be better to do what hiredman said
16:16Fossitomoj: yes, seems like it to me as well now :D
16:16Fossidid somebody get fuzzy-completions to work?
16:17tomojFossi: not using the starter kit?
16:17tomojoh or do you mean in source buffers
16:18Fossi1) no, i don't know about a starter kit and b) yes, i'd like it in source buffers
16:18ChousukeFossi: works for me.
16:18ChousukeFossi: you need a fairly recent SLIME though
16:18Fossii can't figure it out. do i have to write a key binding and such?
16:18tomojI don't have any completions at all in source buffers :(
16:18ChousukeC-c M-i should work at least
16:19tomojsomewhat fuzzy completion on the slime repl, though
16:20FossiC-c M-i is undefined
16:20Chousukewait, hm.
16:20Chousukeare we talking about the same thing, even?
16:20ChousukeThere was a recent patch to swank-clojure that enable fuzzy completion through slime
16:20Fossithis: http://gist.github.com/179737 ?
16:21Chousukeyes
16:21ChousukeI had trouble getting it to work at first, but then it turned out to be because my SLIME was too old.
16:21Fossii don't even get what to do with the file, apart from putting it into swank/commands/contrib/
16:22ChousukeI just applied the patch with git :)
16:22tomojyour modeline should have "Slime[clojure]" in it
16:23Chousukewhere did you install SLIME from?
16:24ChousukeI had SLIME cloned from technomancy's github repo, which turned out to be from May :/
16:24Chousukeand it was too old
16:24Fossimy repl has REPL in it
16:25Fossii have a slime checkout of 25 june
16:25Chousuketry upgrading
16:26Chousukehopefully you have it from a git mirror so you can easily save the current state in a branch? :)
16:26Fossiah, i can revert
16:26Fossibranching is for wussies
16:26ChousukeI wonder why anyone would use CVS nowadays.
16:26Chousukeor SVN.
16:26Chousukeexcept when forced to.
16:27ChousukeWell, SVN might be okay if you have to store binary files.
16:28Fossimy repl still says REPL
16:28Fossinothing about SLIME[clojure]
16:28Chousukeoh, wait, the REPL buffer will say that
16:28Chousukewhat about clojure buffers?
16:29Chousukethey should also say "Fuzzy"
16:29Fossiit says "Slime"
16:29Chousukehmm.
16:29snowwhiteFossi, Nice article on Setting up Emacs & Clojure with Emacs Starter Kit http://freegeek.in/blog/2009/08/setting-up-emacs-clojure-with-emacs-starter-kit/
16:30Fossisnowwhite: well, now that i have it set up more or less, i'm not sure i should use it
16:30ChousukeFossi: can you even do M-x slime-fuzzy-complete-symbol?
16:31Chousukehow do you load slime from your config?
16:31snowwhiteFossi, Cool
16:31Fossialso, i have a ton of stuff in my .emacs and .emacs.d
16:31Chousukeif you do just (slime-setup), that won't work :/
16:31Chousukeyou need (slime-setup '(slime-fancy))
16:31Chousuketo get the good stuff :)
16:32Fossino slime-fu for me :\
16:33Fossiactually, i guess my slime setup code is broken as is anyway
16:33Fossii always have to M-x slime
16:33Chousukethat doesn't mean it's broken.
16:33Chousukeit's not automatic by default anyway
16:37ChousukeFossi: http://github.com/Chousuke/emacs.d/blob/d826d63420dcdc90db639a4d3390a8c3773c8deb/init-clojure.el here's how I do it.
16:42FossiChousuke: ah, now it says slime[clojure]
16:44Fossiand C-c M-i is bound to fuzzy complete as well
16:47FossiChousuke: thanks, now i just have to find out what it actually completes :)
17:52technomancyChousuke: so that fuzzy patch worked for you?
17:52technomancyI locked clojure-mode into using last-known-good revisions by default since so many people were complaining about breakage.
17:52technomancybut if there's a reason to update, I will definitely do it
17:58Chousuketechnomancy: yeah, it does
18:02technomancycool
18:10ambient*sigh* i dont know how to integrate java better to emacs but it's a bit laborious to browse the net for each method in each class when doing java interop
18:15technomancyambient: do you know about the Slime inspector?
18:15ambientno
18:15technomancyC-c I over a java object, and it will list out all its methods
18:16technomancybeen meaning to hook that into autocomplete, but the information is definitely there
18:16technomancythere's also a separate javadoc lookup package, but it's kind of awkward to use.
18:16ambientoh, i have to write that down :)
18:16technomancyyeah, it's super-helpful
18:17ambientthanks
19:11prospero_,(map println '(1 2 3))
19:11clojurebot(nil nil nil)
19:11prospero_hmm
19:11prospero_that's not what I'm getting at my repl
19:12hiredman~map
19:12clojurebotmap is *LAZY*
19:13prospero_yes, but doesn't it get evaluated at the repl?
19:13hiredmanit does, while it is getting printed out
19:13prospero_the output and printing is getting spliced together for me
19:13prospero_ah
19:13prospero_right
19:13prospero_the result and the printing, rather
19:13prospero_so that makes sense, I guess
19:14prospero_if I want to separate them I need to write to a string or something, right?
19:14hiredman,(doc with-out-str)
19:14clojurebot"([& body]); Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls."
19:15hiredmanbut, you also have to watchout because map is lazy, and may be evauluated outside any dynamic bindings
19:15prospero_so I should realize the seq with doall?
19:15hiredmanfor side effect things like printing doseq is better
19:15hiredman,(doc seq)
19:15clojurebot"([coll]); Returns a seq on the collection. If the collection is empty, returns nil. (seq nil) returns nil. seq also works on Strings, native Java arrays (of reference types) and any objects that implement Iterable."
19:15hiredman,(doc doseq)
19:15clojurebot"([seq-exprs & body]); Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by \"for\". Does not retain the head of the sequence. Returns nil."
19:15prospero_I'm just trying to debug a recursive function
19:16prospero_printing what's going on at each level
19:16prospero_so with-out-str sounds like a good bet
19:16hiredmanis there a reason you just don't print the results of the map?
19:17hiredman,(prn (map inc (range 10)))
19:17clojurebot(1 2 3 4 5 6 7 8 9 10)
19:17hiredmanor whatever list
19:17prospero_I'm not actually using map, it was just a good way to demonstrate the behavior I was seeing
19:17prospero_I'm walking a tree
19:18prospero_anyways, with-out-str seems to be working
19:18prospero_thanks
20:36technomancydoes anyone use the subprocess support included in clojure-mode rather than the full-fledged SLIME support?
20:36technomancynever actually heard of anyone using it
20:37Chousukesubprocess support?
20:37technomancyit's got some simplistic support for running Clojure in a subprocess and sending the current buffer to it
20:37technomancya small subset of what slime offers
20:38Chousukeisn't that what inferior-lisp is for? :/
20:40Chousuketechnomancy: have you considered adding support for launching multiple slime instances with clojure-project?
20:40Chousukeor should I say Clojure instances :/
20:43ChousukeHm, gotta go to sleep. later.
20:46technomancyChousuke: I'd accept a patch, but I run one Emacs instance per project myself.
20:46technomancyso I would be unlikely to add it myself
20:46technomancyI guess what I'm talking about in clojure-mode is the inf-lisp integration
20:57somniumany vimclojure users online?
21:31somniumis there a std library function to return the first item in a seq for which a pred returns true?
21:31somnium(I wrote one but would be embarassed to show it...)
21:35shachafsomnium: Why?
21:36somniumbecause its ugly, and its an extremely typical operation :)
21:36somnium,(first (drop-while #(x < 5) [1 2 3 4 5 6 7 8 9]))
21:36clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--4159$fn
21:37somniumgr
21:37somnium ,(first (drop-while #(% < 5) [1 2 3 4 5 6 7 8 9]))
21:37shachafsomnium: Well, if the functions are lazy then that should be fine.
21:38somniumwhered he go...
21:38somniumah, true, I forgot about that
21:38somniumstill haven't quite grasped laziness
21:38shachafI don't know anything about Clojure, though; I should probably not have spoken in the first place. :-)
21:39somnium,(print "still here?")
21:39clojurebotstill here?
21:40hiredmanclojure is not lazy
21:40somnium ,(first (drop-while #(< % 5) [1 2 3 4 5 6 7 8 9]))
21:40hiredmanlazy sequences are lazy
21:40shachafhiredman: I read "Most of the sequence library functions are lazy".
21:40shachafI didn't investigate it further.
21:41somniumhiredman: is there a function in core or contrib to return the first item in a seq via pred?
21:43hiredman(comp first filter)
21:44hiredmanthere was a thrad on the google group about adding a function to contrib somewhere, but I forget if it ever was
21:44somniumah
21:45somniumsome things like that would increase the "user-friendliness" fact imho, but its easy now that I see it
21:45somniumand I guess thats much more flexible to specify (nth ...) or whatever
21:46somnium... I think I had a semi-"lisp enlightenment" moment the other day
21:47somniumwas writing a gtk-wrapper in ruby, and couldn't get a really pleasing syntax without some form of xml
21:47somniumand it clicked
21:59somnium(comp first filter)
23:10manic12I watched clojure for lisp programmers and my brain hurt afterward
23:12technomancythat pain is weakness leaving the body
23:12manic12I don't know how to use the language yet, but i noticed it seems to work on JamVM running on ARM9
23:13technomancymmm... Jam.
23:14manic12my brain is so wired for common lisp, that I feel actually like I'm at a disadvantage
23:15technomancycould be a lot worse
23:21duck1123manic12: just remind yourself that clojure is absolutely nothing like common lisp in any way whatsoever. That way you'll never be surprised.
23:22dthomasHow should I find the index of the first occurrence of a given item in a vector? Or should I be using some other data type, like sorted-set or a map?
23:22dthomas(I see there's an (index) in docs but it's not clear if it does what I want and it doesn't seem to be in Clojure 1.0 anyway.)
23:24manic12I have a large c++ library swigged into CL and I am thinking of reworking the interface files to be for java, and i am contemplating how well it might work in a clojure world
23:28manic12i hope java has finalizations
23:43dthomasGetting the index of something in a vector really seems like it should be obvious and brief...
23:44technomancysweet; jochu merged the fuzzy-find patch. =)
23:46_mst,(.indexOf [1 2 3 "hello" 4 5 6] "hello")
23:46clojurebot3
23:47technomancywow, it's quite the patch
23:47dthomas_mst: [expletive deleted]
23:48_mstI'm hoping I'm not relying on implementation-dependent behaviour in doing that :)
23:52dthomas_mst: I guess that's because a PersistentVector is a java.util.List. Thanks for that.
23:53_mstyep, I think so. I couldn't see anywhere in the docs that said vectors were guaranteed to be Lists, but oh well :)
23:58dthomasHoly crap, repl-utils/show is awesome.