#clojure log - Sep 07 2009

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

3:50 joha1: I cannot find any example of connecting clojure.contrib.sql to an Oracle DB. Can anyone help?

3:51 Is it possible/tested at all?

4:00 nm, it works now

4:07 added 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

4:37 From 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?

4:39 Chousuke: use read-string first

4:39 ,(doc read-string)

4:39 clojurebot: "([s]); Reads one object from the string s"

4:39 joha1: ah, thanks

4:39 Chousuke: beware of #=() though

4:40 ,'#=(println "foo") ; read-time evaluation

4:40 clojurebot: foo

4:40 joha1: ok, will keep it in mind. Should be enough for my needs anyway, so thanks again

4:50 jdz: or bind *read-eval* to false

4:51 ,(binding [*read-eval* false] (read-string "#=(println foo)"))

4:51 clojurebot: java.lang.RuntimeException: java.lang.Exception: EvalReader not allowed when *read-eval* is false.

5:12 LauJensen: Gents, can I have some thoughts? http://bestinclass.wordpress.com/2009/09/07/java-vs-clojure-lets-talk-ceremony/

5:22 liwp: LauJensen: 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,

5:22 but it takes a longer time to write that code.

5:23 LauJensen: Ok I see your point

5:23 It was meant in the context of ceremony

5:24 liwp: yeah, and it makes sense if you read it that way and I agree with the sentiment :-)

5:24 LauJensen: But if you can get to the bottom without strong grievances I'll post it on DZone :)

5:25 liwp: Ok, I'll get back to you when I'm done with it (might be a while, I'm at work)

5:25 LauJensen: Fair enough - Dont get in any trouble on my account :)

5:26 jdz: "since is a functional language"

5:26 LauJensen: thx

5:26 Very succint text

5:26 jdz: and the sentence should end with "in the core" i think

5:27 LauJensen: k

5:27 jdz: but i'm not native english speaker

5:27 LauJensen: Me neither :)

5:27 jdz: "not wanting win" -> "not wanting to win"

5:28 LauJensen: good catch

5:28 jdz: i wouldn't call let a macro

5:28 maybe just form

5:28 LauJensen: A true, its a special form

5:29 jdz: "it's" :)

5:30 liwp: LauJensen: I think you'll end up getting a lot of hatemail from Java developers!-)

5:30 jdz: "if i wanted ... I needed" -> "if i wanted ... I would need", but not completely sure

5:30 LauJensen: I certainly hope so

5:30 liwp: LauJensen: but more seriously, I think you're example has some holes in it

5:30 jdz: "your"

5:30 LauJensen: liwp: Like what?

5:30 liwp: LauJensen: e.g. the import list can be reaplaced with "import java.util.*"

5:31 LauJensen: liwp but to a different effect

5:31 liwp: LauJensen: I agree with you, but this is what the Java devs are going to say

5:31 LauJensen: True - Maybe I should prepare my defences

5:32 liwp: LauJensen: also the iterator creation is unnecessary with the new for syntax: for (String s : list) { ... }

5:32 which reduces a whole bunch of lines from your example

5:32 LauJensen: liwp: Spell it out for me

5:32 liwp: ~paste

5:32 clojurebot: lisppaste8, url

5:32 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

5:33 liwp: LauJensen: urgh, you're code is an image rather than text so I can't copy paste it!

5:33 LauJensen: sec

5:33 lisppaste8: Lau pasted "for liwp" at http://paste.lisp.org/display/86700

5:33 LauJensen: You can annote that

5:34 liwp: LauJensen: ok, give me a minute

5:34 LauJensen: you got it

5:35 lisppaste8: liwp annotated #86700 "untitled" at http://paste.lisp.org/display/86700#1

5:37 LauJensen: If you were to completely mimic the first one, you'd be down from 28 to 22. Thanks alot for the input - I didnt know :)

5:37 miha: ,(+ 1 2)

5:37 clojurebot: 3

5:37 liwp: And 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

5:37 so that would take another ~5 lines away from the java example

5:39 LauJensen: 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

5:40 LauJensen: liwp -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 :)

5:41 lisppaste8: liwp annotated #86700 "untitled" at http://paste.lisp.org/display/86700#2

5:41 liwp: LauJensen: I think your java hatemail will include something like the last annotation

5:41 LauJensen: hehe, nice

5:42 liwp: that's 14 lines I think, so still longer than your clojure version

5:42 Chousuke: the java-like clojure code is not very idiomatic either I think. hmm.

5:42 LauJensen: 17

5:43 liwp: but you can also fiddle with the formatting to make the Java shorter / clojure longer

5:43 LauJensen: Oh, one final thing is that your class name should be Capitalised

5:44 LauJensen: I 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

5:44 liwp: someone's going to point that out in your comments and call you a Java newby ;)

5:45 LauJensen: 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

5:45 LauJensen: liwp: Dont ever get me wrong: I dont want converts :)

5:46 Chousuke: ,(reduce (fn [acc item] (if (some (partial = item) acc) acc (conj acc item))) [] ["foo" "bar" "zonk" "foo"]) ; explicit loops are ugly

5:46 clojurebot: ["foo" "bar" "zonk"]

5:46 jdz: comparing languages using small examples like that will inevitably turn into language flamewars

5:46 liwp: jdz: exactly

5:47 LauJensen: liwp: I'm extending the conclusion as we speak

5:47 Chousuke: reduce is something that's a basic functional tool so it's rather like the for loop special syntax in the java code :P

