#clojure log - Jan 15 2011

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

10:49 rrc7cz: I got the env var issue resolved. Here's the simple JRebel + Lein (just one line!): http://blog.robert-campbell.com/post/2760935713/clojures-gen-class-and-jrebel

10:53 raek: rrc7cz: very interesting!

10:55 rrc7cz: have you posted this to the mailing list?

10:56 fliebel: Would the best way to move the last element of a vector to the front be (vec (cons (last coll) (drop-last coll))), or am I overlooking something? conj ads to the end.

10:57 rrc7cz: raek: not yet. To be honest I'm not sure I have wrapped my head around the problem as much as I should have, so the terminology/lifecycle stuff might be incorrect. The solution works though, so maybe I will

10:57 raek: fliebel: vectors are not very good at pushings things to the front, so I don't think there is any better vector-based solution

10:57 fliebel: have you looked into clojure.lang.PersistentQueue?

10:58 Raynes: fliebel: Probably. Vectors aren't designed for what you're trying to do there.

10:58 raek: queues conj at the back and peek/pop at the front

11:04 ,(-> (into clojure.lang.PeristentQueue/EMPTY [1 2 3]) (pop) (conj :a) (pop) (conj :b))

11:04 clojurebot: java.lang.ClassNotFoundException: clojure.lang.PeristentQueue

11:05 raek: ,(-> (into clojure.lang.PersistentQueue/EMPTY [1 2 3]) (pop) (conj :a) (pop) (conj :b))

11:05 clojurebot: #<PersistentQueue clojure.lang.PersistentQueue@99bf014d>

11:05 raek: ,(-> (into clojure.lang.PersistentQueue/EMPTY [1 2 3]) (pop) (conj :a) (pop) (conj :b) (seq))

11:05 clojurebot: (3 :a :b)

11:10 fliebel: raek: And what about stuffing items in at the wrong end?

11:11 raek: then you need a deque. Maybe finger trees can solve that

11:12 (if you only need to add and remove from the same end, then a stack (list or vector) is sufficient)

11:12 fliebel: I think I'll just stick to my vector.

11:13 raek: stack: add at A, remove at A; queue: add at A, remove at B; deque: add at A or B, remove at A or B

11:14 A="first", B="last" *or* A="last", B="first"

11:38 cheezey: how can i catch ^C? (if possible?)

11:42 raek: this is what I found: http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)

