Re: Lazy load of imports

2009-06-13 Thread Berlin Brown
On Jun 12, 10:31 am, Chouser chou...@gmail.com wrote: On Thu, Jun 11, 2009 at 8:48 PM, Stephen C. Gilardisquee...@mac.com wrote: Do you think there will be any performance hits. I haven't run any tools on it. In looking around the reflection-related code in clojure.lang, it looks to

Re: breaking early from a tight loop

2009-06-13 Thread prhlava
Hello James, Thank you for more examples. (count (take-while belowCount (filter identity (map isInteresting pixels This particular piece of code doesn't look like it would work, unless I've misunderstood what Vlad is asking. I think you'd want something more like: If I understood

Re: breaking early from a tight loop

2009-06-13 Thread CuppoJava
Hi Vlad, I just realized that you don't need the take-while. (take num coll) will directly retrieve up-to num elements out of coll. Cheers -Patrick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To

Re: breaking early from a tight loop

2009-06-13 Thread Wrexsoul
On Jun 12, 9:44 pm, James Reeves weavejes...@googlemail.com wrote:   (defn count-more-than? [n xs]     (or (zero? n)         (if (seq xs)           (recur (dec n) (rest xs)   (defn interesting? [pixels c]     (count-more-than? c (filter in-interval? pixels))) Nice, but user=

Re: breaking early from a tight loop

2009-06-13 Thread Emeka
kedu Wrexsoul user= (count-more-than? 0 ()) true (defn count-more-than? [n xs] (if (not (seq xs)) (or (zero? n) (recur (dec n) (rest xs) I'm afraid your code didn't return true for me. Just look at your code, (seq '()) will always give nil, so your code will return nil and not

Re: Anyone planning on using Clojure for ICFP 2009?

2009-06-13 Thread Michael Wood
On Thu, Jun 11, 2009 at 2:54 AM, Sethseth.schroe...@gmail.com wrote: So the 12th International Conference on Functional Programming is coming up soon. A few months before the event a programming contest is held, typically with very ambitious requirements in a short period of time (2-3 days).

Re: A few suggestions and useful things

2009-06-13 Thread Meikel Brandmeyer
Hi, Am 13.06.2009 um 02:45 schrieb Wrexsoul: I think this exists already somewhere in clojure.contrib.java-utils or so. Don't have that third-party library. Maybe clojure.contrib.duck-streams? Don't have that third-party library. Then you should check it out, no? Let's see.

Re: A few suggestions and useful things

2009-06-13 Thread Jarkko Oranen
On Jun 13, 6:38 am, Wrexsoul d2387...@bsnow.net wrote: Here's a bit more, public domain as usual: (defn get-ultimate-cause [exception]   (loop [e exception]     (let [e2 (. e getCause)]       (if-not e2         e         (recur e2) I think something like this is in clojure-contrib

Re: breaking early from a tight loop

2009-06-13 Thread CuppoJava
Hi Laurent, I like how you distilled the problem down to a reduce with an early- exit. I'm interested in what you said about my suggestion: using map then filter then take then count, which will result in creating, for at least num pixels, at worst the full number of pixels, 2 conses, and 3

Re: breaking early from a tight loop

2009-06-13 Thread James Reeves
On Jun 13, 9:17 pm, Laurent PETIT laurent.pe...@gmail.com wrote: This thread is interesting because we have a solution that is suggested : using map then filter then take then count, which will result in creating, for at least num pixels, at worst the full number of pixels, 2 conses, and 3

Re: breaking early from a tight loop

2009-06-13 Thread Laurent PETIT
2009/6/13 CuppoJava patrickli_2...@hotmail.com: Hi Laurent, I like how you distilled the problem down to a reduce with an early- exit. I'm interested in what you said about my suggestion: using map then filter then take then count, which will result in creating, for at least num pixels,

Re: breaking early from a tight loop

2009-06-13 Thread James Reeves
On Jun 13, 7:02 pm, Wrexsoul d2387...@bsnow.net wrote: Nice, but user= (count-more-than? 0 ()) true (defn count-more-than? [n xs]   (if (seq xs)     (or (zero? n)       (recur (dec n) (rest xs) True enough. My code didn't take into account that edge case. - James

Re: breaking early from a tight loop

2009-06-13 Thread James Reeves
On Jun 13, 9:39 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Well, the array is iterated once by map, the new seq created by map is iterated once by filter, and the new seq created by filter is iterated once by count, so right, I should have written : 3 walks of seqs of the size of the

Re: breaking early from a tight loop

2009-06-13 Thread Laurent PETIT
Hi, This thread is interesting because we have a solution that is suggested : using map then filter then take then count, which will result in creating, for at least num pixels, at worst the full number of pixels, 2 conses, and 3 times walking the array. What's more interesting to me is that the

Re: catching exception error

2009-06-13 Thread Michael Wood
On Thu, Jun 11, 2009 at 7:12 PM, pegphilippe.gi...@gmail.com wrote: Hi clojurians, I was happily clojure-coding whent I tried to catch a exception in a thrown deeply in a function. After looking for the fact that the IllegalArgumentException wasn't catch, I added a catch RuntimeException

Re: breaking early from a tight loop

2009-06-13 Thread Laurent PETIT
2009/6/13 James Reeves weavejes...@googlemail.com: On Jun 13, 9:39 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Well, the array is iterated once by map, the new seq created by map is iterated once by filter, and the new seq created by filter is iterated once by count, so right, I should

EDT interaction

2009-06-13 Thread Wrexsoul
Now I'm working on some Swing code and came up with these, which are obviously going to be useful: (defmacro do-on-edt [ body] `(SwingUtilities/invokeLater #(do ~...@body))) (defmacro get-on-edt [ body] `(let [ret# (atom nil)] (SwingUtilities/invokeLater #(reset! ret# [(do

Re: EDT interaction

2009-06-13 Thread Laurent PETIT
Thank you so much for giving us your light, master of the dotted pair notation ;-) 2009/6/13 Wrexsoul d2387...@bsnow.net: Now I'm working on some Swing code and came up with these, which are obviously going to be useful: (defmacro do-on-edt [ body]  `(SwingUtilities/invokeLater #(do

Re: A few suggestions and useful things

2009-06-13 Thread Wrexsoul
On Jun 13, 4:11 pm, Jarkko Oranen chous...@gmail.com wrote: Also, try using (find-doc foo) and (doc foo) in a repl for documentation searches. For this function, you might want to check out if-let. Find-doc seems to give about the same results as searching through the API page, only also

Re: EDT interaction

2009-06-13 Thread Meikel Brandmeyer
Hi, Am 13.06.2009 um 23:02 schrieb Wrexsoul: Now I'm working on some Swing code and came up with these, which are obviously going to be useful: And which are partly in clojure.contrib.swing-utils :) (defmacro do-on-edt [ body] `(SwingUtilities/invokeLater #(do ~...@body))) (defmacro

Re: EDT interaction

2009-06-13 Thread Kevin Downey
On Sat, Jun 13, 2009 at 2:02 PM, Wrexsould2387...@bsnow.net wrote: Now I'm working on some Swing code and came up with these, which are obviously going to be useful: (defmacro do-on-edt [ body]  `(SwingUtilities/invokeLater #(do ~...@body))) (defmacro get-on-edt [ body]  `(let [ret#

Re: EDT interaction

2009-06-13 Thread Meikel Brandmeyer
Hi, Am 13.06.2009 um 23:29 schrieb Meikel Brandmeyer: (defmacro get-on-edt [ body] `(get-on-edt* (fn [] ~body))) Of course ~...@body instead of ~body... Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature

Re: EDT interaction

2009-06-13 Thread Kevin Downey
On Sat, Jun 13, 2009 at 2:55 PM, Meikel Brandmeyerm...@kotka.de wrote: Hi, Am 13.06.2009 um 23:29 schrieb Meikel Brandmeyer: (defmacro get-on-edt  [ body]  `(get-on-edt* (fn [] ~body))) Of course ~...@body instead of ~body... Sincerely Meikel I know you (Meikel) already fixed it,

Re: A few suggestions and useful things

2009-06-13 Thread Michael Wood
On Sat, Jun 13, 2009 at 10:11 PM, Jarkko Oranenchous...@gmail.com wrote: [...] I think something like this is in clojure-contrib as well. It's a semi- official add-on library for Clojure (You need a CA to contribute), so you should take a look at it :) Wrexsoul: Since you don't seem to have

Re: A few suggestions and useful things

2009-06-13 Thread Michael Wood
On Sat, Jun 13, 2009 at 11:27 PM, Wrexsould2387...@bsnow.net wrote: On Jun 13, 4:11 pm, Jarkko Oranen chous...@gmail.com wrote: [...] I also personally dislike functions that take a boolean parameter; if you must, at least make it optional, with default to false The -raw ending is one I use

Re: EDT interaction

2009-06-13 Thread Aaron Cohen
Isn't this a case of wrapping a Java API needlessly? What's so bad about: (SwingUtilities/invokeLater my-func) ? -- Aaron On Sat, Jun 13, 2009 at 5:59 PM, Kevin Downeyredc...@gmail.com wrote: On Sat, Jun 13, 2009 at 2:55 PM, Meikel Brandmeyerm...@kotka.de wrote: Hi, Am 13.06.2009 um

Re: EDT interaction

2009-06-13 Thread Kevin Downey
it depends how often you are pushing stuff onto the EDT. I have a similar macro called EDT so I can do stuff like (EDT (.setText foo bar)) alternatively I would need to type (SwingUtilities/invokeLater #(.setText foo bar)) or even (SwingUtilities/invokeLater (fn [] (.setText foo bar))) On Sat,

Re: breaking early from a tight loop

2009-06-13 Thread James Reeves
On Jun 13, 9:57 pm, Laurent PETIT laurent.pe...@gmail.com wrote: The filter and map functions produce lazy seqs, so the sequence is only walked once. Well, isn't walking 3 different sequences 1 time almost equivalent (in terms of computer work) to walking 3 times one sequence ? Well, I

Re: super-lazy-seq

2009-06-13 Thread James Reeves
On Jun 13, 4:18 am, Wrexsoul d2387...@bsnow.net wrote: Between files-and-dirs and file-lines-seq I think I have saved as many lines of code as are in the macro+helper fns, so those are at break- even. I'm not completely sure what benefit super-lazy-seq is meant to have. Could you perhaps give

Re: super-lazy-seq

2009-06-13 Thread Wrexsoul
On Jun 13, 9:24 pm, James Reeves weavejes...@googlemail.com wrote: On Jun 13, 4:18 am, Wrexsoul d2387...@bsnow.net wrote: Between files-and-dirs and file-lines-seq I think I have saved as many lines of code as are in the macro+helper fns, so those are at break- even. I'm not completely

Re: A few suggestions and useful things

2009-06-13 Thread Wrexsoul
On Jun 13, 6:20 pm, Michael Wood esiot...@gmail.com wrote: On Sat, Jun 13, 2009 at 10:11 PM, Jarkko Oranenchous...@gmail.com wrote: [...] I think something like this is in clojure-contrib as well. It's a semi- official add-on library for Clojure (You need a CA to contribute), so you

Primitive char Type

2009-06-13 Thread tmountain
I'm writing some simple code, and I believe I'm running into trouble getting a primitive char. user= (def s (new StringBuilder aaa)) #'user/s ; Java method signature is setCharAt(int index, char ch) user= (. s setCharAt (int 0) (char \a)) java.lang.IllegalArgumentException: No matching method

Re: Primitive char Type

2009-06-13 Thread Kevin Downey
user= (def s (StringBuilder. aaa)) #'user/s user= (. s setCharAt 0 \b) nil user= s #StringBuilder baa user= (. s setCharAt (int 0) (char \b)) nil user= (. s setCharAt (int 0) (char \e)) nil user= s #StringBuilder eaa user= works for me On Sat, Jun 13, 2009 at 7:28 PM,

Re: Primitive char Type

2009-06-13 Thread Stephen C. Gilardi
On Jun 13, 2009, at 7:37 PM, Kevin Downey wrote: works for me It's working for me in Java 6, but not Java 5. It looks like something changed there. In Java 5, I'm getting: user= (.setCharAt s 0 \c) java.lang.IllegalArgumentException: Can't call public method of non- public class: public

Re: super-lazy-seq

2009-06-13 Thread James Reeves
On Jun 14, 3:21 am, Wrexsoul d2387...@bsnow.net wrote: It lets you write the generator in a style similar to loop/recur, and generally in half the code. And, it demonstrates the kinds of things you can do with macros. Ahh, I see. That could be useful under some circumstances. However, most

Re: super-lazy-seq

2009-06-13 Thread Wrexsoul
On Jun 13, 11:07 pm, James Reeves weavejes...@googlemail.com wrote: For instance, lets say I want to return a lazy list of all the lines in all the files in a directory tree:   (use '(clojure.contrib java-utils                          duck-streams)) When clojure.contrib releases version

Re: Primitive char Type

2009-06-13 Thread Wrexsoul
On Jun 13, 10:46 pm, Stephen C. Gilardi squee...@mac.com wrote: On Jun 13, 2009, at 7:37 PM, Kevin Downey wrote: works for me It's working for me in Java 6, but not Java 5. It looks like something   changed there. Autoboxing. What I miss is foo-array for foo not in #{int long float

Re: breaking early from a tight loop

2009-06-13 Thread CuppoJava
I actually really do like the reduce with early exit abstraction. Because ultimately, that's what the question is. It's a reduce with optimization. However, I feel that Laurence's reduce is a little too specific. The early exit condition is very likely to *not* depend on the reduce accumulator,