5:47 and you can't write a reduce in Java without even more ceremony.

5:48 LauJensen: Its updated, I think that'll discourage the first few haters

5:48 liwp: Chousuke: 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

5:48 Chousuke: I use #() most of the time I think

5:49 #(= item %) just looks a bit noisy

5:49 LauJensen: Chousuke: Your example is very nice for me, but for an uknowing crowd its perlishly nasty

5:49 Chousuke: LauJensen: the loop code is even worse though :P

5:49 liwp: heh, I'd prefer that, I think, to (partial = item)...

5:49 LauJensen: Its readable for people coming from imperative languages

5:50 Chousuke: LauJensen: but it looks noisy compared to the java loop :/

5:50 (because it's denser)

5:50 eevar2: LauJensen: why use a loop at all?

5:50 LauJensen: Hmm, yes... I'm reconsidering

5:50 Its not bad actually

5:51 Chousuke: include both, just to show that explicit loops are often not needed.

5:51 eevar2: the Java approach would be something like Set uniques = new HashSet( arrayListOfStrings );

5:51 liwp: eevar2: true!

5:51 Chousuke: eevar2: you mean like (vec (set arraylist))?

5:51 ol3: ,(doc slurp)

5:51 clojurebot: "([f] [f enc]); Reads the file named by f using the encoding enc into a string and returns it."

5:51 liwp: like jdz said, these thing will inevitably end up in flame wars

5:52 LauJensen: Chousuke: I think I'll go with yours, I assume thats okay

5:52 Chousuke: sure.

5:53 eevar2: Chousuke: yup. writing convoluted code for simple stuff like this makes both languages look bad ;)

5:54 s/convoluted/naive/

5:57 ol3: hello, clojure-bot supports an encoding for slurp my clojure did not. I have clojure 1.0, what is its default encoding?

5:57 jdz: depends on your JVM

5:57 and environment

5:58 but you can specify one with -Dfile.encoding when starting JVM

5:58 LauJensen: I updated the post. I think its good now :)

5:59 jdz: ol3: but relying on system supplied defaults will get you into trouble sooner or later, anyway

5:59 ol3: I want to specify the encoding at runtime, so i don't use slurp, right?

6:00 jdz: i guess so

6:00 i have written a utility function for myself

6:00 should be somewhere on lisppaste

6:01 others also have provided their versions

6:01 dunno why the encoding stuff is not in the core

6:02 ol3: maybe it will

6:02 ,(doc slurp)

6:02 clojurebot: "([f] [f enc]); Reads the file named by f using the encoding enc into a string and returns it."

6:02 jdz: oh, see, you can specify the encoding :)

6:02 i still use my own version

6:02 http://paste.lisp.org/display/80970

6:03 because i want to read compressed files

6:04 ol3: but encoding is not in the 1.0 version

6:04 Chousuke: Why are you not using BufferedReader or something? :/

6:05 jdz: because my Java-fu is lacking maybe

6:05 Chousuke: (BufferedReader. (InputStreamReader. (SomeInputStream. ...)))

6:08 LauJensen: ok guys, its live: http://www.dzone.com/links/java_vs_clojure_lets_talk_ceremony.html

6:08 Thanks a lot everybody for taking the time

6:08 ol3: Chousuke: thanks, looks good

6:09 Chousuke: There might be more specialised readers than InputStreamReader though.

6:09 check the docs :)

6:10 jdz: ye, i use FileInputStream

6:11 but thanks for pointing this out

6:11 the buffering exercise was fun, anyway

6:11 Chousuke: LauJensen: your idiomatic clojure code is missing a [

6:12 LauJensen: (let [lst "foo" "bar" ...

6:12 jdz: i was just learning Clojure at that time

6:12 LauJensen: thanks for staying awake Chousuke

6:12 eevar2: LauJensen: why do you import java.util.List when you never use the interface?

6:12 LauJensen: eevar2: artifact, thanks for pointing it out

6:15 jdz: also, the indentation of clojure code is very un-ideomatic

6:15 and why is the code in images, anyway?

6:16 LauJensen: wordpress.com doesnt to very nice code highlighting

6:16 jdz: does it accept html?

6:16 LauJensen: yep

6:17 Chousuke: SVG images!

6:17 jdz: LauJensen: what editor are you using?

6:17 LauJensen: For?

6:17 jdz: making the code images

6:18 LauJensen: gnome-text

6:18 ol3: you code use the <pre> tag, highlighting is overrated

6:18 LauJensen: ol3 alright, I'll try that the next time

6:18 images arent optimal

6:19 ol3: if you really need highlighting, there is an htmlize package for emacs

6:19 http://www.emacswiki.org/emacs/Htmlize

6:20 LauJensen: Sweeet :)

6:21 lisppaste8: jdz pasted "ideomatic clojure code in emacs" at http://paste.lisp.org/display/86702

6:21 jdz: using htmlize :)

6:23 and the let error is even preserved :)

6:24 ol3: most of the time i do not use font-lock anymore...

6:25 jdz: pretty colors are essential for things published on the interwebs

6:30 ol3: really? IMHO people only think there is an advantage in highlighting, because it looks nice/cool, but where is the real benefit?

6:30 LauJensen: speed

6:30 ol3: speed?

6:31 LauJensen: yea, your eyes dont need to read everything, they bounce of the colors to the places you need to go, its grooooovy man :)

6:32 ol3: I think this is an illusion, are there tests about this?

6:32 LauJensen: Dont need tests, its evident

6:32 jdz: i'm pretty sure having colors helps with navigation

