splicing and anonymous functions
Hi all, I've stumbled upon some interesting behaviour regarding macros and anonymous functions. I couldn't find doco anywhere on this so if you have any pointers please let me know. Considering the macro: (defmacro splicer [a] `(list ~@ a)) What's the expected result of: (macroexpand-1 '(splicer #(true))) ? What I am getting now is: behaviors.t-canary> (macroexpand-1 '(splicer #(true))) (clojure.core/list fn* [] (true)) behaviors.t-canary> (macroexpand-1 '(splicer (list true))) (clojure.core/list list true) I've found this issue while using Midje to test my code. This simple test case: (fact "splice for lambdas" (let [a #(true)] (a) => true)) Expands to: behaviors.t-canary> (macroexpand-1 '(fact "splice is broken for lambdas" (let [a #(true)] (a) => true))) (midje.util.wrapping/midje-wrapped (clojure.core/every? clojure.core/true? (clojure.core/list "splice is broken for lambdas" (let [a (fn* [] (true))] (midje.util.wrapping/midje-wrapped (midje.semi-sweet/expect (a) midje.semi-sweet/=> true :file-position (midje.util.file-position/line-number-known 1))) And results in: ;.;. FAIL at (NO_SOURCE_FILE:1) ;.;. Expected: true ;.;. Actual: java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.IFn ;.;. behaviors.t_canary$eval7514$a__7515.invoke(NO_SOURCE_FILE:1) ;.;. behaviors.t_canary$eval7514$fn__7517.invoke(NO_SOURCE_FILE:1) Can anyone shed a light on this? Expected behaviour, bug or am I missing something? Cheers -- Phil Calçado http://fragmental.tw http://www.fragmental.com.br -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: splicing and anonymous functions
(1) #( ... ) is tanslated to (fn* [ ARGS ] ( ... )) before any macros are expanded because it is a *reader macro*. (2) The contents of #() are taken to be a function application. That's why you can write #(+ 1 %) and have + applied to 1 and %. By the same token, you can't write #(true) and expect it to work because that expands to applying the function true to no arguments. That can't work because true is not a function. Again: #( + 1 %) (fn* [x] (+ 1 x) ) ^ ^ #(true) (fn* [] (true) ) ^^ don't overlook these parens! // ben 2011/1/30 Phillip Calçado : > Hi all, > > I've stumbled upon some interesting behaviour regarding macros and > anonymous functions. I couldn't find doco anywhere on this so if you > have any pointers please let me know. > > Considering the macro: > > (defmacro splicer [a] `(list ~@ a)) > > What's the expected result of: > > (macroexpand-1 '(splicer #(true))) > > ? > > What I am getting now is: > > behaviors.t-canary> (macroexpand-1 '(splicer #(true))) > (clojure.core/list fn* [] (true)) > behaviors.t-canary> (macroexpand-1 '(splicer (list true))) > (clojure.core/list list true) > > I've found this issue while using Midje to test my code. This simple test > case: > > (fact "splice for lambdas" > (let [a #(true)] > (a) => true)) > > Expands to: > > behaviors.t-canary> (macroexpand-1 '(fact "splice is broken for lambdas" > (let [a #(true)] > (a) => true))) > (midje.util.wrapping/midje-wrapped (clojure.core/every? > clojure.core/true? (clojure.core/list "splice is broken for lambdas" > (let [a (fn* [] (true))] (midje.util.wrapping/midje-wrapped > (midje.semi-sweet/expect (a) midje.semi-sweet/=> true :file-position > (midje.util.file-position/line-number-known 1))) > > > And results in: > ;.;. FAIL at (NO_SOURCE_FILE:1) > ;.;. Expected: true > ;.;. Actual: java.lang.ClassCastException: java.lang.Boolean > cannot be cast to clojure.lang.IFn > ;.;. > behaviors.t_canary$eval7514$a__7515.invoke(NO_SOURCE_FILE:1) > ;.;. > behaviors.t_canary$eval7514$fn__7517.invoke(NO_SOURCE_FILE:1) > > Can anyone shed a light on this? Expected behaviour, bug or am I > missing something? > > Cheers > -- > Phil Calçado > http://fragmental.tw > http://www.fragmental.com.br > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: splicing and anonymous functions
Thanks, Ben, I think that while simplifying the example to create a small failing test case I made some confusion about the root cause of the problems I was having. Cheers -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to disallow unlisted optional argument keys?
Why not use a constraint? It looks much cleaner. (defn hello [& {:keys [a b] :as input}] {:pre [(= (set (keys input)) #{:a :b})]} "hello") You can learn more about constraints here: http://vimeo.com/channels/fulldisclojure#8399758 -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting http-agent to throw an exception if url doesn't exist?
On Sat, Jan 29, 2011 at 01:58, Max Weber wrote: > Give clj-http a try (https://github.com/getwoven/clj-http). It has an > architecture similar to the one of Ring. Especially the Ring-style > middleware helps a lot, if you want to add custom behaviour like error > handling to clj-http. > > Looks great! cheers for this. > On 27 Jan., 02:21, Michael Ossareh wrote: > > On Wed, Jan 26, 2011 at 14:57, Stuart Sierra < > the.stuart.sie...@gmail.com>wrote: > > > > > clojure.contrib.http-agent (which I wrote) is deprecated in 1.2 and > gone in > > > 1.3. > > > > Which lib is recommended to replace it? > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to disallow unlisted optional argument keys?
On Jan 30, 2:17 pm, Alexander Yakushev wrote: > Why not use a constraint? It looks much cleaner. > > (defn hello [& {:keys [a b] :as input}] > {:pre [(= (set (keys input)) #{:a :b})]} > "hello") This is not the use case I was looking for (I listed it in a post above). Constraints are a good place to do this but not sure how to report the offending keyword clearly and easily using constraints -- as in, I need to preempt 'returning false' and throw IllegalArgumentException with correct error message instead. Regards, Shantanu -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
locals clearing
Hi, I've recently heard about the locals clearing feature of Clojure 1.2 (from a recent post by Ken Wesson), and decided to test-drive it. Here is a contrived example: (defn garbage [] (make-array Byte/TYPE 10485760)) (defn -main [& args] (let [a (garbage) b (garbage) c (garbage) d (garbage) e (garbage) f (garbage) g (garbage) h (garbage)] (println "OK"))) Now, when I build this with Leiningen and try to run under -Xmx20M or so, it bombs out on me with an OOME. Changing the let to a bunch of nested lets doesn't help, nor does migrating to Clojure 1.3alpha4. Shouldn't the locals clearing feature detect that each of the a-h locals is no longer needed and clear them right after allocation? Is this a misconception on my part about how this works? Or is something weird going on here? Thanks, -Daniel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
On Jan 28, 12:55 pm, David Nolen wrote: > (ns atest) > > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] > (loop [i (int 0)] > (if (< i (int buffer-size)) > (let [b (byte (aget cpuArray i)) > g (byte (aget cpuArray (unchecked-add i (int 1 > r (byte (aget cpuArray (unchecked-add i (int 2 > a (byte (aget cpuArray (unchecked-add i (int 3] > (aset cpuArray i a) > (aset cpuArray (unchecked-add i (int 1)) b) > (aset cpuArray (unchecked-add i (int 2)) g) > (aset cpuArray (unchecked-add i (int 3)) r) > (recur (unchecked-add i (int 4))) > > (dotimes [_ 10] > (time > (dotimes [_ 1] > (java-like array > On my laptop, removing the "byte" hint speeds it up. (I don't have the server version of Java.) (set! *warn-on-reflection* true) (def buffer-size 192) (def array (byte-array buffer-size)) (defmacro add [m n] (list 'unchecked-add `(int ~m) `(int ~n))) (defn java-like [^bytes cpu_array] (loop [i (int 0)] (if (< i (int buffer-size)) (let [b (aget cpu_array i) g (aget cpu_array (add i 1)) r (aget cpu_array (add i 2)) a (aget cpu_array (add i 3))] (aset cpu_array i a) (aset cpu_array (add i 1) b) (aset cpu_array (add i 2) g) (aset cpu_array (add i 3) r) (recur (int (add i 4))) (dotimes [_ 10] (time (dotimes [_ 1] (java-like array -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
Part of the difference (under 1.2) is due to the (substantial) overhead of accessing the buffer-size var on every iteration. I ran a quick check and using David's version of the code result averaged 17.2ms. Just changing buffer-size to a local with using (let [buffer-size (int 192)]...) the time dropped to an average 3.4ms. On Jan 29, 6:43 am, Benny Tsai wrote: > On my home computer, using the same options, the java version runs in > 1.5 milliseconds, and David's 1.2 Clojure version in 16 milliseconds. > I'm at a loss as to why you're still seeing such a large gap between > the two versions. > > On Jan 28, 6:16 pm, Robert McIntyre wrote: > > > > > > > > > I'm running my JVM with: > > > -verbose:gc -Xmn500M -Xms2000M -Xmx2000M -server > > > sincerely, > > --Robert McIntyre > > > On Fri, Jan 28, 2011 at 4:24 PM, Benny Tsai wrote: > > > Hi Robert, > > > > Just out of curiosity, are you running Clojure with the -server > > > option? When I run David's code, -server mode cuts the time for the > > > first run by half, and the time for subsequent runs by a factor of 5. > > > > On Jan 28, 12:36 pm, Robert McIntyre wrote: > > >> David, thanks for your suggestions. > > > >> I copied your code and tested it out, but on my machine it takes 230 > > >> milliseconds while the java version takes about 3. > > > >> If it's not too much trouble, how long does the java implementation > > >> take on your machine? > > > >> sincerely, > > >> --Robert McIntyre > > > >> On Fri, Jan 28, 2011 at 2:11 PM, David Nolen > > >> wrote: > > >> > On Fri, Jan 28, 2011 at 2:01 PM, Aaron Cohen > > >> > wrote: > > > >> >> On Fri, Jan 28, 2011 at 1:55 PM, David Nolen > > >> >> wrote: > > >> >> > As a comparison, the following accomplishes the same thing in 1.3.0. > > >> >> > (ns test) > > >> >> > (set! *unchecked-math* true) > > >> >> > (set! *warn-on-reflection* true) > > >> >> > (def buffer-size 192) > > >> >> > (def array (byte-array buffer-size)) > > >> >> > (defn java-like [^bytes cpuArray] > > >> >> > (loop [i (int 0)] > > > >> >> Is this hint still necessary on 1.3.0? > > > >> > The int cast on 0 was an oversight on my part. It's not necessary. > > >> > David > > > >> > -- > > >> > You received this message because you are subscribed to the Google > > >> > Groups "Clojure" group. > > >> > To post to this group, send email to clojure@googlegroups.com > > >> > Note that posts from new members are moderated - please be patient > > >> > with your > > >> > first post. > > >> > To unsubscribe from this group, send email to > > >> > clojure+unsubscr...@googlegroups.com > > >> > For more options, visit this group at > > >> >http://groups.google.com/group/clojure?hl=en > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Clojure" group. > > > To post to this group, send email to clojure@googlegroups.com > > > Note that posts from new members are moderated - please be patient with > > > your first post. > > > To unsubscribe from this group, send email to > > > clojure+unsubscr...@googlegroups.com > > > For more options, visit this group at > > >http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
On Jan 28, 12:55 pm, David Nolen wrote: > (ns atest) > > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] > (loop [i (int 0)] > (if (< i (int buffer-size)) > (let [b (byte (aget cpuArray i)) > g (byte (aget cpuArray (unchecked-add i (int 1 > r (byte (aget cpuArray (unchecked-add i (int 2 > a (byte (aget cpuArray (unchecked-add i (int 3] > (aset cpuArray i a) > (aset cpuArray (unchecked-add i (int 1)) b) > (aset cpuArray (unchecked-add i (int 2)) g) > (aset cpuArray (unchecked-add i (int 3)) r) > (recur (unchecked-add i (int 4))) > > (dotimes [_ 10] > (time > (dotimes [_ 1] > (java-like array > > On my machine this takes 9ms. > > As a comparison, the following accomplishes the same thing in 1.3.0. > > (ns test) > > (set! *unchecked-math* true) > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] > (loop [i (int 0)] > (if (< i buffer-size) > (let [b (aget cpuArray i) > g (aget cpuArray (+ i 1)) > r (aget cpuArray (+ i 2)) > a (aget cpuArray (+ i 3))] > (aset cpuArray i a) > (aset cpuArray (+ i 1) b) > (aset cpuArray (+ i 2) g) > (aset cpuArray (+ i 3) r) > (recur (+ i 4)) > > (dotimes [_ 10] > (time > (dotimes [_ 1] > (java-like array Faster than my previous post: (set! *warn-on-reflection* true) (def buffer-size 192) (def array (byte-array buffer-size)) (defmacro add [m n] (list `unchecked-add `(int ~m) `(int ~n))) (defn java-like [^bytes cpu_array] (loop [i (int 0)] (if (< i (int buffer-size)) (let [ i2 (add i 1) i3 (add i 2) i4 (add i 3) b (aget cpu_array i) g (aget cpu_array i2) r (aget cpu_array i3) a (aget cpu_array i4) ] (aset cpu_array i a) (aset cpu_array i2 b) (aset cpu_array i3 g) (aset cpu_array i4 r) (recur (add i 4)) (dotimes [_ 10] (time (dotimes [_ 1] (java-like array -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
David Nolen wrote: > (ns atest) > > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] > (loop [i (int 0)] > (if (< i (int buffer-size)) > (let [b (byte (aget cpuArray i)) > g (byte (aget cpuArray (unchecked-add i (int 1 > r (byte (aget cpuArray (unchecked-add i (int 2 > a (byte (aget cpuArray (unchecked-add i (int 3] > (aset cpuArray i a) > (aset cpuArray (unchecked-add i (int 1)) b) > (aset cpuArray (unchecked-add i (int 2)) g) > (aset cpuArray (unchecked-add i (int 3)) r) > (recur (unchecked-add i (int 4))) > > (dotimes [_ 10] > (time >(dotimes [_ 1] > (java-like array > > On my machine this takes 9ms. > > As a comparison, the following accomplishes the same thing in 1.3.0. > > (ns test) > > (set! *unchecked-math* true) > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] > (loop [i (int 0)] >(if (< i buffer-size) > (let [b (aget cpuArray i) >g (aget cpuArray (+ i 1)) >r (aget cpuArray (+ i 2)) >a (aget cpuArray (+ i 3))] >(aset cpuArray i a) >(aset cpuArray (+ i 1) b) >(aset cpuArray (+ i 2) g) >(aset cpuArray (+ i 3) r) >(recur (+ i 4)) > > (dotimes [_ 10] > (time >(dotimes [_ 1] > (java-like array Another slight speed-up: (set! *warn-on-reflection* true) (def buffer-size 192) (def array (byte-array buffer-size)) (defmacro add [m n] `(unchecked-add (int ~m) (int ~n))) (defmacro amove[a i j] `(aset ~a ~j (aget ~a ~i))) (defn java-like [^bytes cpu_array] (loop [i (int 0)] (if (< i (int buffer-size)) (let [ i2 (add i 1) i3 (add i 2) i4 (add i 3) a (aget cpu_array i4) ] (amove cpu_array i3 i4) (amove cpu_array i2 i3) (amove cpu_array i i2) (aset cpu_array i a) (recur (add i 4)) (dotimes [_ 10] (time (dotimes [_ 1] (java-like array -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: locals clearing
On Jan 30, 6:08 am, Daniel Janus wrote: > Hi, > > I've recently heard about the locals clearing feature of Clojure 1.2 (from a > recent post by Ken Wesson), and decided to test-drive it. Here is a > contrived example: > > (defn garbage [] > (make-array Byte/TYPE 10485760)) > > (defn -main [& args] > (let [a (garbage) > b (garbage) > c (garbage) > d (garbage) > e (garbage) > f (garbage) > g (garbage) > h (garbage)] > (println "OK"))) > > Now, when I build this with Leiningen and try to run under -Xmx20M or so, it > bombs out on me with an OOME. Changing the let to a bunch of nested lets > doesn't help, nor does migrating to Clojure 1.3alpha4. > > Shouldn't the locals clearing feature detect that each of the a-h locals is > no longer needed and clear them right after allocation? Is this a > misconception on my part about how this works? Or is something weird going > on here? > Locals clearing happens at the point of last use. Since those locals are never used, no clearing code is emitted. This java program fails similarly: public class Mem { public static void main (String[] args) { byte[] a = new byte[10485760]; byte[] b = new byte[10485760]; byte[] c = new byte[10485760]; byte[] d = new byte[10485760]; byte[] e = new byte[10485760]; byte[] f = new byte[10485760]; byte[] g = new byte[10485760]; byte[] h = new byte[10485760]; System.out.println ("Ok"); } } This works in Clojure due to locals clearing: (defn garbage [] (make-array Byte/TYPE 10485760)) (defn -main [& args] (let [a (garbage) b (when a (garbage)) c (when b (garbage)) d (when c (garbage)) e (when d (garbage)) f (when e (garbage)) g (when f (garbage)) h (when g (garbage))] (println "OK"))) Since unused locals serve no purpose, optimizing that case is not going to become a priority any time soon. (Note: I still think the JVM GC should be able to figure out that those locals are dead references. I'm just not going to work around it in this case). Rich -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: locals clearing
Am I correct in assuming that if those allocations had been smaller (i.e. if the JVM had not run out of memory), the GC would have eventually detected the dead references and freed them once the locals went out of scope? Bill Smith On Sunday, January 30, 2011 7:41:44 AM UTC-6, Rich Hickey wrote: > > > > (Note: I still think the JVM > GC should be able to figure out that those locals are dead references. > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
proxy and java.io.Writer
Hi. I'm trying to create a java.io.Writer proxy (which writes to a JTextArea) but I can't get it to work. Here is my clojure code so far: (def text-area (javax.swing.JTextArea.)) (def frame (let [f (javax.swing.JFrame.)] (.. f getContentPane (add text-area)) (.setMinimumSize f (java.awt.Dimension. 200 200)) (.setVisible f true) f)) (def text-area-writer (proxy [java.io.Writer] [] (close []) (flush []) (write [^chars chrs ^int offs ^int len] (.append text-area (String. chrs offs len) When I load the code above I get an "IllegalArgumentException: Unable to resolve classname: int" so I think I'm not type hinting correctly. Here is a similar piece of java code which works as expected: public class Main extends JFrame { private JTextArea text; public Writer writer; public Main() { text = new JTextArea(); getContentPane().add(text); setVisible(true); setMinimumSize(new Dimension(200, 200)); writer = new TextAreaWriter(); } class TextAreaWriter extends Writer { public void close() throws IOException {} public void flush() throws IOException {} public void write(char[] chrs, int offs, int len) throws IOException { String str = new String(chrs, offs, len); text.append(str); } } public static void main(String[] args) throws IOException { Main m = new Main(); m.writer.write("Hello, World!"); } } Any help is much appreciated! /Jonas -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
GrumpyLittleTed wrote: > Part of the difference (under 1.2) is due to the (substantial) > overhead of accessing the buffer-size var on every iteration. > > I ran a quick check and using David's version of the code result > averaged 17.2ms. Just changing buffer-size to a local with using (let > [buffer-size (int 192)]...) the time dropped to an average 3.4ms. > Great! Now I remember that that same technique is used in Lua. See long this version takes. (set! *warn-on-reflection* true) (def buffer-size 192) (def array (byte-array buffer-size)) (defmacro add [m n] `(unchecked-add (int ~m) (int ~n))) (defmacro amove[a i j] `(aset ~a ~j (aget ~a ~i))) (defn java-like [^bytes cpu_array] (let [buffer-size (int buffer-size)] (loop [i (int 0)] (if (< i buffer-size) (let [ i2 (add i 1) i3 (add i 2) i4 (add i 3) a (aget cpu_array i4) ] (amove cpu_array i3 i4) (amove cpu_array i2 i3) (amove cpu_array i i2) (aset cpu_array i a) (recur (add i 4))) (dotimes [_ 10] (time (dotimes [_ 1] (java-like array -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Debugging with 1.3 and CDT
I'm trying to set up debugging for my application using the Clojure Debugging Toolkit. I'm fairly certain I have everything set up properly, but I can't seem to get it to "reval" appropriately. I am using the Clojure maven plugin to launch a swank server. (with the debugging args from George's site) I am using Clojure 1.3, which I think may be part of my problem. I am able to set breakpoints, step in, step out, continue, etc. As soon as I try to do any reval-ing, I get an exception. (this includes trying to print locals) The stacktrace of the exception is: com.sun.jdi.InvocationException: Exception occurred in target VM (NO_SOURCE_FILE:0) at clojure.lang.Compiler.eval(Compiler.java:5440) at clojure.lang.Compiler.eval(Compiler.java:5391) at clojure.core$eval.invoke(core.clj:2382) at clojure.main$repl$read_eval_print__5624.invoke(main.clj:183) at clojure.main$repl$fn__5629.invoke(main.clj:204) at clojure.main$repl.doInvoke(main.clj:204) at clojure.lang.RestFn.invoke(RestFn.java:422) at clojure.main$repl_opt.invoke(main.clj:262) at clojure.main$main.doInvoke(main.clj:354) at clojure.lang.RestFn.invoke(RestFn.java:409) at clojure.lang.Var.invoke(Var.java:365) at clojure.lang.AFn.applyToHelper(AFn.java:163) at clojure.lang.Var.applyTo(Var.java:482) at clojure.main.main(main.java:37) Caused by: com.sun.jdi.InvocationException: Exception occurred in target VM at com.sun.tools.jdi.ClassTypeImpl.invokeMethod(ClassTypeImpl.java:246) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:90) at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28) at com.georgejahad.cdt$remote_invoke.invoke(cdt.clj:562) at clojure.lang.AFn.applyToHelper(AFn.java:174) at clojure.lang.AFn.applyTo(AFn.java:151) at clojure.core$apply.invoke(core.clj:544) at clojure.core$partial$fn__3680.doInvoke(core.clj:2011) at clojure.lang.RestFn.invoke(RestFn.java:422) at com.georgejahad.cdt$add_local_to_map.invoke(cdt.clj:653) at clojure.core$r.invoke(core.clj:799) at com.georgejahad.cdt$add_locals_to_map.invoke(cdt.clj:673) at com.georgejahad.cdt$gen_form_with_locals.invoke(cdt.clj:686) at com.georgejahad.cdt$reval_ret_STAR_.invoke(cdt.clj:714) at clojure.lang.AFn.applyToHelper(AFn.java:169) at clojure.lang.AFn.applyTo(AFn.java:151) at clojure.core$apply.invoke(core.clj:542) at clojure.core$partial$fn__3678.doInvoke(core.clj:2009) at clojure.lang.RestFn.invoke(RestFn.java:422) at com.georgejahad.cdt$safe_reval.invoke(cdt.clj:764) at user$eval800.invoke(NO_SOURCE_FILE:8) at clojure.lang.Compiler.eval(Compiler.java:5424) ... 13 more I'm AOT compiling my classes, if that makes a difference. Does anyone know what might be going on? If I were upgrade CDT and the debug-repl to 1.3, would that help? Also, I'm sure I don't have all my source paths set up properly in emacs, but I don't think that's the problem in this case. (Ubuntu 10.10, OpenJDK Runtime Environment (IcedTea6 1.9.4)) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: locals clearing
Hi On 30 January 2011 15:49, .Bill Smith wrote: > Am I correct in assuming that if those allocations had been smaller (i.e. if > the JVM had not run out of memory), the GC would have eventually detected > the dead references and freed them once the locals went out of scope? Yes, once they are out of scope they are eligible for garbage collection. The "locals clearing" is just an optimisation to allow the GC before they are out of scope, but after they are no longer needed. > On Sunday, January 30, 2011 7:41:44 AM UTC-6, Rich Hickey wrote: >> >> (Note: I still think the JVM >> GC should be able to figure out that those locals are dead references. -- Michael Wood -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: proxy and java.io.Writer
On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund wrote: > Hi. > I'm trying to create a java.io.Writer proxy (which writes to a > JTextArea) but I can't get it to work. > Here is my clojure code so far: > > (def text-area (javax.swing.JTextArea.)) > > (def frame > (let [f (javax.swing.JFrame.)] > (.. f getContentPane (add text-area)) > (.setMinimumSize f (java.awt.Dimension. 200 200)) > (.setVisible f true) > f)) > > (def text-area-writer > (proxy [java.io.Writer] [] > (close []) > (flush []) > (write [^chars chrs ^int offs ^int len] > (.append text-area (String. chrs offs len) > > When I load the code above I get an "IllegalArgumentException: Unable > to resolve classname: int" so I think I'm not type hinting correctly. Indeed. You can't (in 1.2 at least) type hint "int" though you can "ints" (array of int). Note that int is a primitive type while array of int is a reference type. Type hinting as Integer shouldn't throw exceptions, but you can probably omit all but the chars hint and have the correct String constructor overload selected. Also note that while text area .append is safe to call from off the EDT, other Swing methods mostly aren't, and it's something to watch for if you do anything similar to this with other Swing components, and wherever you construct your text area and its surrounds. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
"Ken Wesson" wrote: >On Sat, Jan 29, 2011 at 1:46 PM, Mike Meyer > wrote: >> Ditto. Most often, the "code" site is the sole project site, and >everything is there. Some larger projects may have a separate "home" >page, but it's always prominently mentioned on the "code" site. In >either case, the "code" site is worth checking out - especially if it's >the first link turned up by Google. > >The real problem is that navigating those sites can be a pain, if you >aren't intimately familiar with how the project is organized. Ever >land at some SourceForge page, see just a brief description of what >the project's software is supposed to do and a bunch of SourceForge >infrastructure, click "files", and encounter a bewildering array of >zips and binaries, none clearly labeled as, say, the Windows installer >for the current version? Sure, Sturgeon's law is closer to 99% than 90% for the web. But if you don't even look at the right page to start with because of a false assumption, then any suggestions for fixing it are at best futile. -- Sent from my Android tablet with K-9 Mail. Please excuse my brevity. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to disallow unlisted optional argument keys?
On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar wrote: > On Jan 30, 2:17 pm, Alexander Yakushev > wrote: >> Why not use a constraint? It looks much cleaner. >> >> (defn hello [& {:keys [a b] :as input}] >> {:pre [(= (set (keys input)) #{:a :b})]} >> "hello") Where is this documented? > This is not the use case I was looking for (I listed it in a post > above). Constraints are a good place to do this but not sure how to > report the offending keyword clearly and easily using constraints -- > as in, I need to preempt 'returning false' and throw > IllegalArgumentException with correct error message instead. Try this version of my earlier macro: (defmacro defkfn [name keys & body] (let [[docstring keys body] (if (string? keys) [[keys] (first body) (rest body)] [[] keys body])] `(defn ~name ~@docstring [& {:keys ~keys :as input#}] (doseq [k# (keys input#)] (when-not (~(set (map (comp keyword str) keys)) k#) (throw (IllegalArgumentException. (str "bad key " k#) ~@body))) user=> (defkfn foo [a b] (+ a (* 2 b))) #'user/foo user=> (foo :a 2 :b 1) 4 user=> (foo :b 2 :a 1) 5 user=> (foo :b 2 :a 1 :c 3) # user=> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
On Sun, Jan 30, 2011 at 12:07 PM, Mike Meyer wrote: > Sure, Sturgeon's law is closer to 99% than 90% for the web. But if you don't > even look at the right page to start with That is why I say it behooves projects that wish to grow a large user-base to have a highly-ranked google result be clearly the place for prospective end-users to go for further information, documentation, friendly download links, etc. :) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
"Ken Wesson" wrote: >On Sun, Jan 30, 2011 at 12:07 PM, Mike Meyer > wrote: >> Sure, Sturgeon's law is closer to 99% than 90% for the web. But if >you don't even look at the right page to start with > >That is why I say it behooves projects that wish to grow a large >user-base to have a highly-ranked google result be clearly the place >for prospective end-users to go for further information, >documentation, friendly download links, etc. :) > Which is exactly what the project page is for most people - if it's the #1 Google result. -- Sent from my Android tablet with K-9 Mail. Please excuse my brevity. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
On Sat, Jan 29, 2011 at 10:37 AM, GrumpyLittleTed wrote: > Part of the difference (under 1.2) is due to the (substantial) > overhead of accessing the buffer-size var on every iteration. > > I ran a quick check and using David's version of the code result > averaged 17.2ms. Just changing buffer-size to a local with using (let > [buffer-size (int 192)]...) the time dropped to an average 3.4ms. Yes, putting buffer-size in a let makes the performance in 1.3.0 identical to Java with long loop arithmetic. David -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer wrote: > "Ken Wesson" wrote: >>That is why I say it behooves projects that wish to grow a large >>user-base to have a highly-ranked google result be clearly the place >>for prospective end-users to go for further information, >>documentation, friendly download links, etc. :) > > Which is exactly what the project page is for most people Disagree. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
"Ken Wesson" wrote: >On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer > wrote: >> "Ken Wesson" wrote: >>>That is why I say it behooves projects that wish to grow a large >>>user-base to have a highly-ranked google result be clearly the place >>>for prospective end-users to go for further information, >>>documentation, friendly download links, etc. :) >> >> Which is exactly what the project page is for most people > >Disagree. Of course - you're not most people, you're a developer. That means names like bitbucket and sourceforge mean something to you. They don't for people who aren't developers. -- Sent from my Android tablet with K-9 Mail. Please excuse my brevity. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: proxy and java.io.Writer
On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson wrote: > On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund wrote: >> Hi. >> I'm trying to create a java.io.Writer proxy (which writes to a >> JTextArea) but I can't get it to work. >> Here is my clojure code so far: >> >> (def text-area (javax.swing.JTextArea.)) >> >> (def frame >> (let [f (javax.swing.JFrame.)] >> (.. f getContentPane (add text-area)) >> (.setMinimumSize f (java.awt.Dimension. 200 200)) >> (.setVisible f true) >> f)) >> >> (def text-area-writer >> (proxy [java.io.Writer] [] >> (close []) >> (flush []) >> (write [^chars chrs ^int offs ^int len] >> (.append text-area (String. chrs offs len) >> >> When I load the code above I get an "IllegalArgumentException: Unable >> to resolve classname: int" so I think I'm not type hinting correctly. > > Indeed. You can't (in 1.2 at least) type hint "int" though you can > "ints" (array of int). Note that int is a primitive type while array > of int is a reference type. > > Type hinting as Integer shouldn't throw exceptions, but you can > probably omit all but the chars hint and have the correct String > constructor overload selected. I tried with 1.3.0-alpha5. With type hints I get "CompilerException java.lang.IllegalArgumentException: Only long and double primitives are supported". If I only keep the ^chars hint I get an ArityException when I do (.write text-area-writer "hello"). Is this problem unsolvable with proxy? Should I look into gen-class and AOT compilation instead? > > Also note that while text area .append is safe to call from off the > EDT, other Swing methods mostly aren't, and it's something to watch > for if you do anything similar to this with other Swing components, > and wherever you construct your text area and its surrounds. > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
On Sun, Jan 30, 2011 at 1:24 PM, Mike Meyer wrote: > "Ken Wesson" wrote: > >>On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer >> wrote: >>> "Ken Wesson" wrote: That is why I say it behooves projects that wish to grow a large user-base to have a highly-ranked google result be clearly the place for prospective end-users to go for further information, documentation, friendly download links, etc. :) >>> >>> Which is exactly what the project page is for most people >> >>Disagree. > > Of course - you're not most people, you're a developer. That means names > like bitbucket and sourceforge mean something to you. They don't for people > who aren't developers. Not until after they go there once or twice, find confusing project pages with no clear starting point for prospective end users, and form an opinion of the site. :) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: proxy and java.io.Writer
On Sun, Jan 30, 2011 at 1:35 PM, Jonas Enlund wrote: > On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson wrote: >> On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund wrote: >>> Hi. >>> I'm trying to create a java.io.Writer proxy (which writes to a >>> JTextArea) but I can't get it to work. >>> Here is my clojure code so far: >>> >>> (def text-area (javax.swing.JTextArea.)) >>> >>> (def frame >>> (let [f (javax.swing.JFrame.)] >>> (.. f getContentPane (add text-area)) >>> (.setMinimumSize f (java.awt.Dimension. 200 200)) >>> (.setVisible f true) >>> f)) >>> >>> (def text-area-writer >>> (proxy [java.io.Writer] [] >>> (close []) >>> (flush []) >>> (write [^chars chrs ^int offs ^int len] >>> (.append text-area (String. chrs offs len) >>> >>> When I load the code above I get an "IllegalArgumentException: Unable >>> to resolve classname: int" so I think I'm not type hinting correctly. >> >> Indeed. You can't (in 1.2 at least) type hint "int" though you can >> "ints" (array of int). Note that int is a primitive type while array >> of int is a reference type. >> >> Type hinting as Integer shouldn't throw exceptions, but you can >> probably omit all but the chars hint and have the correct String >> constructor overload selected. > > I tried with 1.3.0-alpha5. With type hints I get "CompilerException > java.lang.IllegalArgumentException: Only long and double primitives > are supported". If I only keep the ^chars hint I get an ArityException > when I do (.write text-area-writer "hello"). Does it work with 1.2? Where exactly is the ArityException being thrown -- for what function or method? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
On Sun, 30 Jan 2011 13:38:24 -0500 Ken Wesson wrote: > On Sun, Jan 30, 2011 at 1:24 PM, Mike Meyer > wrote: > > "Ken Wesson" wrote: > > > >>On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer > >> wrote: > >>> "Ken Wesson" wrote: > That is why I say it behooves projects that wish to grow a large > user-base to have a highly-ranked google result be clearly the place > for prospective end-users to go for further information, > documentation, friendly download links, etc. :) > >>> > >>> Which is exactly what the project page is for most people > >> > >>Disagree. > > > > Of course - you're not most people, you're a developer. That means names > > like bitbucket and sourceforge mean something to you. They don't for people > > who aren't developers. > > Not until after they go there once or twice, find confusing project > pages with no clear starting point for prospective end users, and form > an opinion of the site. :) Yup. Those pages are about as well organized as every other page one finds on the internet, so they wind up forming the exact same opinion as they do of most sites. If someone takes the time to do a good site design, it doesn't matter who hosts it. If they don't, putting it on a custom domain won't magically make it better. For instance, try and figure out how to install the Cyanogenmod software based on www.cyanogenmod.com. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: proxy and java.io.Writer
On Sun, Jan 30, 2011 at 8:39 PM, Ken Wesson wrote: > On Sun, Jan 30, 2011 at 1:35 PM, Jonas Enlund wrote: >> On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson wrote: >>> On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund >>> wrote: Hi. I'm trying to create a java.io.Writer proxy (which writes to a JTextArea) but I can't get it to work. Here is my clojure code so far: (def text-area (javax.swing.JTextArea.)) (def frame (let [f (javax.swing.JFrame.)] (.. f getContentPane (add text-area)) (.setMinimumSize f (java.awt.Dimension. 200 200)) (.setVisible f true) f)) (def text-area-writer (proxy [java.io.Writer] [] (close []) (flush []) (write [^chars chrs ^int offs ^int len] (.append text-area (String. chrs offs len) When I load the code above I get an "IllegalArgumentException: Unable to resolve classname: int" so I think I'm not type hinting correctly. >>> >>> Indeed. You can't (in 1.2 at least) type hint "int" though you can >>> "ints" (array of int). Note that int is a primitive type while array >>> of int is a reference type. >>> >>> Type hinting as Integer shouldn't throw exceptions, but you can >>> probably omit all but the chars hint and have the correct String >>> constructor overload selected. >> >> I tried with 1.3.0-alpha5. With type hints I get "CompilerException >> java.lang.IllegalArgumentException: Only long and double primitives >> are supported". If I only keep the ^chars hint I get an ArityException >> when I do (.write text-area-writer "hello"). > > Does it work with 1.2? Where exactly is the ArityException being > thrown -- for what function or method? It didn't work in 1.2 either. Here is some more info on the exception thrown (this is with 1.3.0-alpha5) user=> (.write text-area-writer "Hello, World!") ArityException Wrong number of args (2) passed to: user$fn--38$fn clojure.lang.AFn.throwArity (AFn.java\ :439) user=> (pst) ArityException Wrong number of args (2) passed to: user$fn--38$fn user.proxy$java.io.Writer$0.write (:-1) sun.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2) sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke (Method.java:616) clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:90) clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:28) user/eval47 (NO_SOURCE_FILE:4) clojure.lang.Compiler.eval (Compiler.java:6223) clojure.lang.Compiler.eval (Compiler.java:6190) clojure.core/eval (core.clj:2680) clojure.main/repl/read-eval-print--5617 (main.clj:180) nil user=> Thanks for helping out with this Ken! > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
On Sun, Jan 30, 2011 at 1:45 PM, Mike Meyer wrote: >> Not until after they go there once or twice, find confusing project >> pages with no clear starting point for prospective end users, and form >> an opinion of the site. :) > > Yup. Those pages are about as well organized as every other page one > finds on the internet, so they wind up forming the exact same opinion > as they do of most sites. If someone takes the time to do a good site > design, it doesn't matter who hosts it. If they don't, putting it on a > custom domain won't magically make it better. For instance, try and > figure out how to install the Cyanogenmod software based on > www.cyanogenmod.com. But that's neglecting a crucial biasing factor: with project-hosting sites it's very easy to just slap together a few text blurbs for the front page and carry on your business using the tracker and repository; with regular web hosting you need to think a bit and actually come up with some page content, and you probably wouldn't have bothered to get regular web hosting if you weren't intending to. So if there's a regular .com site it's got a higher probability of being easy for end-users to navigate versus a randomly-selected sourceforge page. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Debugging with 1.3 and CDT
Hey Daniel: I'm embarrassed to say I've never tried it before on 1.3. You've found a real bug. I'll try to get a proper patch out later today, but if you're in a hurry, you might try changing this line in cdt.clj: (def ge (memoize #(first (find-methods (va) #"get" to this: (def ge (memoize #(first (find-methods (va) #"get$" Let me know how it goes. Thanks for "going were no man has gone before!" g On Jan 30, 8:12 am, Daniel Renfer wrote: > I'm trying to set up debugging for my application using the Clojure > Debugging Toolkit. I'm fairly certain I have everything set up properly, but > I can't seem to get it to "reval" appropriately. > > I am using the Clojure maven plugin to launch a swank server. (with the > debugging args from George's site) I am using Clojure 1.3, which I think may > be part of my problem. I am able to set breakpoints, step in, step out, > continue, etc. As soon as I try to do any reval-ing, I get an exception. > (this includes trying to print locals) > > The stacktrace of the exception is: > > com.sun.jdi.InvocationException: Exception occurred in target VM > (NO_SOURCE_FILE:0) > at clojure.lang.Compiler.eval(Compiler.java:5440) > at clojure.lang.Compiler.eval(Compiler.java:5391) > at clojure.core$eval.invoke(core.clj:2382) > at clojure.main$repl$read_eval_print__5624.invoke(main.clj:183) > at clojure.main$repl$fn__5629.invoke(main.clj:204) > at clojure.main$repl.doInvoke(main.clj:204) > at clojure.lang.RestFn.invoke(RestFn.java:422) > at clojure.main$repl_opt.invoke(main.clj:262) > at clojure.main$main.doInvoke(main.clj:354) > at clojure.lang.RestFn.invoke(RestFn.java:409) > at clojure.lang.Var.invoke(Var.java:365) > at clojure.lang.AFn.applyToHelper(AFn.java:163) > at clojure.lang.Var.applyTo(Var.java:482) > at clojure.main.main(main.java:37) > Caused by: com.sun.jdi.InvocationException: Exception occurred in target VM > at com.sun.tools.jdi.ClassTypeImpl.invokeMethod(ClassTypeImpl.java:246) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:616) > at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:90) > at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28) > at com.georgejahad.cdt$remote_invoke.invoke(cdt.clj:562) > at clojure.lang.AFn.applyToHelper(AFn.java:174) > at clojure.lang.AFn.applyTo(AFn.java:151) > at clojure.core$apply.invoke(core.clj:544) > at clojure.core$partial$fn__3680.doInvoke(core.clj:2011) > at clojure.lang.RestFn.invoke(RestFn.java:422) > at com.georgejahad.cdt$add_local_to_map.invoke(cdt.clj:653) > at clojure.core$r.invoke(core.clj:799) > at com.georgejahad.cdt$add_locals_to_map.invoke(cdt.clj:673) > at com.georgejahad.cdt$gen_form_with_locals.invoke(cdt.clj:686) > at com.georgejahad.cdt$reval_ret_STAR_.invoke(cdt.clj:714) > at clojure.lang.AFn.applyToHelper(AFn.java:169) > at clojure.lang.AFn.applyTo(AFn.java:151) > at clojure.core$apply.invoke(core.clj:542) > at clojure.core$partial$fn__3678.doInvoke(core.clj:2009) > at clojure.lang.RestFn.invoke(RestFn.java:422) > at com.georgejahad.cdt$safe_reval.invoke(cdt.clj:764) > at user$eval800.invoke(NO_SOURCE_FILE:8) > at clojure.lang.Compiler.eval(Compiler.java:5424) > ... 13 more > > I'm AOT compiling my classes, if that makes a difference. Does anyone know > what might be going on? If I were upgrade CDT and the debug-repl to 1.3, > would that help? Also, I'm sure I don't have all my source paths set up > properly in emacs, but I don't think that's the problem in this case. > (Ubuntu 10.10, OpenJDK Runtime Environment (IcedTea6 1.9.4)) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
That's excellent. Thank you everyone. Maybe someone could compile all these "let's speed up this clojure code" threads and put it somewhere as a valuable resource we could point to when things like this come up again? sincerely, --Robert McIntyre On Sun, Jan 30, 2011 at 1:01 PM, David Nolen wrote: > On Sat, Jan 29, 2011 at 10:37 AM, GrumpyLittleTed > wrote: >> >> Part of the difference (under 1.2) is due to the (substantial) >> overhead of accessing the buffer-size var on every iteration. >> >> I ran a quick check and using David's version of the code result >> averaged 17.2ms. Just changing buffer-size to a local with using (let >> [buffer-size (int 192)]...) the time dropped to an average 3.4ms. > > Yes, putting buffer-size in a let makes the performance in 1.3.0 identical > to Java with long loop arithmetic. > David > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: proxy and java.io.Writer
On Sun, Jan 30, 2011 at 1:47 PM, Jonas Enlund wrote: > user=> (.write text-area-writer "Hello, World!") > ArityException Wrong number of args (2) passed to: user$fn--38$fn > clojure.lang.AFn.throwArity (AFn.java\ > :439) > user=> (pst) > ArityException Wrong number of args (2) passed to: user$fn--38$fn > user.proxy$java.io.Writer$0.write (:-1) > sun.reflect.NativeMethodAccessorImpl.invoke0 > (NativeMethodAccessorImpl.java:-2) > sun.reflect.NativeMethodAccessorImpl.invoke > (NativeMethodAccessorImpl.java:57) > sun.reflect.DelegatingMethodAccessorImpl.invoke > (DelegatingMethodAccessorImpl.java:43) > java.lang.reflect.Method.invoke (Method.java:616) > clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:90) > clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:28) > user/eval47 (NO_SOURCE_FILE:4) > clojure.lang.Compiler.eval (Compiler.java:6223) > clojure.lang.Compiler.eval (Compiler.java:6190) > clojure.core/eval (core.clj:2680) > clojure.main/repl/read-eval-print--5617 (main.clj:180) > nil > user=> The proxy documentation says If a method fn is not provided for a class method, the superclass methd will be called. This doesn't seem to work if you override one of several overloads of a method. The documentation should probably be clarified to reflect that this isn't the case for overloads of a method you have overridden; it seems you have to supply one function (overloaded for arity) that implements all of the overloads, as that one function will be called for all of the overloads. This proxy works: (proxy [java.io.Writer] [] (close []) (flush []) (write ([chrs offs len] (if (string? chrs) (.append text-area (subs chrs offs (+ offs len))) (.append text-area (String. ^chars chrs offs len ([thing] (.append text-area (str thing)) The second arity handles all the overloaded .write methods with only one parameter, and the first handles the String offset length and Char-Array offset length overloads. > Thanks for helping out with this Ken! You're welcome. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
On Sun, 30 Jan 2011 13:51:40 -0500 Ken Wesson wrote: > On Sun, Jan 30, 2011 at 1:45 PM, Mike Meyer > wrote: > >> Not until after they go there once or twice, find confusing project > >> pages with no clear starting point for prospective end users, and form > >> an opinion of the site. :) > > > > Yup. Those pages are about as well organized as every other page one > > finds on the internet, so they wind up forming the exact same opinion > > as they do of most sites. If someone takes the time to do a good site > > design, it doesn't matter who hosts it. If they don't, putting it on a > > custom domain won't magically make it better. For instance, try and > > figure out how to install the Cyanogenmod software based on > > www.cyanogenmod.com. > > But that's neglecting a crucial biasing factor: with project-hosting > sites it's very easy to just slap together a few text blurbs for the > front page and carry on your business using the tracker and > repository; with regular web hosting you need to think a bit and > actually come up with some page content, and you probably wouldn't > have bothered to get regular web hosting if you weren't intending to. > So if there's a regular .com site it's got a higher probability of > being easy for end-users to navigate versus a randomly-selected > sourceforge page. Disagree, and already provided a counter-example. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting started with Counterclockwise
On Sun, Jan 30, 2011 at 2:58 PM, Mike Meyer wrote: > On Sun, 30 Jan 2011 13:51:40 -0500 > Ken Wesson wrote: >> But that's neglecting a crucial biasing factor: with project-hosting >> sites it's very easy to just slap together a few text blurbs for the >> front page and carry on your business using the tracker and >> repository; with regular web hosting you need to think a bit and >> actually come up with some page content, and you probably wouldn't >> have bothered to get regular web hosting if you weren't intending to. >> So if there's a regular .com site it's got a higher probability of >> being easy for end-users to navigate versus a randomly-selected >> sourceforge page. > > Disagree, and already provided a counter-example. A counter-example to what? The argument I made is probabilistic. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to disallow unlisted optional argument keys?
On Sun, Jan 30, 2011 at 12:12 PM, Ken Wesson wrote: > On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar > wrote: >> On Jan 30, 2:17 pm, Alexander Yakushev >> wrote: >>> Why not use a constraint? It looks much cleaner. >>> >>> (defn hello [& {:keys [a b] :as input}] >>> {:pre [(= (set (keys input)) #{:a :b})]} >>> "hello") > > Where is this documented? http://clojure.org/special_forms#toc10 -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Debugging with 1.3 and CDT
That did the trick. The keys on my keyboard that spell out "println" thank you. On Sun, Jan 30, 2011 at 2:25 PM, George Jahad wrote: > Hey Daniel: > > I'm embarrassed to say I've never tried it before on 1.3. You've > found a real bug. I'll try to get a proper patch out later today, but > if you're in a hurry, you might try changing this line in cdt.clj: > > (def ge (memoize #(first (find-methods (va) #"get" > > to this: > > (def ge (memoize #(first (find-methods (va) #"get$" > > Let me know how it goes. > > Thanks for "going were no man has gone before!" > > g > > > > On Jan 30, 8:12 am, Daniel Renfer wrote: >> I'm trying to set up debugging for my application using the Clojure >> Debugging Toolkit. I'm fairly certain I have everything set up properly, but >> I can't seem to get it to "reval" appropriately. >> >> I am using the Clojure maven plugin to launch a swank server. (with the >> debugging args from George's site) I am using Clojure 1.3, which I think may >> be part of my problem. I am able to set breakpoints, step in, step out, >> continue, etc. As soon as I try to do any reval-ing, I get an exception. >> (this includes trying to print locals) >> >> The stacktrace of the exception is: >> >> com.sun.jdi.InvocationException: Exception occurred in target VM >> (NO_SOURCE_FILE:0) >> at clojure.lang.Compiler.eval(Compiler.java:5440) >> at clojure.lang.Compiler.eval(Compiler.java:5391) >> at clojure.core$eval.invoke(core.clj:2382) >> at clojure.main$repl$read_eval_print__5624.invoke(main.clj:183) >> at clojure.main$repl$fn__5629.invoke(main.clj:204) >> at clojure.main$repl.doInvoke(main.clj:204) >> at clojure.lang.RestFn.invoke(RestFn.java:422) >> at clojure.main$repl_opt.invoke(main.clj:262) >> at clojure.main$main.doInvoke(main.clj:354) >> at clojure.lang.RestFn.invoke(RestFn.java:409) >> at clojure.lang.Var.invoke(Var.java:365) >> at clojure.lang.AFn.applyToHelper(AFn.java:163) >> at clojure.lang.Var.applyTo(Var.java:482) >> at clojure.main.main(main.java:37) >> Caused by: com.sun.jdi.InvocationException: Exception occurred in target VM >> at com.sun.tools.jdi.ClassTypeImpl.invokeMethod(ClassTypeImpl.java:246) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> at java.lang.reflect.Method.invoke(Method.java:616) >> at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:90) >> at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28) >> at com.georgejahad.cdt$remote_invoke.invoke(cdt.clj:562) >> at clojure.lang.AFn.applyToHelper(AFn.java:174) >> at clojure.lang.AFn.applyTo(AFn.java:151) >> at clojure.core$apply.invoke(core.clj:544) >> at clojure.core$partial$fn__3680.doInvoke(core.clj:2011) >> at clojure.lang.RestFn.invoke(RestFn.java:422) >> at com.georgejahad.cdt$add_local_to_map.invoke(cdt.clj:653) >> at clojure.core$r.invoke(core.clj:799) >> at com.georgejahad.cdt$add_locals_to_map.invoke(cdt.clj:673) >> at com.georgejahad.cdt$gen_form_with_locals.invoke(cdt.clj:686) >> at com.georgejahad.cdt$reval_ret_STAR_.invoke(cdt.clj:714) >> at clojure.lang.AFn.applyToHelper(AFn.java:169) >> at clojure.lang.AFn.applyTo(AFn.java:151) >> at clojure.core$apply.invoke(core.clj:542) >> at clojure.core$partial$fn__3678.doInvoke(core.clj:2009) >> at clojure.lang.RestFn.invoke(RestFn.java:422) >> at com.georgejahad.cdt$safe_reval.invoke(cdt.clj:764) >> at user$eval800.invoke(NO_SOURCE_FILE:8) >> at clojure.lang.Compiler.eval(Compiler.java:5424) >> ... 13 more >> >> I'm AOT compiling my classes, if that makes a difference. Does anyone know >> what might be going on? If I were upgrade CDT and the debug-repl to 1.3, >> would that help? Also, I'm sure I don't have all my source paths set up >> properly in emacs, but I don't think that's the problem in this case. >> (Ubuntu 10.10, OpenJDK Runtime Environment (IcedTea6 1.9.4)) > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.co
Re: How to disallow unlisted optional argument keys?
On Sun, Jan 30, 2011 at 4:03 PM, Aaron Cohen wrote: > On Sun, Jan 30, 2011 at 12:12 PM, Ken Wesson wrote: >> On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar >> wrote: >>> On Jan 30, 2:17 pm, Alexander Yakushev >>> wrote: Why not use a constraint? It looks much cleaner. (defn hello [& {:keys [a b] :as input}] {:pre [(= (set (keys input)) #{:a :b})]} "hello") >> >> Where is this documented? > > http://clojure.org/special_forms#toc10 Interesting. I don't remember seeing this before. As I suspected, :post causes problems with using recur, though this fact is not documented anywhere. (I guessed it would, because it must add an implicit (let [x (body ...)] (if-not (condition-on-x) (throw ...) x)) around the function body, or even around each separate return site.) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
How to disallow unlisted optional argument keys?
> Where is this documented? I couldn't find the documentation for it. I learned about them in Full Disclojure screencasts by Sean Devlin. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: def inside a function / set object null
> You just discard all references to an object. And then afterwards I called (makea), creating a new 'a object. But then why does it throw an exception when I deref it? I searched the archives and learned that my intended coding style (using global vars) isn't idiomatic: http://groups.google.com/group/clojure/msg/e40c4bed7dc28ebb so then I settled with the following code, to handle the db and server variables, which i sometimes redefine. in case of freeing the objects, then i'd reset! them to nil. i hope this is a good method of managing global vars that are accessible from everywhere. (defn create-db [] (EmbeddedGraphDatabase. (:dir-db (:directories *config* (defn create-server [] (run-jetty (var routes) (:jetty *config*))) (defonce db (atom (create-db))) (defonce server (atom (create-server))) (defn stop "stop the servers." [] (.stop @server) (.shutdown @db)) (defn restart "restart the servers." [] (stop) (reset! db (create-db)) (reset! server (create-server))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
Nice! That version runs in 6 milliseconds on my machine, fastest of all the code posted so far. One more idea: use 'unchecked-inc' instead of 'unchecked-add'. This takes it under 3 milliseconds in my tests. (defn java-like [^bytes cpu_array] (let [buffer-size (int buffer-size)] (loop [i (int 0)] (if (< i buffer-size) (let [i2 (unchecked-inc i) i3 (unchecked-inc i2) i4 (unchecked-inc i3) a (aget cpu_array i4)] (amove cpu_array i3 i4) (amove cpu_array i2 i3) (amove cpu_array i i2) (aset cpu_array i a) (recur (unchecked-inc i4))) On Jan 30, 8:15 am, Bill James wrote: > GrumpyLittleTed wrote: > > Part of the difference (under 1.2) is due to the (substantial) > > overhead of accessing the buffer-size var on every iteration. > > > I ran a quick check and using David's version of the code result > > averaged 17.2ms. Just changing buffer-size to a local with using (let > > [buffer-size (int 192)]...) the time dropped to an average 3.4ms. > > Great! Now I remember that that same technique is used in Lua. > See long this version takes. > > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > > (defmacro add [m n] `(unchecked-add (int ~m) (int ~n))) > (defmacro amove[a i j] `(aset ~a ~j (aget ~a ~i))) > > (defn java-like [^bytes cpu_array] > (let [buffer-size (int buffer-size)] > (loop [i (int 0)] > (if (< i buffer-size) > (let [ i2 (add i 1) > i3 (add i 2) > i4 (add i 3) > a (aget cpu_array i4) > ] > (amove cpu_array i3 i4) > (amove cpu_array i2 i3) > (amove cpu_array i i2) > (aset cpu_array i a) > (recur (add i 4))) > > (dotimes [_ 10] > (time > (dotimes [_ 1] > (java-like array -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Struct vs. Record: Now and Future
This is not solvable in the most general case. Java serialization tries really hard to be a completely generic format, but when you have a large graph of complex objects it becomes unwieldy and inefficient. Clojure's pr/read will suffice if you restrict yourself to types that can be read by the Clojure reader. For more complex data, you probably want a custom format that takes advantage of characteristics of your application's data to achieve better efficiency. -Stuart Sierra clojure.com -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to disallow unlisted optional argument keys?
Alexander Yakushev wrote: > Why not use a constraint? It looks much cleaner. > > (defn hello [& {:keys [a b] :as input}] > {:pre [(= (set (keys input)) #{:a :b})]} > "hello") > > You can learn more about constraints here: > http://vimeo.com/channels/fulldisclojure#8399758 {:pre [(clojure.set/subset? (set (keys input)) #{:a :b})]} -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to disallow unlisted optional argument keys?
On Sun, Jan 30, 2011 at 5:08 PM, Alexander Yakushev wrote: >> Where is this documented? > > I couldn't find the documentation for it. I learned about them in Full > Disclojure screencasts by Sean Devlin. There is another, quite active thread on this topic right here, right now. It includes some macro code for a defkfn that throws an exception on unwanted keys. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
a tour of Clojure (network analysis of Clojure projects)
I've been studying network analysis recently, in an attempt to automatically infer relationships between various Clojure projects. If a program can determine which similar libraries are good replacements for eachother, and which libraries tend to work well together, I can build a browseable directory of Clojure libraries. While this is initially more difficult than building such a directory manually, I would expect the long term maintenance costs to be lower and for the directory to remain more up-to-date. As an intermediate step in that goal, I collected information about hundreds of Clojure projects, and mapped out the relationships of projects based on who contributed to them. A pair of projects are considered connected if they have at least two contributors in common. I removed projects with less than two connections so that the network would be easier to visualize. You can see a picture of the resulting network at the top of this article. http://ericlavigne.wordpress.com/2011/01/30/a-tour-of-the-clojure-landscape/ I noticed that, while I was familiar with a lot of the projects, those projects tended to be clumped together into a few small parts of the graph. With that in mind, I thought it would be useful to briefly introduce various projects from different parts of the network (some of which I just discovered in these last few days after seeing the network). -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ridiculously massive slowdown when working with images
Benny Tsai wrote: > Nice! That version runs in 6 milliseconds on my machine, fastest of > all the code posted so far. One more idea: use 'unchecked-inc' > instead of 'unchecked-add'. This takes it under 3 milliseconds in my > tests. > > (defn java-like [^bytes cpu_array] > (let [buffer-size (int buffer-size)] > (loop [i (int 0)] > (if (< i buffer-size) > (let [i2 (unchecked-inc i) > i3 (unchecked-inc i2) > i4 (unchecked-inc i3) > a (aget cpu_array i4)] > (amove cpu_array i3 i4) > (amove cpu_array i2 i3) > (amove cpu_array i i2) > (aset cpu_array i a) > (recur (unchecked-inc i4))) > Yes, that speeds it up considerably. If I can get Java server installed on my machine, I'll post some timings. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en