11:42 you should be able to pass it a (Thread. #(<do stuff here))

11:55 fliebel: Why does the repl call equiv on my object when printing it?

12:11 cheezey: raek: thanks

12:15 fliebel: Wooo! I finished my persistent heap! https://gist.github.com/781061

13:24 dakrone: can anyone speak to the memory efficiency of contrib's datalog database?

13:34 fliebel: What is the CP for the global cake project? I just want to require a script in the current directory.

13:44 rrc7cz: raek: this sucks, it doesn't work after all. It's _really_ weird: the stub class is compiled and reloaded fine. A newly added method will be present and the -fn will be defined. Somehow they aren't connected, however

14:04 phenom_: which clojure book would people recommend? halloway or fogus/houser? I'm more interested in the entperise application and concurrency domains

14:09 rrc7cz: phenom: it's just my opinion, but I think halloway is a more hands on intro text, while fogus/houser is a good second/third book to help you think the clojure way, more high level topics, etc

14:11 phenom_: rrc7cz: how about rathore's Clojure In Action?

14:12 rrc7cz: phenom: that was my least favorite. I own all four books

14:13 I like Luke's book Practical Clojure as a second/third book after Halloway. It's in the same style, but more coverage and detail

14:13 I think Halloway is still the best intro text. The Luke for more hands on details/coverage and Fogus/Houser for higher level topics

14:14 that was my experience anyway

14:15 fliebel: How can I make clojure.pprint do more nesting indention? Right now it's doing a few levels of nesting, and then just skyscrapers.

14:27 currentB: what's the best way to get a copy of an object, but without the meta info?

14:28 (by object i actually mean anything that could have metadata)

14:29 mrBliss: currentB: something like (with-meta obj nil)

14:33 currentB: mrBliss: thanks!

14:35 tomoj: note that there is no need to actually copy :D

14:37 ... or is there?

14:37 fliebel: tomoj: Everything that has meta is clojure is immutable, so I don't think so.

14:38 tomoj: right, there is no need

14:38 strange thing is..

14:38 &(let [x (with-meta [] {:foo 3})] (identical? x (with-meta x nil)))

14:38 sexpbot: ⟹ false

14:38 tomoj: oh

14:38 of course

14:38 but the actual data still won't be copied I guess

14:40 &(let [x (with-meta (vec (repeat 1000000 0)) {:foo 3})] (time (when (with-meta x nil))))

14:40 sexpbot: ⟹ "Elapsed time: 0.610729 msecs" nil

14:40 tomoj: &(let [x (with-meta (vec (repeat 10000 0)) {:foo 3})] (time (when (with-meta x nil))))

14:40 sexpbot: ⟹ "Elapsed time: 0.536794 msecs" nil

15:02 replaca: fliebel: ayt?

15:02 fliebel: yes

15:03 replaca: ^

15:03 replaca: fliebel: pprint does it's nesting based on structure and most structures want either the whole element on the line or the lines are broken by subelement

15:03 but you can change this by changing the dispatch

15:03 brbv

15:03 brb

15:32 bobo_: when using (for can i get the current index or something? so i can alternate a true/false for example?

15:35 zmyrgel: hi, is it better to use == when testing numbers or just stick with = ?

15:41 fliebel: bobo_: map-indexed might help you.

15:42 zmyrgel: I'd say == might be a tad faster for numbers, but I don't know, and unless you need it, I'd stick with = for clarity.

15:44 In other news, I just found out my heapsort is semi-lazy. Crazy applications for that appreciated :) http://pepijndevos.nl/sorting-obsession

15:49 zmyrgel: fliebel: ok. Well I need all the speed I can get

16:14 replaca: technomancy: are you around?

16:45 LauJensen: Is anyone familiar with a JTable alternative which more freely supports embedded progressbars, checkboxes, buttons, etc etc

16:47 bobo_: LauJensen: http://blogs.sun.com/geertjan/entry/outlineview_sample maybe? if i remember correct it exists as a standalone jar, so you dont need the entire netbeans paltform

16:48 not sure about progressbars, but cant se why it shouldnt work

16:48 LauJensen: Thats an extended treeview, not JTable

17:12 timmc: Whoa... let* doesn't provide destructuring bindings?

17:12 bmh: How can I access the request object from within a compojure route definition?

17:23 gfrlog: ,(doc let*)

17:23 clojurebot: excusez-moi

17:24 companion_cube: why does clojurebot speak french ?

17:24 ,(doc fn)

17:24 clojurebot: "([& sigs]); (fn name? [params* ] exprs*) (fn name? ([params* ] exprs*)+) params => positional-params* , or positional-params* & next-param positional-param => binding-form next-param => binding-form...

17:25 companion_cube: so it's only for special forms ?

17:38 LauJensen: Its my understanding that LGPL does not consume its host project as the GPL does - Correct?

17:38 (I know I should ask a lawyer, but anyway...)

17:40 timmc: LauJensen: I believe that is true, as long as you are only linking against it/calling it/etc.

17:40 seancorfield: LGPL allows a library to be bundled without imposing LGPL on the whole bundle

17:43 LauJensen: Perfect, thanks guys

17:44 Uawdal: Is there a built-in function to split a string at every instance of a certain character?

17:45 LauJensen: Uawdal: (.split "h/e/y" "/")

17:45 That returns a java array of ["h" "e" "y"]

17:45 &(vec (.split "h/e/y" "/"))

17:45 sexpbot: ⟹ ["h" "e" "y"]

17:46 Uawdal: Ah cool, thanks LauJensen

17:46 LauJensen: For those of you who have seen the awesome quaqua kit, is there an alternative available somewhere, which does not have the Apple restrictions imposed on it?

17:47 tomoj: Uawdal: there's also one in contrib

17:47 oh, wait, it's in core now

17:48 &(doc clojure.string/replace)

17:48 sexpbot: ⟹ "([s match replacement]); Replaces all instance of match with replacement in s. match/replacement can be: string / string char / char pattern / (string or function of match). See also replace-first."

17:49 tomoj: oops

17:49 ,(clojure.string/split "h/e/y" #"/")

17:49 clojurebot: java.lang.ClassNotFoundException: clojure.string

17:50 tomoj: well, it works

17:50 seems strange that it requires a regex

17:56 bmh: any compojure/ring users out there?

17:57 tomoj: have a question? just ask it

17:57 LauJensen: tomoj: Java says (.split string regex) or (.split regex string) - clj.string uses the latter

17:57 tomoj: yeah

17:58 I guess you can't support both with one function without reflection?

17:58 bmh: LauJensen: What seancorfield said about the LGPL is misleading. The GPL and LGPL attach with regards to linking, not distribution

17:58 LauJensen: bmh: How so?

17:59 tomoj: sure you could

17:59 bmh: LauJensen: If I sent you a gzip file containing some LGPL source and some "all rights reserved" source, the fact that they were 'bundled' together is really irrelevant

18:00 LauJensen: k

18:01 bmh: If it really matters, talk to a lawyer. This stuff gets muddy fast.

18:01 LauJensen: bmh: I am well aware, thanks

18:03 bmh: back to compojure: I want to access the request object from within defroutes

18:03 Uawdal: That's even simpler, thanks tomoj!

18:04 seancorfield: bmh: 'linking' is open to some interpretation given the way LGPL is used on software these days that doesn't have an actual linker associated but i admit bundling was a loose term

18:04 tomoj: Uawdal: well..

18:04 you have to require or use clojure.string

18:05 .split works anywhere

18:05 but an array-backed vector is nicer than an array

18:06 Uawdal: yep. I don't mind the require if it makes the code itself simpler

18:10 bmh: seancorfield: I think the next project I do, whatever it is, will be unlicensed. The edge cases and interactions between the whole zoo of licenses is just painful.

18:23 dale: java.io representing EOF as -1 makes it kind of ugly to write a (case) for both EOF and which char was returned from (.read a-reader).

18:46 Uawdal: Anyone know if tail recursion made it into jvm 7/8?

18:47 mhi^: zakwilson: You've convinced me of Clojure. ;]

18:47 zakwilson: mhi^: glad to hear it [this is a continuation from another channel, for anyone else]

18:49 dnolen: Uawdal: seems unlikely. in the meantime you can use lazy-sequences, trampoline and recur

18:51 Uawdal: My searching on invokedynamic shows a bunch of different people saying invokedynamic wont help all that much. Why'd they bother with that over tail calls?

18:51 dale: How do you append an element to a list?

18:52 companion_cube: in general, do people who use clojure also use statically typed languages like scala ? or is it kind of uncompatible ?

18:52 zakwilson: Is my impression correct that Moustache is more popular, or at least growing faster than Compojure?

18:53 dale: I guess (concat '(a b c) (cons 'd)) will work.

18:53 Or (cons 'd nil) rather.

18:54 zakwilson: companion_cube: I also use Haskell. I may also learn Scala to target Android because Clojure's performance on Android is still not very good as far as I know. From what I know of Scala, I would almost always prefer to use Clojure.

18:55 companion_cube: well, it's different way of thinking

18:57 zakwilson: companion_cube: Yes, it is, and I have sometimes missed static types in Clojure after using Haskell, but I've also ported a project from Haskell to Clojure because, among other things, the type system made it annoying to do what I wanted.

18:58 My other issues were that Haskell didn't do incremental compilation very well, and Clojure's map implementation is faster.

18:58 Uawdal: I quite like Scala. I lean towards clojure mainly because I like small languages: Scala feels heavy next to clojure. But I could actually see my coworkers learning Scala, whereas Clojure scares people (unfairly) with the lisp syntax.

18:59 companion_cube: do projects using both languages exit ?

18:59 zakwilson: Get better coworkers.

18:59 companion_cube: exist*

18:59 zakwilson: I'm sure somebody somewhere has a project. I don't know of any though.

19:00 I have a project that uses both Clojure and Haskell. There's just nothing like Parsec when you want to transform some structured text.

19:02 companion_cube: there are parser combinators in scala too ;)

19:02 Uawdal: companion_cube: You can have both in a project, but they generally can't call each other directly. You would probably need Java inbetween, as they both talk to Java quite easily

19:03 companion_cube: surely

19:03 the problem would be for deployment, makes lots of .jar :)