6:32 Chousuke: the colours help make the structure clearer to me.

6:33 processing colour takes less mental effort than processing the actual text

6:33 so if I can ignore parts of code based on its colour, I am more efficient :)

6:34 and on the other hand, I might focus better on parts with an "important" colour

6:34 hiredman: at the very least rainbow parens are a must

6:34 jdz: not

6:34 Chousuke: not to me

6:34 hiredman: :/

6:34 they are great

6:34 Chousuke: I don't even look at parens much nowadays.

6:34 jdz: proper indentation is a must

6:35 Chousuke: I don't need to care which paren ends which expression because I know paredit takes care of that :)

6:35 ol3: nope, the defn/defun is not important, it's at the beginning of the line anyway

6:36 but nevermind, people are different

6:36 jdz: well, i'm more concerned with colorization of strings

6:37 Chousuke: the other thing is that colours are much more pleasant than just grey text

6:37 at least, when they have purpose.

6:37 _mst: the differences are interesting... I've always turned my syntax highlighting back to bold or not bold :)

7:49 ol3: is there a standard way to update a map in a map?

7:50 (dosync (alter map assoc :other-map (assoc (:other-map @map) :key :new-value)))

7:50

7:51 @r

8:00 cgrand: (doc assoc-in)

8:00 clojurebot: "([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."

8:00 cgrand: (doc update-in)

8:00 clojurebot: "([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."

8:01 cgrand: ol3: (dosync (alter map assoc-in [:other-map :key] :new-value))

8:04 ol3: cgrand: thank you

8:06 this is really cool!

8:07 ,(assoc-in nil [:this :is :a :deep :structure] :value)

8:07 clojurebot: {:this {:is {:a {:deep {:structure :value}}}}}

8:08 cgrand: update-in and dissoc-in are cool too

8:09 ol3: (doc dissoc-in)

8:09 clojurebot: "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."

8:11 ol3: (doc dissoc-in)

8:11 clojurebot: "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."

8:11 ol3: works even if keys are string

8:13 Chousuke: works with vectors too

8:13 at least, IIRC.

8:14 ,(update-in [2 [1 2 3]] [1 2] inc)

8:14 clojurebot: [2 [1 2 4]]

8:19 ol3: why are references funcallable?

8:20 just curious

8:21 cgrand: last time I asked, Rich told me to not rely on that -- it's undocumented

8:22 I guess it may be some legacy from the time where refs and vars were the same thing

8:23 ol3: so always use the @, ok

8:57 hamza: (doto frame (..) (.pack) (...)), pack call causes classcastexception?

8:58 hiredman: lisppaste8: url

8:58 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

8:58 hiredman:

8:59 lisppaste8: hamza pasted "snake" at http://paste.lisp.org/display/86708

8:59 hamza: it's the example from programming clojure..

9:01 hiredman: what page?

9:01 jdz: the .pack call is commented out, though

9:02 hiredman: did you copy it out of the book, or have you tried from the source repo?

9:02 hamza: i copied from the book, i was testing if setSize would work thats why its commented out, with setSize it works but .pack causes exception

9:04 hiredman: ah

9:04 you miscopied

9:05 you are missing two * in game-panel

9:05 hand copying a large chunk of code like can be troublesome

9:06 hamza: what am i missing?

9:06 hiredman: you are missing two calls to *

9:06 the parens are there

9:07 so you have two numbers there

9:07 ,(1 2)

9:07 clojurebot: java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn

9:07 emacsen: What's the proper way to overload a function name that's used in the core?

9:07 hiredman: ^-

9:07 ,(doc refer-clojure)

9:07 clojurebot: "([& filters]); Same as (refer 'clojure.core <filters>)"

9:07 hiredman: ,(doc refer)

9:07 clojurebot: "([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

9:08 emacsen: thx

9:08 hiredman: refer-clojure has a corresponding :refer-clojure for the ns for

9:08 form

9:08 emacsen: "name" fits my problemset too well

9:09 Jomyoot: How to define a function that takes variable number of inputs [a b] and [a b c]

9:09 I cannot (defn) twice

9:09 it erases the first (defn)

9:09 emacsen: Jomyoot, read the section on multiple arity

9:09 Jomyoot: in Java, I would just define the function twice with different inputs

9:10 emacsen: Jomyoot, functions can take multiple forms

9:10 hiredman: Jomyoot: there are many ways

9:10 emacsen: Jomyoot: http://clojure.org/functional_programming

9:10 achim: for example (defn foo ([a b] ...) ([a b c] ...)), or (defn foo [a b & [c]] ...)

9:10 emacsen: read the section on multiple arity

9:11 Jomyoot: thanks

9:11 hiredman: ,((fn ([a] a) ([a b] [a b])) 1)

9:11 clojurebot: 1

9:11 hiredman: ,((fn ([a] a) ([a b] [a b])) 1 2)

9:11 clojurebot: [1 2]

9:13 emacsen: hiredman, thx for your help

9:15 and what's the current prefered pretty-printer?

9:16 hiredman: ~scala (0 /: List(1,2,3))(_ + _)

9:16 clojurebot: Int = 6

9:16 * hiredman giggles

9:17 jdz: emacsen: clojure.contrib/pprint

9:18 liwp: hiredman: huh?

9:18 is that a reduce?

9:18 hiredman: I don't know scala

9:18 * liwp knows no scala

9:18 liwp: ok then :)

9:18 ~scala (0 /: List(1,2,3,4))(_ + _)

9:18 clojurebot: Int = 10

