Re: including sound or image files with Leiningen uberjar command
On Sep 16, 7:20 am, loonster tbur...@acm.org wrote: Sound or image files will show up in the resulting uberjar if they reside in a /resources subdirectory of a Leiningen home project directory. I can't find any documentation for how to refer to and load such resource files within a project.clj and/or a source clj file so that that the resources can be used by a standalone jar. Many thanks for any hints. Tim You can refer to resources using (clojure.java.io/input-stream (clojure.java.io/resource path/to/ image)) See also ring.util.response/resource-response if you want to do this in a war/jar web app. Joost. -- 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 convert general recursion to loop .. recur syntax
Am Donnerstag, 15. September 2011 schrieb Ken Wesson : On Thu, Sep 15, 2011 at 8:56 AM, Herwig Hochleitner hhochleit...@gmail.com javascript:; wrote: Consider (defn find-in-tree ([tree pred?] (concat (filter pred? tree) (mapcat find-in-tree (filter sequential? tree) (repeat pred?) which of course is much simpler written as (defn find-in-tree ([tree pred?] (filter pred? (flatten tree Not quite -- these differ in the case where pred? sometimes fires for a subtree and not just for leaves. The latter will miss all the subtrees for which pred? returns logical true. ack -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.comjavascript:; 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 javascript:; For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- __ Herwig Hochleitner -- 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
Clojure embedded in a Java Application
Hi I'm new to Clojure so forgive me if this is a dumb question. I want to incorporate some Clojure into a Java application. String rule=(str key val label); String str = (ns test) + (defn foo [key val label] + rule + ); System.out.println(str); Compiler.load(new StringReader(str)); // Get a reference to the foo function. Var foo = RT.var(test, foo); // Call it! Object result = foo.invoke( hello,world,this is a test); The code works BUT if I try to pass in a map for example like so Object result = foo.invoke( hello,world,#{:a 1 :b 2}); I always get a ClassCastException. Am I doing something ridiculous here? Is it possible to pass in a Map from the Java world into the Clojure code? Also any comments on using Clojure within a Java app appreciated. Is it a good idea. I was thinking of allowing rules to be dynamically added to fields within a web application. -- 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: including sound or image files with Leiningen uberjar command
I use the following helper function: (defn getResource Load resource. This is guaranteed to work with JNLP'd jars. [resource-string] (.getResource (.getContextClassLoader (Thread/currentThread)) resource-string)) Note the comment. I had a lot of trouble loading resources when my uberjars were deployed via JNLP. -- 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
Wrapping an expression inside a function
Given a list of vectors, I want to return a list of vector whose elements are grouped by index. For example: Given [:a :b] [:c :d] = [:a :c] [:b :d] For this, I wrote the expression (map (partial conj []) [:a :b] [:c :d]) = [:a :c] [:b :d] It returned the right answer. Now I want wrap the above expression in a function, so I wrote (defn columns [ y] (map (partial conj []) y)) (columns [:a :b] [:c :d]) =([[:a :b]] [[:c :d]]) Not the right answer. I tried to use the apply function with no success. How can I wrap the expression inside a function. -- 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: including sound or image files with Leiningen uberjar command
Note that this implementation is the same as (clojure.java.io/resource) [1]. Dave [1] https://github.com/clojure/clojure/blob/3a3374f714e5a755b7de2a761f37696f07a74e80/src/clj/clojure/java/io.clj#L422 On Fri, Sep 16, 2011 at 8:58 AM, willyh wheine...@gmail.com wrote: I use the following helper function: (defn getResource Load resource. This is guaranteed to work with JNLP'd jars. [resource-string] (.getResource (.getContextClassLoader (Thread/currentThread)) resource-string)) Note the comment. I had a lot of trouble loading resources when my uberjars were deployed via JNLP. -- 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: Wrapping an expression inside a function
Hi, the use of a apply should work. Also note the (partial conj []) is not necessary. vector works as well. user= (defn columns [ xs] (apply map vector xs)) #'user/columns user= (columns [:a :b] [:c :d]) ([:a :c] [:b :d]) Sincerely Meikel -- 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: Wrapping an expression inside a function
Not the right answer. I tried to use the apply function with no success. How can I wrap the expression inside a function. Why not use partition and interleave? user (partition 2 (interleave [:a :b] [:c :d])) ((:a :c) (:b :d)) U -- 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: Clojure embedded in a Java Application
The problem could be that #{} in clojure is a set literal, try using clojure.lang.PersistentHashSet/create Hi I'm new to Clojure so forgive me if this is a dumb question. I want to incorporate some Clojure into a Java application. String rule=(str key val label); String str = (ns test) + (defn foo [key val label] + rule + ); System.out.println(str); Compiler.load(new StringReader(str)); // Get a reference to the foo function. Var foo = RT.var(test, foo); // Call it! Object result = foo.invoke( hello,world,this is a test); The code works BUT if I try to pass in a map for example like so Object result = foo.invoke( hello,world,#{:a 1 :b 2}); I always get a ClassCastException. Am I doing something ridiculous here? Is it possible to pass in a Map from the Java world into the Clojure code? Also any comments on using Clojure within a Java app appreciated. Is it a good idea. I was thinking of allowing rules to be dynamically added to fields within a web application. -- 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: Clojure embedded in a Java Application
Hi, Am Donnerstag, 15. September 2011 23:39:10 UTC+2 schrieb Eamonn: The code works BUT if I try to pass in a map for example like so Object result = foo.invoke( hello,world,#{:a 1 :b 2}); This does not pass a map to the function, but the string #{:a 1 :b 2}. And from your example I don't see where the class cast exception should come from. To create a clojure map use the normal hash-map function. Var keyword = RT.var(clojure.core, keyword); Var hashMap = RT.var(clojure.core, hash-map); foo.invoke(hello, world, hashMap.invoke(keyword.invoke(a), 1, keyword.invoke(b), 2)); Hope this helps. Sincerely Meikel -- 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
good example of clojure swing db program
I would like to see a listing of a swing type CRD database program to see how the items go together. Thanks, still trying to relate to Clojre type programming -- 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
org.clojure:java.classpath 0.2.0 released
http://search.maven.org/#artifactdetails%7Corg.clojure%7Cjava.classpath%7C0.2.0%7Cjar Fixes http://dev.clojure.org/jira/browse/CLASSPATH-2 -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: Rounding the edges of an Emacs beginner
I've sectioned off most of this evening to try out these tricks and treats. So far, it's all working well with 'evil'http://gitorious.org/evil/pages/Home, and swank debugging http://www.youtube.com/watch?v=galfpq969Hg. Tim On Thu, Sep 15, 2011 at 11:32 AM, gaz jones gareth.e.jo...@gmail.comwrote: M-{ and M-} in emacs go forward/backwards a paragraph. when in code, this often translates well to moving around between fragments/functions etc. you also have C-v and M-v for forward/backward a page and then C-l for centering on the current line. i use all of those a lot... On Thu, Sep 15, 2011 at 2:15 AM, Stefan Kamphausen ska2...@googlemail.com wrote: Hi, we're getting totally OT here and should probably better head for gnu.emacs.help. Anyway, just one more bark from me and then I'll be quiet (but will respond to mail ;-) On Thursday, September 15, 2011 2:08:28 AM UTC+2, frye wrote: In Vim , you press Ctrl-d and Ctrl-u to go down and up a block respectively. Depending on the size of your window, it moves the cursor about 1/3rd of the way down (or up) the screen. This is very handy to have when just browsing a buffer. You can be more precise by pressing 37k, to move the cursor up 37 lines, etc. For whatever reason, I haven't been able to find something similar in Emacs. OK, I tried what it does in vim. Some things come to my mind. 1. PgUp/PgDn obviously 2. Try hitting C-l (that's an 'l' like in 'like') several times in a row. It won't move your cursor but the line it's on. 3. I've been using some personal binding on my home and end keys for ages which moves me to the beginning/end of a line, beginning/end of the currently displayed window and beginning/end of the whole buffer on successive hits. See chb-home and chb-end on http://www.skamphausen.de/cgi-bin/ska/dot-emacs.d-slash-init.el. Combine that with C-l. 4. You might want to try out swiss-move.el (shameless self-plug). Maybe it's confusing, maybe helpful. Cheers, Stefan -- 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: org.clojure:java.classpath 0.2.0 released
I can't look at http://dev.clojure.org/jira/browse/CLASSPATH-2 Is it set to non-public? Am Freitag, 16. September 2011 schrieb Stuart Sierra : http://search.maven.org/#artifactdetails%7Corg.clojure%7Cjava.classpath%7C0.2.0%7Cjar Fixes http://dev.clojure.org/jira/browse/CLASSPATH-2 -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.comjavascript:_e({}, 'cvml', '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 javascript:_e({}, 'cvml', 'clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- __ Herwig Hochleitner -- 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
misuse of or bug in transients?
When I convert the following code to use transients it returns different result. Am I doing anything wrong or is it a bug in transients? (defn tt [] (loop [i 0 tset #{}] (if (= i (int 5e5)) (count tset) (recur (inc i) (let [nn (rem (* i (int 1e3)) 131071) plus (count (filter #(contains? tset %) (range nn (+ nn 10 ] (conj tset (+ plus nn))) (tt) 131074 (defn tt [] (loop [i 0 tset (transient #{})] (if (= i (int 5e5)) (count (persistent! tset)) (recur (inc i) (let [nn (rem (* i (int 1e3)) 131071) plus (count (filter #(contains? tset %) (range nn (+ nn 10 ] (conj! tset (+ plus nn))) (tt) 131071 P.S. Tested under 1.3-RC0 and 1.2.1 -- 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
android / mobile help
hi, i dream of having a remote repl onto e.g. android so that i can try to reduce the write-push-run-test-debug-repeat cycle time. pretty please, does anybody have insights / experience / git hub forks / ideas about this? getting to a point where i can do code updates more easily, in fragments, would be so much better than the current molasses android developer situation, i gotta hopoe... many thanks. -- 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: android / mobile help
On Fri, Sep 16, 2011 at 1:24 PM, Raoul Duke rao...@gmail.com wrote: hi, i dream of having a remote repl onto e.g. android so that i can try to reduce the write-push-run-test-debug-repeat cycle time. pretty please, does anybody have insights / experience / git hub forks / ideas about this? getting to a point where i can do code updates more easily, in fragments, would be so much better than the current molasses android developer situation, i gotta hopoe... many thanks. Have you considered using ClojureScript instead? 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: android / mobile help
hi, On Fri, Sep 16, 2011 at 10:36 AM, David Nolen dnolen.li...@gmail.com wrote: Have you considered using ClojureScript instead? i had not. my context probably won't allow it, frankly. things need to be as close to native as possible to stand a snowball's chance in hell of being allowed :-) -- 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: android / mobile help
On Fri, Sep 16, 2011 at 1:38 PM, Raoul Duke rao...@gmail.com wrote: hi, On Fri, Sep 16, 2011 at 10:36 AM, David Nolen dnolen.li...@gmail.com wrote: Have you considered using ClojureScript instead? i had not. my context probably won't allow it, frankly. things need to be as close to native as possible to stand a snowball's chance in hell of being allowed :-) JavaScript can call into Java via Rhino. You also have V8 + NDK. Doing some Googling around both of these approaches seem to draw interest (regardless of Clojure). 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: misuse of or bug in transients?
Certainly looks like a valid use of transients. Might be related to http://dev.clojure.org/jira/browse/CLJ-829 but I dunno. On Sep 16, 9:55 am, Sergey Didenko sergey.dide...@gmail.com wrote: When I convert the following code to use transients it returns different result. Am I doing anything wrong or is it a bug in transients? (defn tt [] (loop [i 0 tset #{}] (if (= i (int 5e5)) (count tset) (recur (inc i) (let [nn (rem (* i (int 1e3)) 131071) plus (count (filter #(contains? tset %) (range nn (+ nn 10 ] (conj tset (+ plus nn))) (tt) 131074 (defn tt [] (loop [i 0 tset (transient #{})] (if (= i (int 5e5)) (count (persistent! tset)) (recur (inc i) (let [nn (rem (* i (int 1e3)) 131071) plus (count (filter #(contains? tset %) (range nn (+ nn 10 ] (conj! tset (+ plus nn))) (tt) 131071 P.S. Tested under 1.3-RC0 and 1.2.1 -- 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: misuse of or bug in transients?
Here's what I speculate the problem is: Last time I checked, contains? doesn't work on transient sets. Try rewriting (contains? tset %) as (tset %). Let me know if that change fixes your program. This is a bug I reported something like 1-2 years ago. If this turns out to be the source of your problem, I'm disappointed to hear it is still not fixed in 1.3. --Mark On Fri, Sep 16, 2011 at 10:53 AM, Alan Malloy a...@malloys.org wrote: Certainly looks like a valid use of transients. Might be related to http://dev.clojure.org/jira/browse/CLJ-829 but I dunno. On Sep 16, 9:55 am, Sergey Didenko sergey.dide...@gmail.com wrote: When I convert the following code to use transients it returns different result. Am I doing anything wrong or is it a bug in transients? (defn tt [] (loop [i 0 tset #{}] (if (= i (int 5e5)) (count tset) (recur (inc i) (let [nn (rem (* i (int 1e3)) 131071) plus (count (filter #(contains? tset %) (range nn (+ nn 10 ] (conj tset (+ plus nn))) (tt) 131074 (defn tt [] (loop [i 0 tset (transient #{})] (if (= i (int 5e5)) (count (persistent! tset)) (recur (inc i) (let [nn (rem (* i (int 1e3)) 131071) plus (count (filter #(contains? tset %) (range nn (+ nn 10 ] (conj! tset (+ plus nn))) (tt) 131071 P.S. Tested under 1.3-RC0 and 1.2.1 -- 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: android / mobile help
I have the android build cycle down to a single command that creates an installable apk file. If I do this on a machine with a web server I can put the apk file into a directory with a web page link. So all that would be needed is a form that has a build button on it and downloads the updated link. I also have a keyboard/mouse (I'm using an Asus tablet) so I can edit the files. The only missing link is a good ssh/x11 app that will let me do the emacs editing. Tim Daly On Fri, 2011-09-16 at 13:36 -0400, David Nolen wrote: On Fri, Sep 16, 2011 at 1:24 PM, Raoul Duke rao...@gmail.com wrote: hi, i dream of having a remote repl onto e.g. android so that i can try to reduce the write-push-run-test-debug-repeat cycle time. pretty please, does anybody have insights / experience / git hub forks / ideas about this? getting to a point where i can do code updates more easily, in fragments, would be so much better than the current molasses android developer situation, i gotta hopoe... many thanks. Have you considered using ClojureScript instead? 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 2:07 PM, Mark Engelberg mark.engelb...@gmail.comwrote: Here's what I speculate the problem is: Last time I checked, contains? doesn't work on transient sets. Try rewriting (contains? tset %) as (tset %). Let me know if that change fixes your program. This is a bug I reported something like 1-2 years ago. If this turns out to be the source of your problem, I'm disappointed to hear it is still not fixed in 1.3. --Mark Examining the Java sources it looks like the transient collections do not support contains? by design. 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: misuse of or bug in transients?
Then it is contrary to the docs: http://clojure.org/transients Transients support the read-only interface of the source, i.e. you can call nth, get, count and fn-call a transient vector, just like a persistent vector. Examining the Java sources it looks like the transient collections do not support contains? by design. -- 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: misuse of or bug in transients?
Yes, now it works. Thanks. Try rewriting (contains? tset %) as (tset %). Let me know if that change fixes your program. -- 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 2:20 PM, David Nolen dnolen.li...@gmail.com wrote: On Fri, Sep 16, 2011 at 2:07 PM, Mark Engelberg mark.engelb...@gmail.comwrote: Here's what I speculate the problem is: Last time I checked, contains? doesn't work on transient sets. Try rewriting (contains? tset %) as (tset %). Let me know if that change fixes your program. This is a bug I reported something like 1-2 years ago. If this turns out to be the source of your problem, I'm disappointed to hear it is still not fixed in 1.3. --Mark Examining the Java sources it looks like the transient collections do not support contains? by design. Am I misunderstanding https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ATransientSet.java#L32 ? -- 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 11:20 AM, David Nolen dnolen.li...@gmail.comwrote: Examining the Java sources it looks like the transient collections do not support contains? by design. David Unfortunately, another design decision in Clojure is that contains? returns spurious results, rather than an error, for things that do not support contains?. As a consequence, when you try to use contains? with transient sets (a perfectly reasonable thing to assume would work), you get zero feedback that this is unsupported -- your program just returns incorrect results. --Mark -- 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 2:37 PM, Aaron Cohen aa...@assonance.org wrote: Am I misunderstanding https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ATransientSet.java#L32 ? Transient collections don't implement Associative (which extends IPersistentCollection and ILookup) which defines containsKey. I do see that ITransientAssociative does exist, but it does not define containsKey. 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 2:44 PM, Mark Engelberg mark.engelb...@gmail.comwrote: On Fri, Sep 16, 2011 at 11:20 AM, David Nolen dnolen.li...@gmail.comwrote: Examining the Java sources it looks like the transient collections do not support contains? by design. David Unfortunately, another design decision in Clojure is that contains? returns spurious results, rather than an error, for things that do not support contains?. As a consequence, when you try to use contains? with transient sets (a perfectly reasonable thing to assume would work), you get zero feedback that this is unsupported -- your program just returns incorrect results. --Mark Hmm... contains? doesn't throw when given a type that it doesn't support it. But then neither does get. One problem I see is that you can't map over a heterogenous collection with these fns if it does throw without enumerating the various types that are supported everywhere in your code. Protocols in ClojureScript, where they appear much earlier and can be properly extended to set of desired types (unlike Java interfaces), provide a better story here. 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: Mocking out namespaces
On Thu, Sep 15, 2011 at 6:42 AM, Chris Perkins chrisperkin...@gmail.comwrote: On Wednesday, September 14, 2011 11:19:13 AM UTC-4, Brian Hurt wrote: Say I have two name spaces, A and B, with A depending on B. I want to test namespace A, replacing module B with a mock B for testing purposes- preferably without having to load B at all (B sucks in a bunch of stuff, like dependencies on databases and external web sites and etc. that I don't want to deal with in testing). What is the easy, clojure-approved, mechanism for doing this? I tried: my-project |-- src | |-- A.clj | |-- B.clj | -- mocks | |-- B.clj |-- testdriver.clj # Run with the real B: java -cp clojure.jar:src clojure.main testdriver.clj # Run with the mock B: java -cp clojure.jar:mocks:src clojure.main testdriver.clj I don't know if my ascii-art directory tree makes any sense at all, but the point is that if you put mocks earlier in the classpath than src, then the mock B should get loaded instead of the real one. This is the best answer so far, but it doesn't deal with the three-level case- A depends upon B which depends upon C, and I want to test A without sucking in B and C, and test B without sucking in C. Maybe I'm asking the wrong question. If I have code that naturally structures like: ++ || | A| || ++ || | B| || ++ || | C| || ++ || |Database| | Or | | Webservice | | Or | |Similar | ++ How *should* I structure this code for testing? I was assuming the natural way to do this is to make A, B, and C separate name spaces but maybe this is wrong. The problem isn't just *writing* the code- I need to be able to change this code later, and have some assurance it still works. So load it up into a repl and play with it isn't a viable solution. Or is clojure code just not testable/maintainable? Brian -- 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: misuse of or bug in transients?
Here is the (a?) ticket for this issue: http://dev.clojure.org/jira/browse/CLJ-700 I too have thought, it was fixed by now. Am Freitag, 16. September 2011 schrieb David Nolen : On Fri, Sep 16, 2011 at 2:37 PM, Aaron Cohen aa...@assonance.orgjavascript:_e({}, 'cvml', 'aa...@assonance.org'); wrote: Am I misunderstanding https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ATransientSet.java#L32 ? Transient collections don't implement Associative (which extends IPersistentCollection and ILookup) which defines containsKey. I do see that ITransientAssociative does exist, but it does not define containsKey. 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.comjavascript:_e({}, 'cvml', '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 javascript:_e({}, 'cvml', 'clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- __ Herwig Hochleitner -- 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: android / mobile help
On Fri Sep 16 10:24 2011, Raoul Duke wrote: hi, i dream of having a remote repl onto e.g. android so that i can try to reduce the write-push-run-test-debug-repeat cycle time. pretty please, does anybody have insights / experience / git hub forks / ideas about this? getting to a point where i can do code updates more easily, in fragments, would be so much better than the current molasses android developer situation, i gotta hopoe... Well, this can and has been done. There is a version of Clojure out there that supports dynamic compilation on Android (based on a 1.2.0 release of Clojure) [1]. With this, it is possible to include some sort of server on the Android device that can provide a REPL. For example, the Clojure REPL for Android supports a VimClojure-compatible server (no source available, yet). Due to how dynamic compilation occurs, it's slow (a few seconds), but it sure beats having to do an entire compile/deploy cycle. As I will be talking about Android and Clojure at the Conj this year, I will be making an effort to update the Clojure code to release 1.3 and release the code to the REPL itself. Sincerely, Daniel Solano Gómez [1]: https://github.com/sattvik/clojure/tree/android-1.2.x signature.asc Description: Digital signature
Re: android / mobile help
On Fri, Sep 16, 2011 at 12:34 PM, Daniel Solano Gomez cloj...@sattvik.com wrote: source available, yet). Due to how dynamic compilation occurs, it's slow (a few seconds), but it sure beats having to do an entire compile/deploy cycle. keen! -- 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: org.clojure:java.classpath 0.2.0 released
Sorry, I don't know where to configure this in JIRA. Help? -Stuart Sierra -- 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 3:26 PM, Herwig Hochleitner hhochleit...@gmail.comwrote: Here is the (a?) ticket for this issue: http://dev.clojure.org/jira/browse/CLJ-700 I too have thought, it was fixed by now. The other thing to consider is that - is this a contract that is desirable to support? Transients are only about performance - lowering the time it takes to construct a collection. Perhaps there are faster implementations which cannot fulfill the contract of supporting contains? 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: org.clojure:java.classpath 0.2.0 released
Fixed. It needed Default Permission Scheme = Clojure Permission Scheme. - Chas On Sep 16, 2011, at 3:42 PM, Stuart Sierra wrote: Sorry, I don't know where to configure this in JIRA. Help? -Stuart Sierra -- 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: Mocking out namespaces
On Friday, September 16, 2011 3:12:49 PM UTC-4, Brian Hurt wrote: How *should* I structure this code for testing? I was assuming the natural way to do this is to make A, B, and C separate name spaces but maybe this is wrong. The best way to make these namespaces testable, in my opinion, is remove the dependencies. In the ideal scenario, only the bottom layer -- layer C in your diagram -- would have any side-effects. Layer B -- the middle layer -- would consist entirely of pure functions that operate on the data structures generated and consumed by C, but would have no direct dependencies on C. Finally, layer A would tie the two together. I wrote about this approach here: http://stuartsierra.com/2011/08/08/clojure-namespaces In this style, layer B is easy to unit-test. Tests for layer C are integration tests that know about external services like databases. Tests for layer A are whole-application tests. Another option is to design the APIs of B and C around an object that represents the runtime environment. The testing environment returns mock data; the production environment uses the real functions. This object could be an argument to functions in B and C, or it could be a Var bound to a special value for testing. -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: Mocking out namespaces
On Friday, September 16, 2011 3:12:49 PM UTC-4, Brian Hurt wrote: On Thu, Sep 15, 2011 at 6:42 AM, Chris Perkins chrispe...@gmail.comwrote: On Wednesday, September 14, 2011 11:19:13 AM UTC-4, Brian Hurt wrote: Say I have two name spaces, A and B, with A depending on B. I want to test namespace A, replacing module B with a mock B for testing purposes- preferably without having to load B at all (B sucks in a bunch of stuff, like dependencies on databases and external web sites and etc. that I don't want to deal with in testing). What is the easy, clojure-approved, mechanism for doing this? I tried: How *should* I structure this code for testing? I was assuming the natural way to do this is to make A, B, and C separate name spaces but maybe this is wrong. The problem isn't just *writing* the code- I need to be able to change this code later, and have some assurance it still works. So load it up into a repl and play with it isn't a viable solution. Or is clojure code just not testable/maintainable? Brian I don't have a detailed answer because I haven't done much mocking myself, but I'm confident that it's possible. The reason for my confidence is that references from one namespace to another live in Vars, which are mutable. Here's a very simple example: I made a namespace a containing a function a-fn, which just calls b-fn in namespace b. Then I created a mock-b that defines a different b-fn. user= (require 'a) nil user= (a/a-fn) real b user= (require 'mock-b) nil user= (alter-var-root #'b/b-fn (constantly mock-b/b-fn)) #mock_b$b_fn mock_b$b_fn@1e1be92 user= (a/a-fn) mock b Note that the behavior of a-fn has been altered at runtime. I can imagine a mocking utility that, given a namespace (eg: b), and a mock namespace (eg: mock-b), would go through the vars in mock-b and call alter-var-root on all the matching vars in b before calling a test suite. In fact, I wouldn't be surprised at all to find this on github somewhere. Not much detail there, but I hope this helps somewhat. - Chris 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: misuse of or bug in transients?
Support of membership testing is pretty much the defining characteristic of sets, transient or not. Transient sets already support membership testing in the form of (my-set item). If they support the IFn interface for membership testing, it's hard for me to imagine that it would be much more difficult to support the same behavior for whatever interface makes contains? work properly. On Fri, Sep 16, 2011 at 12:42 PM, David Nolen dnolen.li...@gmail.comwrote: On Fri, Sep 16, 2011 at 3:26 PM, Herwig Hochleitner hhochleit...@gmail.com wrote: Here is the (a?) ticket for this issue: http://dev.clojure.org/jira/browse/CLJ-700 I too have thought, it was fixed by now. The other thing to consider is that - is this a contract that is desirable to support? Transients are only about performance - lowering the time it takes to construct a collection. Perhaps there are faster implementations which cannot fulfill the contract of supporting contains? 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: misuse of or bug in transients?
Am Freitag, 16. September 2011 schrieb David Nolen : The other thing to consider is that - is this a contract that is desirable to support? Transients are only about performance - lowering the time it takes to construct a collection. Perhaps there are faster implementations which cannot fulfill the contract of supporting contains? Fair point! OTOH such an implementation would still need to support get, which is supposed to be fast too (the reason it's stated explicitely in the contains? doc is, so that people don't confuse it with some) In fact, one could implement contains? as (defn contains? [c x] (not= ::not-found (get c x ::not-found))) right now and retain the performance guarantees. And it would work on transients too :) kind regards -- __ Herwig Hochleitner -- 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 4:33 PM, Mark Engelberg mark.engelb...@gmail.comwrote: Support of membership testing is pretty much the defining characteristic of sets, transient or not. Transient sets already support membership testing in the form of (my-set item). If they support the IFn interface for membership testing, it's hard for me to imagine that it would be much more difficult to support the same behavior for whatever interface makes contains? work properly. I suspect that part of the reason there is little movement on this is that transients are as of 1.3 *still* marked alpha. And from what I understand they will most likely become an implementation detail. That is direct use will be thoroughly discouraged. 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: Mocking out namespaces
On Fri, Sep 16, 2011 at 4:28 PM, Chris Perkins chrisperkin...@gmail.comwrote: On Friday, September 16, 2011 3:12:49 PM UTC-4, Brian Hurt wrote: On Thu, Sep 15, 2011 at 6:42 AM, Chris Perkins chrispe...@gmail.comwrote: On Wednesday, September 14, 2011 11:19:13 AM UTC-4, Brian Hurt wrote: Say I have two name spaces, A and B, with A depending on B. I want to test namespace A, replacing module B with a mock B for testing purposes- preferably without having to load B at all (B sucks in a bunch of stuff, like dependencies on databases and external web sites and etc. that I don't want to deal with in testing). What is the easy, clojure-approved, mechanism for doing this? I tried: How *should* I structure this code for testing? I was assuming the natural way to do this is to make A, B, and C separate name spaces but maybe this is wrong. The problem isn't just *writing* the code- I need to be able to change this code later, and have some assurance it still works. So load it up into a repl and play with it isn't a viable solution. Or is clojure code just not testable/maintainable? Brian I don't have a detailed answer because I haven't done much mocking myself, but I'm confident that it's possible. The reason for my confidence is that references from one namespace to another live in Vars, which are mutable. Here's a very simple example: I made a namespace a containing a function a-fn, which just calls b-fn in namespace b. Then I created a mock-b that defines a different b-fn. user= (require 'a) nil user= (a/a-fn) real b user= (require 'mock-b) nil user= (alter-var-root #'b/b-fn (constantly mock-b/b-fn)) #mock_b$b_fn mock_b$b_fn@1e1be92 user= (a/a-fn) mock b Note that the behavior of a-fn has been altered at runtime. I can imagine a mocking utility that, given a namespace (eg: b), and a mock namespace (eg: mock-b), would go through the vars in mock-b and call alter-var-root on all the matching vars in b before calling a test suite. In fact, I wouldn't be surprised at all to find this on github somewhere. Not much detail there, but I hope this helps somewhat. For the record, this is exactly what I'm doing- I'm just kind of surprised I have to actually create this infrastructure. Brian -- 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: misuse of or bug in transients?
Sorry! Disregard my former post. In fact, get doesn't work on transients either. Fingers too fast :/ Still, looking keys up in a map while building it, is a valid use case for transients, because you do that with persistent collections too. Same with sets. At the very least, get and contains? should throw on transients, but as Mark said: Lookup is the defining characteristic of sets and maps. If transients support the read-only interface of their persistent variants, why shouldn't they support generic access too? IIRC you're supposed to convert existing reduce's and loop's by wrapping it in (persistent! ... (transient ...)) and replacing assoc with assoc! kind regards Am Freitag, 16. September 2011 schrieb Herwig Hochleitner : Am Freitag, 16. September 2011 schrieb David Nolen : The other thing to consider is that - is this a contract that is desirable to support? Transients are only about performance - lowering the time it takes to construct a collection. Perhaps there are faster implementations which cannot fulfill the contract of supporting contains? Fair point! OTOH such an implementation would still need to support get, which is supposed to be fast too (the reason it's stated explicitely in the contains? doc is, so that people don't confuse it with some) In fact, one could implement contains? as (defn contains? [c x] (not= ::not-found (get c x ::not-found))) right now and retain the performance guarantees. And it would work on transients too :) kind regards -- __ Herwig Hochleitner -- __ Herwig Hochleitner -- 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: heaps in clojure
Using PriorityQueue should give a good, fast result. Here's my implementation: (defn smallest-n [n xs] (let [q (java.util.PriorityQueue. xs)] (for [i (range n)] (.poll q (smallest-n 5 (shuffle (range 100))) ;; (0 1 2 3 4) Jim -- 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: including sound or image files with Leiningen uberjar command
Great. I can eliminate another function from my general purpose utilities file. Thanks. I need to comb the docs more. On Sep 16, 9:21 am, Dave Ray dave...@gmail.com wrote: Note that this implementation is the same as (clojure.java.io/resource) [1]. Dave [1]https://github.com/clojure/clojure/blob/3a3374f714e5a755b7de2a761f376... On Fri, Sep 16, 2011 at 8:58 AM, willyh wheine...@gmail.com wrote: I use the following helper function: (defn getResource Load resource. This is guaranteed to work with JNLP'd jars. [resource-string] (.getResource (.getContextClassLoader (Thread/currentThread)) resource-string)) Note the comment. I had a lot of trouble loading resources when my uberjars were deployed via JNLP. -- 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: heaps in clojure
That's really no different from just sorting the list and taking the first 5. O(n log(n)). And for really large data sets, this is going to consume a lot of memory. The method I outlined would be O(n) and doesn't force the sequence to all be resident in memory at the same time. On Fri, Sep 16, 2011 at 6:22 AM, Jim Oly james...@gmail.com wrote: Using PriorityQueue should give a good, fast result. Here's my implementation: (defn smallest-n [n xs] (let [q (java.util.PriorityQueue. xs)] (for [i (range n)] (.poll q (smallest-n 5 (shuffle (range 100))) ;; (0 1 2 3 4) Jim -- 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: Mocking out namespaces
On Fri, Sep 16, 2011 at 4:01 PM, Stuart Sierra the.stuart.sie...@gmail.comwrote: On Friday, September 16, 2011 3:12:49 PM UTC-4, Brian Hurt wrote: How *should* I structure this code for testing? I was assuming the natural way to do this is to make A, B, and C separate name spaces but maybe this is wrong. The best way to make these namespaces testable, in my opinion, is remove the dependencies. In the ideal scenario, only the bottom layer -- layer C in your diagram -- would have any side-effects. Layer B -- the middle layer -- would consist entirely of pure functions that operate on the data structures generated and consumed by C, but would have no direct dependencies on C. Finally, layer A would tie the two together. I wrote about this approach here: http://stuartsierra.com/2011/08/08/clojure-namespaces In this style, layer B is easy to unit-test. Tests for layer C are integration tests that know about external services like databases. Tests for layer A are whole-application tests. In my case, pretty much all the functions are of the form do some action, and each layer is collecting simple(r) actions up into more complicated applications. The bottom level of actions may be read an individual email and put an email in the database. The next level up action is read an email and put it in the database. The next level up would be read all the emails from this folder into the database, then for all folders for this user, then for all users, and so on. So this structure isn't really applicable. The reality is, of course, always more complicated. :-} Another option is to design the APIs of B and C around an object that represents the runtime environment. The testing environment returns mock data; the production environment uses the real functions. This object could be an argument to functions in B and C, or it could be a Var bound to a special value for testing. We just had a long discussion on this. The problem here is fan-out. So, I'm testing function a1 in ns a. Function a1 calls function b1, b2, and b3 in ns b. b1 calls c1, c2, and c3, etc. So now, testing a single function up in ns a requires me to mock out 9 functions down in c- 27 down in ns d. Even worse, *which* functions I need to mock out, to test a, requires a knowledge of the implementations not only of a1, but also b1-b3 and possible c1-c9. And If I modify c7 or b2, I now have to remember to go fix the tests for a1 as well. This is why I'm so insistent that I can mock out b. If I can do that, then I only need to supply three functions, and which three functions require only knowledge of the specific function I'm testing. Brian -- 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: misuse of or bug in transients?
Am Freitag, 16. September 2011 schrieb David Nolen : I suspect that part of the reason there is little movement on this is that transients are as of 1.3 *still* marked alpha. And from what I understand they will most likely become an implementation detail. That is direct use will be thoroughly discouraged. That makes sense. So we basically have two options now: - make it work - make it an error I'll be glad to help with either. Shall we repost this to the dev list, so that Rich has a chance to look at it? kind regards -- __ Herwig Hochleitner -- 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: misuse of or bug in transients?
On Fri, Sep 16, 2011 at 5:12 PM, Herwig Hochleitner hhochleit...@gmail.comwrote: Am Freitag, 16. September 2011 schrieb David Nolen : I suspect that part of the reason there is little movement on this is that transients are as of 1.3 *still* marked alpha. And from what I understand they will most likely become an implementation detail. That is direct use will be thoroughly discouraged. That makes sense. So we basically have two options now: - make it work - make it an error I will note: It will probably not become an error because of the reasons I mentioned above and there is no reason to single out transients over all the other types that also return false. There are already patches that fix issue and they haven't been applied. 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
[1.3 RC0] extend-protocol doesn't compile for class expressions
Hi all, I'd like to extend some protocol to objects of classes that were compiled in memory, and thus I don't have the class handy as literal but have to resolve it. To simplify the issue, my code is basically like this: --8---cut here---start-8--- (defprotocol BlaBla (bla [this])) (extend-protocol BlaBla (class 17) (bla [this] (inc this)) (class s) (bla [this] (reverse this)) (class \s) (bla [this] foo)) --8---cut here---end---8--- But that extend-protocol form does not compile: --8---cut here---start-8--- nth not supported on this type: Character [Thrown class java.lang.UnsupportedOperationException] Backtrace: 0: clojure.lang.RT.nthFrom(RT.java:835) 1: clojure.lang.RT.nth(RT.java:785) 2: clojure.core$emit_hinted_impl$hint__5517$fn__5519.invoke(core_deftype.clj:710) 3: clojure.core$map$fn__3811.invoke(core.clj:2432) 4: clojure.lang.LazySeq.sval(LazySeq.java:42) 5: clojure.lang.LazySeq.seq(LazySeq.java:60) 6: clojure.lang.RT.seq(RT.java:466) 7: clojure.lang.RT.countFrom(RT.java:519) 8: clojure.lang.RT.count(RT.java:512) 9: clojure.lang.Cons.count(Cons.java:49) 10: clojure.lang.Compiler.analyze(Compiler.java:6207) --8---cut here---end---8--- The problem might be that extend-protocol expands into a sequence of extend-type calls, and that into an extend form. The extend-type docs say Propagates the class as a type hint on the first argument of all fns. Clearly, in my case forms like (class 17) don't work as type hint. That said, evaling them won't work either, cause my real code is more like: --8---cut here---start-8--- (let [x (foo)] (extend-protocol BlaBla (get-class x 'Foo) (bla [this] ...) (get-class x 'Bar) (bla [this] ...))) --8---cut here---end---8--- Anyway, I can simply use 3 extend to achieve the same, and that compiles and works fine: --8---cut here---start-8--- (extend (class 17) BlaBla {:bla (fn [this] (inc this))}) (extend (class \s) BlaBla {:bla (fn [this] foo)}) (extend (class s) BlaBla {:bla (fn [this] (reverse this))}) --8---cut here---end---8--- However, it's much less convenient. In my real code, I don't have 3 but ~20 classes that should participate in the BlaBla protocol. So, is this a bug or is it just me trying to do unsupported things? IMHO, if the class is not given literally, then the type hint should be omitted (maybe with a warning)... Bye, Tassilo -- 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
Breaking change to core.logic
Hello all, I'll be changing core.logic so that logic variables are introduced w/ fresh and NOT exist. I'm loathe to make this change now but Daniel Friedman has a forthcoming paper on constraint logic programming with miniKanren (now clpKanren) and Friedman, Byrd, and Kiselyov have all agreed that fresh is a better name. That said, clpKanren is truly stunning - it's an extensible system that allows for CLP(X) and from my initial assessment performs quite well. We'll be incorporating this new research ASAP in core.logic. Given that HM(X) Type Inference is CLP(X) Solvinghttp://www.google.com/url?sa=tsource=webcd=1ved=0CBkQFjAAurl=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.73.6596%26rep%3Drep1%26type%3Dpdfrct=jq=HM(X)%20is%20CLP(X)ei=TsBzTvTYDurF0AHGtrncAgusg=AFQjCNGM_CBtDf2FQSFkJy-P2Ps-ivR30wsig2=mOln5iUPwUhJyafvOakW6A, and the research around GHC 7's type checker, Version 3 PDFhttp://research.microsoft.com/~simonpj/papers/constraints/jfp-outsidein.pdf, I'm excited to see if we can similarly leverage constraint logic programming in the context of Clojure. 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
small project to learn clojure
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hi community, i feel compelled to do something more complex in clojure. not too big, but bigger than what fits in 100 lines and offers some chances to use macros. it should also be fun, maybe something like robocode. - -- -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.14 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJOc8SiAAoJENRtux+h35aGh1cP/jpv1MaEES/5uTPdbDH3Sx45 hVMMC7zw6q2X1b2yEpfxSJzuDoThS7ptI2vQL2izbr9C0fwuBxuXgIXgSgLAl14S mVwnpfn5BIcuNf0QS1QfpJhCLQDJnh+EF13DKnqrNJnP9ACLJ89p8a0CB9SURFCE SgpWoTrAgNKiF1N+P9uP54N7WhwlQ20qkmn+XZDKLJWa4PFlQEpHM32rwYsYpEv8 1eM+X1xR0Z6LEKjbZGyWOShgvN2j4YdosQUWL7FQku2Z7150g13upt6nLNvF9tC6 IO+xlnJ4T68Joq8o3jOBhw+hMszQ0Ax54UfW2Q1QJjiB/E5Ex7NPhCCPdDKcQSPU YWEPHhf/ft9mXWxlEXRhLw1C0R4FwZ6OtNdMLx7X7jk/e/DCjFIxyXinyObm6BVZ sCaX4EzwA16rBeAc3D3LxMigvfm0zxEx1sp1skSyL2HQ7rNb++nR7hJjmd96yT20 MxxbIc0eTj4IZEKz+8W5U+FV7rYa11SREiDq0BBmxi1i3tJarNAAJ9I48OhOFn3y QSAT4/oblh8xa4+FgFLVnWz9rXNJMhBcgVcA1fxJLvysxG4C3MMOhVBRtR4kBt4x OcBDNn+yny4FYknxDQMo9l5VJyBuD6AlHIaKK/eBkikaX06Fwkg6/MgzwMtkJ7yR NT21x0zDCYiXdTa3SNv8 =Gqz8 -END PGP SIGNATURE- -- 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: misuse of or bug in transients?
Am Freitag, 16. September 2011 schrieb David Nolen : I will note: It will probably not become an error because of the reasons I mentioned above and there is no reason to single out transients over all the other types that also return false. Thanks, I just was about to start a thread on dev about contains? and get being to loosely typed. Your response arrived JIT to make me reread your comment about heterogenous collections. The reason to single out transients is that returning false/nil from contains?/get, is a particularly bad interaction after having read http://clojure.org/Transients where it says: Transients support the read-only interface of the source, i.e. you can call *nth*, *get*, *count* and fn-call a transient vector, just like a persistent vector. Since contains? and get on a transient return faulty values anyway, contrary to the doc, why not make it a NotImplementedError for 1.3.0? There are already patches that fix issue and they haven't been applied. True. But Rich didn't seem averse to the idea of making it defined behavior, either. -- 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: Mocking out namespaces
Brian Marick wrote Midje to support Clojure testing with a lot of mocking. May be worth a try: https://github.com/marick/Midje -S -- 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: heaps in clojure
Pepijn de Vos had a blogpost about lazy sorts. One of them seems to be a particularly good fit for this problem: http://pepijndevos.nl/lazy-sorting/index.html (the heap-sort example seems the fastest of those for this use-case...). Em sexta-feira, 16 de setembro de 2011, Mark Engelberg escreveu: That's really no different from just sorting the list and taking the first 5. O(n log(n)). And for really large data sets, this is going to consume a lot of memory. The method I outlined would be O(n) and doesn't force the sequence to all be resident in memory at the same time. On Fri, Sep 16, 2011 at 6:22 AM, Jim Oly james...@gmail.comjavascript:_e({}, 'cvml', 'james...@gmail.com'); wrote: Using PriorityQueue should give a good, fast result. Here's my implementation: (defn smallest-n [n xs] (let [q (java.util.PriorityQueue. xs)] (for [i (range n)] (.poll q (smallest-n 5 (shuffle (range 100))) ;; (0 1 2 3 4) Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.comjavascript:_e({}, 'cvml', '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 javascript:_e({}, 'cvml', 'clojure%2bunsubscr...@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.comjavascript:_e({}, 'cvml', '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 javascript:_e({}, 'cvml', 'clojure%2bunsubscr...@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: heaps in clojure
That heap-sort example is not really lazy. The java.util.concurrent.PriorityBlockingQueue essentially sorts the whole thing, and then the heap-sort is just making a lazy seq over that. Also, note that the speed test at that link is only working with lists of 1000, and the original poster described himself as dealing with large datasets. I doubt these benchmarks will be applicable. On Fri, Sep 16, 2011 at 5:06 PM, Joop Kiefte iko...@gmail.com wrote: Pepijn de Vos had a blogpost about lazy sorts. One of them seems to be a particularly good fit for this problem: http://pepijndevos.nl/lazy-sorting/index.html (the heap-sort example seems the fastest of those for this use-case...). -- 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: misuse of or bug in transients?
IMO, get and contains? should work on transients. If the fn-call variant of get works, the others can for transients be defined in terms of that. Add containsKey to ITransientAssociative and implement containsKey on transient sets and maps to do what calling them as functions does, and the problem is completely solved. I can't see why there'd be any controversy over this, by the way. The behavior violates least surprise, is contrary to the written docu, and is easily fixed without worsening the transients' current performance. -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: small project to learn clojure
Notice something you do often, and try to automate it. Or find an open- source project you use, and you wish were better in some way, and improve it. Learning a language by means of I need to learn something, what should I do is not as effective, or as fun, as learning it by doing something you care about. On Sep 16, 2:50 pm, Dennis Haupt d.haup...@googlemail.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hi community, i feel compelled to do something more complex in clojure. not too big, but bigger than what fits in 100 lines and offers some chances to use macros. it should also be fun, maybe something like robocode. - -- -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.14 (MingW32) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJOc8SiAAoJENRtux+h35aGh1cP/jpv1MaEES/5uTPdbDH3Sx45 hVMMC7zw6q2X1b2yEpfxSJzuDoThS7ptI2vQL2izbr9C0fwuBxuXgIXgSgLAl14S mVwnpfn5BIcuNf0QS1QfpJhCLQDJnh+EF13DKnqrNJnP9ACLJ89p8a0CB9SURFCE SgpWoTrAgNKiF1N+P9uP54N7WhwlQ20qkmn+XZDKLJWa4PFlQEpHM32rwYsYpEv8 1eM+X1xR0Z6LEKjbZGyWOShgvN2j4YdosQUWL7FQku2Z7150g13upt6nLNvF9tC6 IO+xlnJ4T68Joq8o3jOBhw+hMszQ0Ax54UfW2Q1QJjiB/E5Ex7NPhCCPdDKcQSPU YWEPHhf/ft9mXWxlEXRhLw1C0R4FwZ6OtNdMLx7X7jk/e/DCjFIxyXinyObm6BVZ sCaX4EzwA16rBeAc3D3LxMigvfm0zxEx1sp1skSyL2HQ7rNb++nR7hJjmd96yT20 MxxbIc0eTj4IZEKz+8W5U+FV7rYa11SREiDq0BBmxi1i3tJarNAAJ9I48OhOFn3y QSAT4/oblh8xa4+FgFLVnWz9rXNJMhBcgVcA1fxJLvysxG4C3MMOhVBRtR4kBt4x OcBDNn+yny4FYknxDQMo9l5VJyBuD6AlHIaKK/eBkikaX06Fwkg6/MgzwMtkJ7yR NT21x0zDCYiXdTa3SNv8 =Gqz8 -END PGP SIGNATURE- -- 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: including sound or image files with Leiningen uberjar command
On Sep 16, 1:24 am, Joost jo...@zeekat.nl wrote: On Sep 16, 7:20 am, loonster tbur...@acm.org wrote: Sound or image files will show up in the resulting uberjar if they reside in a /resources subdirectory of a Leiningen home project directory. I can't find any documentation for how to refer to and load such resource files within a project.clj and/or a source clj file so that that the resources can be used by a standalone jar. Many thanks for any hints. Tim You can refer to resources using (clojure.java.io/input-stream (clojure.java.io/resource path/to/ image)) See also ring.util.response/resource-response if you want to do this in a war/jar web app. Joost. Well, thanks all. The most succinct code turned out to be (clojure.java.io/resource fileName) and so my test fragment now consists of: (ns depExp (:gen-class)) (import '(java.applet Applet) '(java.io File) '(java.net URL)) (defn -main [ args] (.play (Applet/newAudioClip (clojure.java.io/resource looncall.au ;;;BTW, the looncall.au is a small sound file;;; ...which works fine in the REPL and it also compiles but the resulting standalone jar file throws an error: main java.lang.NullPointerException. Am using lein uberjar. ??? -- 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