19:04 Uawdal: Yeah. Both can be built with Maven, which could automate that somewhat

19:12 zakwilson: companion_cube: somebody was working on a Clojure port of Parsec too.

19:23 timmc: Is there some reason I can call a self-recursive function in file A from file B, but not from later in file A?

19:26 (Different namespaces for the two files, and using (defn ...) for the functions.)

19:26 nicknack: Hi all. I have a (probably stupid) question about primitives and 1.3:

19:27 People seem unhappy about exception rather than promotion being the default. If Clojure is already catching overflow to throw an exception, why can't we jump into an alternative compilation that allows for promotion instead?

19:39 timmc: Lemme see if I can get a simplified example.

19:39 Lemme see if I can get a simplified example.

19:49 Augh, can't reduce it.

20:27 dabd: How to import several classes from a Java package at once with 'import'? thx

20:29 without explicitly enumerating them...

20:30 dnolen: dabd: no possible

20:30 s/no/not

20:30 sexpbot: <dnolen> dabd: not possible

20:30 dabd: I have a bunch of classes generated from WSDL files and it is a pain to list them all...

20:31 timmc: dabd: Is each one explicitly referred to in your code?

20:31 dabd: not all in the same file

20:32 timmc: (never mind, silly question)

20:34 In other news, I'm still getting this darn "java.lang.IllegalStateException: Var timmcHW1.spatial/mondrian-oriented is unbound."