9:19 liwp: I guess so

9:19 emacsen: clojure.contrib.pprint.PrettyWriter [Thrown class java.lang.ClassNotFoundException]

9:19 liwp: ~scala (1 /: List(1,2,3,4))(_ * _)

9:19 clojurebot: Int = 24

9:19 ol3: is the 'Programming Clojure' book good?

9:19 hiredman: you neeed to compile contrib properly

9:19 emacsen: hiredman, what do you mean by properly? :)

9:20 liwp: emacsen: with ant

9:20 hiredman: emacsen: run ant, and looking for a line with "Warning" in it, and follow the directions

9:20 emacsen: hiredman, ah, good point. I didn't compile clojure.contrib at all

9:20 at least not the slime used one

9:20 jdz: emacsen: clojure.contrib.pprint/pprint i think the function is named

9:20 emacsen: thx

9:20 hiredman: well there is no clojure.contrib

9:21 Chouser: ~scala ( for( i <- 1 to 100 ) yield i * i ).foldLeft(0) ( _ + _ )

9:21 clojurebot: Int = 338350

9:30 AWizzArd: The 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?

9:30 Chousuke: AWizzArd: Flags§Flag/SEEN

9:30 er

9:30 $*

9:30 hiredman: haha

9:31 AWizzArd: Chousuke: unfortunately not

9:31 ah

9:32 what works is javax.mail.Flags$Flag/SEEN

9:32 but Flags$Flag/SEEN not, although I imported Flags

9:33 I get at java.lang.Exception: No such namespace: Flags$Flag when I do Flags$Flag/SEEN

9:33 cgrand: AWizzArd: you need to import Flags$Flag

9:33 AWizzArd: oh nice :)

9:34 yes, that works

9:34 thx

9:47 ol3: is there a prog1 in clojure

9:49 hiredman: do

9:49 jdz: umm, not really

9:49 hiredman: ok

9:49 jdz: ,(doc do)

9:49 clojurebot: I don't understand.

9:50 ol3: ,(doc 'do)

9:50 hiredman: ~progn

9:50 clojurebot: java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol

9:50 Excuse me?

9:50 hiredman: do is a special form

9:50 ol3: to be more specific, i need a queue , one thread enques values another dequeues values

9:50 jdz: ol3: well you can write a simple macro with a let + do

9:51 AWizzArd: you could try a clojure.lang.PersistentQueue

9:51 jdz: ol3: then prog1 is completely not the tool for you

9:51 hiredman: ,(conj (clojure.lang.PersistentQueue/empty) 1)

9:51 clojurebot: java.lang.NoSuchFieldException: empty

9:51 hiredman: ,(conj (clojure.lang.PersistentQueue/EMPTY) 1)

9:51 clojurebot: (1)

9:52 hiredman: ,(peek (conj (clojure.lang.PersistentQueue/EMPTY) 1))

9:52 clojurebot: 1

9:52 hiredman: ,(pop (conj (clojure.lang.PersistentQueue/EMPTY) 1))

9:52 clojurebot: ()

9:52 hiredman: ,(pop (conj (clojure.lang.PersistentQueue/EMPTY) 1 2 3))

9:52 clojurebot: (2 3)

9:53 AWizzArd: like lists, but you conj to the end

9:53 jdz: ,(conj (PersistentQueue/EMPTY) 1)

9:53 clojurebot: java.lang.Exception: No such namespace: PersistentQueue

9:53 ol3: ah, this is exactly what i needed, thank you!

9:53 AWizzArd: right, it is undocumented and a little bit hidden :)

9:54 jdz: isn't clojure.lang used by default?

9:54 hiredman: nope

9:54 ,(import 'clojure.lang.PersistentQueue)

9:54 clojurebot: clojure.lang.PersistentQueue

9:54 jdz: ,(conj (PersistentQueue/EMPTY) 1)

9:54 clojurebot: (1)

9:54 jdz: hehe, until next reboot i guess :)

9:55 AWizzArd: you could (import 'clojure.lang.PersistentQueue) first

9:55 oh, hiredman was faster :)

9:57 jdz: is it possible to blow up clojurebot by importing too many namespaces?

9:58 Jomyoot: How to convert [1 2 3] into Java Array {1, 2, 3}

9:58 AWizzArd: ,(to-array [1 2 3])

9:58 clojurebot: #<Object[] [Ljava.lang.Object;@57e9bb>

9:59 hiredman: ,(into-array [1 2 3])

9:59 clojurebot: #<Integer[] [Ljava.lang.Integer;@150ad83>

9:59 AWizzArd: another alternative

9:59 hiredman: ,(into-array Integer/TYPE [1 2 3])

9:59 clojurebot: #<int[] [I@196a671>

9:59 AWizzArd: ,(int-array 3 [1 2 3])

9:59 Jomyoot: what's difference?

9:59 clojurebot: #<int[] [I@419710>

9:59 AWizzArd: Jomyoot: performance

10:00 Jomyoot: i think i need int-array

10:00 hiredman: Jomyoot: the type of the array

10:00 the first one is an array of Objects

10:00 the second an array of Integers, the third ints

10:00 Jomyoot: ,(int-array [1 2 3])

10:00 clojurebot: #<int[] [I@bc03b>

10:24 ambient: anyone tried Clojure on the CLR? is it usable?

10:32 Fossi: as in .NET?

10:33 i thought that was discontinued until new-new is done

10:33 ambient: oh ok :)

10:33 arbscht: really, when?

10:33 Fossi: i thought reimplementing all the persistent datastructures is just a little too painful :)

10:34 arbscht: looks active to me http://github.com/richhickey/clojure-clr/

10:34 don't use the one in contrib, that really is discontinued

10:35 dmiller2718: ClojureCLR is active. It is usable, but I wouldn't use it for production use yet.

10:35 rsynnott_: what's wrong with Clojure on the JVM, anyway? :)

10:35 dmiller2718: Needs more people banging on it.

10:35 Fossi: ah. cool then

10:36 arbscht: dmiller2718: any plans to support mono?

10:36 rsynnott_: seems like a hard project to get off the ground, given the limited CLR support on any platform other than Windows

10:36 Fossi: given that windows is still 90% of the market, maybe not so much

10:37 dmiller2718: No 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:38 rsynnott_: Fossi: rather less than 90% of the programmer market, though, and JVM works on 99.9% of the market

10:41 Fossi: well, deplying a java desktop app to windows is still a pain though

10:42 although it is not so important anymore with the ubiquitious internet

10:52 AWizzArd: I 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:53 liwp: AWizzArd: 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:53 AWizzArd: i.e. the file would be 'hidden' from the user in the jar but still readable by the program

10:54 jdz: AWizzArd: or is it something like reading text file into Clojure (Java) data strutcures and then serializing them?

10:56 AWizzArd: It's text data which gets compiled into a regex

10:58 what 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:58 In CL I would compile the regex and then dump an image for very fast load times.

11:00 I 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:19 tomoj: AWizzArd: java.util.regex.Pattern implements Serializable

11:20 oh but looks like they just serialize to the pattern string anyway

11:24 ol3: "520um_die_ecke_gedacht_03.swf"

11:24 (list "520um_die_ecke_gedacht_03.swf")

11:24 oops, sry

11:49 Jomyoot: how do I access an inner java class ?

11:49 A.B

11:49 B is defined inside A

11:50 A.B or (. A B) do not work

11:50 A.B

11:50 (. A B ) do not work

11:50 cgrand: A$B

11:52 Chousuke: Jomyoot: A$B, and you need to explicitly import the class

11:52 ~inner class

11:52 clojurebot: No entiendo

11:52 Chousuke: hmm

11:52 Jomyoot: darn

11:52 thanks

11:53 Chousuke: clojurebot: 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:53 clojurebot: 'Sea, mhuise.

11:55 Jomyoot: ,(int-array [ ])

11:55 clojurebot: java.lang.NullPointerException

11:55 Jomyoot: ,(int-array [1])

11:55 clojurebot: #<int[] [I@12bf469>

11:55 Jomyoot: now that's disturbing

11:55 why cannot i have a int[] with size of 0

11:55 Chousuke: ,(into-array Integer/TYPE [])

11:55 clojurebot: #<int[] [I@74bff8>

11:56 Chousuke: still, I suppose that is a bug.

11:57 ambient: is there any way to tab-complete java classes in clojure/emacs and rapidly jump to java classes documentation?