20:41 I have (defn mondrian-oriented ...) which is self-recursive, and (defn mondrian ...) below it. mondrian-oriented used to be called directly from another file, and there were no issues. :-(

20:41 Anyway, what do I need to do to get self-recursion in Clojure?

20:44 tonyl: timmc: that exception, do you call mondrian inside mondrian-oriented?

20:45 timmc: Nope. mondrian calls mondrian-oriented with an extra argument.

20:45 tonyl: and you get that exception after you compile the namespace?

20:46 timmc: Compilation works fine.

20:46 This is a runtime error.

20:47 Clojure 1.2.0, using Leiningen for building.

20:47 http://lab.brainonfire.net/drop/mccormack_t_HW1.tar.gz <-- If you're curious. There's not a lot of code, and src/timmcHW1/spatial.clj is the file in question, used by gallery.clj, which is used by core.clj.

20:49 tonyl: interesting usually that exception comes up when a symbol is declared but not bind to a value

20:49 * tonyl goes to take a look

20:54 tonyl: i think (defn mondrian-oriented ...) has an extra parenthesis at the end, it should be 6

20:55 timmc: But how would that...

20:56 tonyl: I was thinking a missing paren since it would make the defn not ended, but yeah and extra paren would not do that

20:56 timmc: Unless another earlier function has too few?

20:57 tonyl: maybe

20:57 i am looking

20:57 timmc: tonyl: Woah! I think that's it.

20:57 tonyl: the extra parenthesis?

20:58 timmc: bounded-random had too few parens

20:58 tonyl: oh nice, those are hard to fine

20:58 timmc: Ugh, I need to stop using gEdit for sexp languages.

20:58 tonyl: i need to set up my text editor to color match those parens

20:58 timmc: It's just so lightweight!

20:59 tonyl: yeah i like it too

20:59 timmc: tonyl: Thanks for your help. I can finally move on to my logic bugs now. :-P

20:59 tonyl: those are the fun ones :P

21:01 timmc: tonyl: You know why my reduction didn't work? Every time I deleted functions and emptied out the bodies of others, I would always end up with balanced parens. >_<

21:01 tonyl: hehe

21:02 it happens

21:03 timmc: So... why did it compile, if mondrian-oriented was declared inside another function? Does defn put stuff into the top-level scope?

21:05 raek: yes

21:05 unlike 'define' in Scheme

21:05 timmc: fantastic

21:06 by which I mean AAIIEEEE

21:06 Scriptor: timmc: afaik, defn is just combining def and fn

21:06 timmc: And now I have a reduced testcase that demonstrates this.

21:07 Scriptor: wait, never mind

21:07 defn *always* puts the function in the top level scope?

21:08 pdk`: if you need to create a function in a local scope

21:08 you could use stuff like letfn

21:09 timmc: Scriptor: That's what I'm seeing.

21:27 OK, I put up a minimal testcase that shows the "bug": http://www.brainonfire.net/blog/parens-defn-hoist-runtime-error-clojure/

21:34 Hopefully the next person to Google that error string in frustration will hit my blog post and be enlightened.

23:47 phenom_: so what's the best clojure ide ?

23:47 emacs ?

23:48 Mimisbrunnr: phenom_: emacs is the best ide

23:49 Scriptor: and operating system :p

23:49 Mimisbrunnr: hear hear

23:49 phenom_: use what you are most comfortable with that supports clojure. Emacs is nice because of SLIME

23:52 timmc: I wish I could use Emacs' hilighting and indenting and whatnot in a regular GUI with modern keybindings and menus.

23:52 ("modern" not being a slight towards Emacs here)

23:52 Mimisbrunnr: modern keybindings?

23:53 timmc: C-c for copy, etc.

23:53 Scriptor: is Emacs' highlighting and indenting that good?

23:53 Mimisbrunnr: Scriptor: yes

23:53 timmc: Scriptor: Yeah, compared to everything else I've enountered.

23:53 Mimisbrunnr: timmc: you can change them to that

23:53 timmc: Mimisbrunnr: That would require learning how to configure emacs.

23:54 Mimisbrunnr: timmc: you aren't using emacs until you are configuring it =P

23:54 Scriptor: hmm, learning new keybindings isn't all that hard

23:54 timmc: Sure it is.

23:55 Mimisbrunnr: timmc: what do you usually edit with?

23:55 Scriptor: after enough time it becomes natural

23:55 at least, that's what happened with vim :)

23:55 timmc: Mimisbrunnr: gEdit.

23:55 Mimisbrunnr: Scriptor: it's the "enough time" part that is' a bit

23:55 *bitch

23:55 timmc: It is lightweight and convenient.

23:56 Mimisbrunnr: how do you do editing without a gui?

23:56 timmc: Eclipse has a decent Clojure plugin, but Eclipse wants to be a full Development Environment, not just an editor.

23:56 Mimisbrunnr: I rarely do. Sometimes vim, usually nano.

23:56 Mimisbrunnr: ahh

23:57 Scriptor: Mimisbrunnr: editing without a gui is pretty easy, especially since a lot of terminals provide good integration with the mouse and the clipboard

23:57 Mimisbrunnr: that would be my problem with gEdit. I usually don't have a gui and generally switch systems enough that Gnome is everything but portable

Logging service provided by n01se.net