11:57 like (. frame <tab> lists all frame's methods

11:57 Jomyoot: ,(into-array Integer/TYPE [1 2 3])

11:57 clojurebot: #<int[] [I@df980>

11:58 Jomyoot: is into-array Integer/TYPE the same as int-array?

11:58 ambient: or (FooJavaClass/<tab> also lists the possible options

12:03 Jomyoot: ,(int-array [1 2 3])

12:03 clojurebot: #<int[] [I@1059fd6>

12:06 Fossi: doing something to the leaves of a tree. hints?

12:07 Jomyoot: #<Timestamp 2009-08-29 22:47:07.0> is a java.sql.TimeStamp, right?

12:44 hamza: anyone got etags to index .clj files?

13:06 emacsen: We can't escape durka42 ;)

13:07 durka42: nope

13:08 LauJensen: Jomyoot: Yes

13:14 Gents, 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:30 ambient: what i would be interested in is RoR or Django vs. web dev with Clojure

13:32 btw i think you could do distinct with just putting and getting items out of a set. (referring to that linked article)

13:37 LauJensen: Yea ok. Unfortunately I've only done webdev with C#/ASP, I'm blank on RoR/Django

13:37 (and ofc w. compojure)

13:38 ambient: i just think that Clojure being a lisp makes ORM and templating a bit different comparing to the traditional methods in OOP

13:38 arbscht: is compojure mature enough to warrant comparison? the api is unstable and even compojure.org isn't up yet

13:43 rsynnott_: ambient: that's a framework issue to an extent

13:43 (it's not a language thing per se)

13:43 ambient: but with lisp i think there's a more direct connection at least for templating

13:44 rsynnott_: well, there can be if you want it, I suppose

13:44 there doesn't really _have_ to be

13:44 (and in some cases it might be desirable to avoid it insofar as is possible)

13:45 ambient: i can't see the reasons for that

13:49 cgrand: ambient: 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:49 ambient: afaik 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:50 cgrand yes

13:52 rsynnott_: ambient: many people might like to avoid using cl-who or an analagous clojure thing (does one exist?)

13:52 it's often desirable to have non-programmers edit templates, for instance

13:53 arbscht: compojure uses nested structures like cl-who

13:53 rsynnott_: ah

13:54 * rsynnott_ hasn't really looked at compojure

13:54 cgrand: rsynnott_: several, eg http://github.com/mmcgrana/clj-html/tree/master and compojure.html

13:54 arbscht: but you're not limited to it, as with cl-who on hunchentoot

13:55 rsynnott_: you're not limited to cl-who on hunchentoot

13:55 arbscht: right

13:55 rsynnott_: (oh, sorry, I misread that)

13:55 snowwhite: ping

13:56 How can i check the type of an input in clojure?

13:56 arbscht: ,(class 42)

13:56 clojurebot: java.lang.Integer

13:59 snowwhite: How can i check the type of an input in clojure? Anyone?

13:59 arbscht: ,(type 42)

13:59 clojurebot: java.lang.Integer

13:59 arbscht: snowwhite: use one of those forms. type is more general (checks metadata before class)

14:02 cgrand: ambient: to have designers edit templates was a key design decision for enlive

14:02 LauJensen: I think making Compojure / ClojureQL the target for a few blog posts is a very good idea

14:02 Chouser: bah. I'm confused again about where delays are required for finger-trees.

14:03 The bottom of page 7 says no delay is needed for cons/conj

14:04 The 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:06 rest/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:06 so ... is delay needed at all? I'm sure I'm missing something...

14:07 ambient: cgrand it's a lot better than designers just designing static pages and the programmers making them function?

14:07 i've only worked in an environment where everyone knew how to code

14:07 who were doing webdev

14:08 cgrand: ambient: yes it's when the design change after you started to code

14:09 ambient: i see

14:15 rsynnott_: it's often desirable to be able to have UI people modify templates without help

14:23 snowwhite: I am trying to parse the json string. Here is the code snippet. Can anyone through some light?

14:24 I am trying to parse the json string. Here is the code snippet http://pastebin.ca/1557501. I Can anyone through some light?

14:24 I am trying to parse the json string. Here is the code snippet http://pastebin.ca/1557501. Can anyone through some light?

14:25 slashus2: snowwhite: Maybe you can refer to the implementation in clojure.contrib

14:25 danlarkin: snowwhite: that looks right to me, what's the problem?

14:26 slashus2: snowwhite: Sorry, I thought you were trying to implement a json parser before I looked at your snippet.

14:27 snowwhite: danlarkin: 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:28 danlarkin: ((first v) "email")

14:30 snowwhite: danlarkin, ?

14:30 danlarkin: ok, so you have a vector of two items, right? and each item has an "email" key and a "timestamp" key

14:30 so (first v) will be the first vector

14:31 and they you want the "email" key from that vector

14:31 s/they/then

14:31 did I misunderstand what you want?

14:32 sorry, (first v) will be the first hash-map, not first vector

14:32 snowwhite: I think it's not a hash-map any more

14:33 other i could have done (filter (fn [map] (get map :email)) data)

14:33 *otherwise

14:33 danlarkin, otherwise i could have done (filter (fn [map] (get map :email)) data)

14:34 danlarkin: no

14:34 the keys in your hash-maps are not keywords

14:34 they are strings

14:35 maybe that's where you're getting confused

14:42 snowwhite: danlarkin, (map (fn [d] (get d "email")) data) This should be the statement

14:42 arbscht: (map #(% "email") data)

14:42 snowwhite: danlarkin, Thanks for helping me in clearing up my doubts. - Cheers

14:43 arbscht, Exactly. Thanks

14:46 LauJensen: danlarkin: Now that you're all warmed up. What are the major benefits of using Compojure/Clojure vs Django ?

14:46 danlarkin: hahah ummmmmm can I defer my response?

14:47 LauJensen: sure

14:48 danlarkin: that is a loaded question :)

14:48 LauJensen: As always

15:07 ambient: LauJensen performance? java interop?

15:08 LauJensen: Any references that speak on performance?

15:09 danlarkin: LauJensen: is that to me? I had a stupid kernel panic, sorry

15:10 LauJensen: dan, ambient mentioned performance and java-interop

15:10 danlarkin: :-o

15:13 ambient: well nothing much except what can be found from google, http://berlinbrowndev.blogspot.com/2008/08/application-server-benchmarks-including.html

15:14 LauJensen: Very interesting... and very hard to compare graphs... Wonder why he picked a diffferent layout for each screenshot :)

15:18 But 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:21 ambient: yes, that is very clear

15:23 LauJensen: But I really dont like the trend of all the graphs, which is that PHP out performs everything else by a factor 10

15:37 hiredman: well php is a very simple language

15:40 I have a lisp interpreter in php and have been daydreaming^W thinking about a compiler that emits php

15:40 if you want to target php

15:40 LauJensen: I dont

15:41 Just wondering, why a language that got hammered in the language shootout, suddenly wins so big

15:43 Fossi: great. i just discovered that emacs does not save back into jar files, even if it seems like it does

15:43 so i can reimplement all those changes i made to the clojure-couchdb client yesterday

15:43 danlarkin: Fossi: what? I believe it does

15:44 hiredman: :(

15:44 surely you made the changes to a git checkout, and commited the changes then built a jar :P

15:45 Fossi: didn't do the trick for me. i thought so too

15:45 it said saving yesterday all the time, but today my changes are gone

15:45 even unjar'ed

15:45 LauJensen: M-x recover-this-file ?

15:45 arbscht: LauJensen: I'd guess it's optimized for serving dynamic content, not all the things the language shootout tests for

15:46 danlarkin: maybe you're looking at a different jar, I've made modifications to a jar in emacs and they've persisted

15:46 Fossi: LauJensen: i save backups to /tmp/ which gets wiped :D

15:46 danlarkin: might be. let me try to open from emacs

15:47 LauJensen: Fossi: Alright, not too bright :)

15:47 Fossi: nope, no luck

15:48 Chousuke: what's the point of saving backups to a place that gets deleted? :P

15:48 Fossi: but let me check if i have another copy around that might be the modified one

15:50 LauJensen: Chousuke: I think if Emacs decided it was best to delete the code, it probably made the right call :)

16:00 tomoj: I don't get it, how could emacs save into a jar?

16:00 emacs can open jar files as if they're directories or something?

16:05 Chousuke: tomoj: why not? treating zip files as directories in not exactly a new idea.

16:06 tomoj: oh, archive-mode

16:06 that's kinda neat

16:07 seems like it would be better to do what hiredman said

16:16 Fossi: tomoj: yes, seems like it to me as well now :D

16:16 did somebody get fuzzy-completions to work?

16:17 tomoj: Fossi: not using the starter kit?

16:17 oh or do you mean in source buffers

16:18 Fossi: 1) no, i don't know about a starter kit and b) yes, i'd like it in source buffers

16:18 Chousuke: Fossi: works for me.

16:18 Fossi: you need a fairly recent SLIME though

16:18 Fossi: i can't figure it out. do i have to write a key binding and such?

16:18 tomoj: I don't have any completions at all in source buffers :(

16:18 Chousuke: C-c M-i should work at least

16:19 tomoj: somewhat fuzzy completion on the slime repl, though

16:20 Fossi: C-c M-i is undefined

16:20 Chousuke: wait, hm.

16:20 are we talking about the same thing, even?

16:20 There was a recent patch to swank-clojure that enable fuzzy completion through slime

16:20 Fossi: this: http://gist.github.com/179737 ?

16:21 Chousuke: yes

16:21 I had trouble getting it to work at first, but then it turned out to be because my SLIME was too old.

16:21 Fossi: i don't even get what to do with the file, apart from putting it into swank/commands/contrib/

16:22 Chousuke: I just applied the patch with git :)

16:22 tomoj: your modeline should have "Slime[clojure]" in it

16:23 Chousuke: where did you install SLIME from?

16:24 I had SLIME cloned from technomancy's github repo, which turned out to be from May :/

16:24 and it was too old

16:24 Fossi: my repl has REPL in it

16:25 i have a slime checkout of 25 june

16:25 Chousuke: try upgrading

16:26 hopefully you have it from a git mirror so you can easily save the current state in a branch? :)

16:26 Fossi: ah, i can revert

16:26 branching is for wussies

16:26 Chousuke: I wonder why anyone would use CVS nowadays.

16:26 or SVN.

16:26 except when forced to.

16:27 Well, SVN might be okay if you have to store binary files.

16:28 Fossi: my repl still says REPL

16:28 nothing about SLIME[clojure]

16:28 Chousuke: oh, wait, the REPL buffer will say that

16:28 what about clojure buffers?

16:29 they should also say "Fuzzy"

16:29 Fossi: it says "Slime"

16:29 Chousuke: hmm.

16:29 snowwhite: Fossi, 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:30 Fossi: snowwhite: well, now that i have it set up more or less, i'm not sure i should use it

16:30 Chousuke: Fossi: can you even do M-x slime-fuzzy-complete-symbol?

16:31 how do you load slime from your config?

16:31 snowwhite: Fossi, Cool

16:31 Fossi: also, i have a ton of stuff in my .emacs and .emacs.d

16:31 Chousuke: if you do just (slime-setup), that won't work :/

16:31 you need (slime-setup '(slime-fancy))

16:31 to get the good stuff :)

16:32 Fossi: no slime-fu for me :\

16:33 actually, i guess my slime setup code is broken as is anyway

16:33 i always have to M-x slime

16:33 Chousuke: that doesn't mean it's broken.

16:33 it's not automatic by default anyway

16:37 Fossi: http://github.com/Chousuke/emacs.d/blob/d826d63420dcdc90db639a4d3390a8c3773c8deb/init-clojure.el here's how I do it.

16:42 Fossi: Chousuke: ah, now it says slime[clojure]

16:44 and C-c M-i is bound to fuzzy complete as well

16:47 Chousuke: thanks, now i just have to find out what it actually completes :)

17:52 technomancy: Chousuke: so that fuzzy patch worked for you?

17:52 I locked clojure-mode into using last-known-good revisions by default since so many people were complaining about breakage.

17:52 but if there's a reason to update, I will definitely do it

17:58 Chousuke: technomancy: yeah, it does

18:02 technomancy: cool

18:10 ambient: *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:15 technomancy: ambient: do you know about the Slime inspector?

18:15 ambient: no

18:15 technomancy: C-c I over a java object, and it will list out all its methods

18:16 been meaning to hook that into autocomplete, but the information is definitely there

18:16 there's also a separate javadoc lookup package, but it's kind of awkward to use.

18:16 ambient: oh, i have to write that down :)

18:16 technomancy: yeah, it's super-helpful

18:17 ambient: thanks

19:11 prospero_: ,(map println '(1 2 3))

19:11 clojurebot: (nil nil nil)

19:11 prospero_: hmm

19:11 that's not what I'm getting at my repl

19:12 hiredman: ~map

19:12 clojurebot: map is *LAZY*

19:13 prospero_: yes, but doesn't it get evaluated at the repl?

19:13 hiredman: it does, while it is getting printed out

19:13 prospero_: the output and printing is getting spliced together for me

19:13 ah

19:13 right

19:13 the result and the printing, rather

19:13 so that makes sense, I guess

19:14 if I want to separate them I need to write to a string or something, right?

19:14 hiredman: ,(doc with-out-str)

19:14 clojurebot: "([& 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:15 hiredman: but, you also have to watchout because map is lazy, and may be evauluated outside any dynamic bindings

19:15 prospero_: so I should realize the seq with doall?

19:15 hiredman: for side effect things like printing doseq is better

19:15 ,(doc seq)

19:15 clojurebot: "([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:15 hiredman: ,(doc doseq)

19:15 clojurebot: "([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:15 prospero_: I'm just trying to debug a recursive function

19:16 printing what's going on at each level

19:16 so with-out-str sounds like a good bet

19:16 hiredman: is there a reason you just don't print the results of the map?

19:17 ,(prn (map inc (range 10)))

19:17 clojurebot: (1 2 3 4 5 6 7 8 9 10)

19:17 hiredman: or whatever list

19:17 prospero_: I'm not actually using map, it was just a good way to demonstrate the behavior I was seeing

19:17 I'm walking a tree

19:18 anyways, with-out-str seems to be working

19:18 thanks

20:36 technomancy: does anyone use the subprocess support included in clojure-mode rather than the full-fledged SLIME support?

20:36 * technomancy is thinking of removing it

20:36 technomancy: never actually heard of anyone using it

20:37 Chousuke: subprocess support?

20:37 technomancy: it's got some simplistic support for running Clojure in a subprocess and sending the current buffer to it

20:37 a small subset of what slime offers

20:38 Chousuke: isn't that what inferior-lisp is for? :/

20:40 technomancy: have you considered adding support for launching multiple slime instances with clojure-project?

20:40 or should I say Clojure instances :/

20:43 Hm, gotta go to sleep. later.

20:46 technomancy: Chousuke: I'd accept a patch, but I run one Emacs instance per project myself.

20:46 so I would be unlikely to add it myself

20:46 I guess what I'm talking about in clojure-mode is the inf-lisp integration

20:57 somnium: any vimclojure users online?

21:31 is there a std library function to return the first item in a seq for which a pred returns true?

21:31 (I wrote one but would be embarassed to show it...)

21:35 shachaf: somnium: Why?

21:36 somnium: because its ugly, and its an extremely typical operation :)

21:36 ,(first (drop-while #(x < 5) [1 2 3 4 5 6 7 8 9]))

21:36 clojurebot: java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--4159$fn

21:37 somnium: gr

21:37 ,(first (drop-while #(% < 5) [1 2 3 4 5 6 7 8 9]))

21:37 shachaf: somnium: Well, if the functions are lazy then that should be fine.

21:38 somnium: whered he go...

21:38 ah, true, I forgot about that

21:38 still haven't quite grasped laziness

21:38 shachaf: I don't know anything about Clojure, though; I should probably not have spoken in the first place. :-)

21:39 * shachaf tries not to mention #haskell.

21:39 somnium: ,(print "still here?")

21:39 clojurebot: still here?

21:40 hiredman: clojure is not lazy

21:40 somnium: ,(first (drop-while #(< % 5) [1 2 3 4 5 6 7 8 9]))

21:40 hiredman: lazy sequences are lazy

21:40 shachaf: hiredman: I read "Most of the sequence library functions are lazy".

21:40 I didn't investigate it further.

21:41 somnium: hiredman: is there a function in core or contrib to return the first item in a seq via pred?

21:43 hiredman: (comp first filter)

21:44 there was a thrad on the google group about adding a function to contrib somewhere, but I forget if it ever was

21:44 somnium: ah

21:45 some things like that would increase the "user-friendliness" fact imho, but its easy now that I see it

21:45 and I guess thats much more flexible to specify (nth ...) or whatever

21:46 ... I think I had a semi-"lisp enlightenment" moment the other day

21:47 was writing a gtk-wrapper in ruby, and couldn't get a really pleasing syntax without some form of xml

21:47 and it clicked

21:59 (comp first filter)

23:10 manic12: I watched clojure for lisp programmers and my brain hurt afterward

23:12 technomancy: that pain is weakness leaving the body

23:12 manic12: I don't know how to use the language yet, but i noticed it seems to work on JamVM running on ARM9

23:13 technomancy: mmm... Jam.

23:14 manic12: my brain is so wired for common lisp, that I feel actually like I'm at a disadvantage

23:15 technomancy: could be a lot worse

23:21 duck1123: manic12: just remind yourself that clojure is absolutely nothing like common lisp in any way whatsoever. That way you'll never be surprised.

23:22 dthomas: How 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:22 (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:24 manic12: I 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:28 i hope java has finalizations

23:43 dthomas: Getting the index of something in a vector really seems like it should be obvious and brief...

23:44 technomancy: sweet; jochu merged the fuzzy-find patch. =)

23:46 _mst: ,(.indexOf [1 2 3 "hello" 4 5 6] "hello")

23:46 clojurebot: 3

23:47 technomancy: wow, it's quite the patch

23:47 dthomas: _mst: [expletive deleted]

23:47 * technomancy prefers the term "elided"

23:48 _mst: I'm hoping I'm not relying on implementation-dependent behaviour in doing that :)

23:52 dthomas: _mst: I guess that's because a PersistentVector is a java.util.List. Thanks for that.

23:53 * dthomas also finds (instance?) instead of (isa?), and (bases).

23:53 _mst: yep, I think so. I couldn't see anywhere in the docs that said vectors were guaranteed to be Lists, but oh well :)

23:58 dthomas: Holy crap, repl-utils/show is awesome.

Logging service provided by n01se.net