use/require/import and quoted form
Hi, I was wondering why use/require and import take quoted forms as their arguments, other alternatives could be strings or keywords, so what is special about the choice of quoted form here? Andy -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
range-sum
Hi all, I often see this code for summing up a range from 0-N : `(reduce + (range N))` However there is a much faster way for this : `(/ (* N (dec N)) 2)` Do you think this should be in the language so that people do not use the slow version? 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Confused by Clojure floating-point differences (compared to other languages)
Just to add a bit to the thread: the Java compiler treats java.lang.Math differently when more efficient alternatives are available. StrictMath is used only as a fallback. From the java.lang.Math javadochttp://docs.oracle.com/javase/7/docs/api/java/lang/Math.html : By default many of the Math methods simply call the equivalent method in StrictMath for their implementation. Code generators are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of Math methods. Such higher-performance implementations still must conform to the specification for Math. Also, check this StackOverflow questionhttp://stackoverflow.com/q/4232231/946814 . As most probably all your versions use the same native libraries or hardware instructions, the differences must rely either on float configuration parameters, like rounding modes, or the other of operations. On Wednesday, February 5, 2014 1:58:45 PM UTC-2, Glen Fraser wrote: Thanks for the tip. After reading your comment, I looked and discovered the Java library called StrictMath, and tried it (replacing Math/cos and Math/sin by the StrictMath versions). I did indeed get different results than with the regular library, but unfortunately still not the same answer as in other languages. I guess the Java implementation(s) are indeed different. It's not a big deal for me, just something I found confusing, wondering if I'd done something wrong. Thanks, Glen. On Wednesday, February 5, 2014 4:06:31 PM UTC+1, Jon Harrop wrote: IIRC, Java provides unusual trigonometric functions which, I’m guessing, Clojure is using. I think the Java ones are actually more accurate (and slower) so you may well find the answer obtained on the JVM is more precise than the others. Cheers, Jon. *From:* clo...@googlegroups.com [mailto:clo...@googlegroups.com] *On Behalf Of *Glen Fraser *Sent:* 05 February 2014 13:17 *To:* clo...@googlegroups.com *Subject:* Confused by Clojure floating-point differences (compared to other languages) (sorry if you received an earlier mail from me that was half-formed, I hit send by accident) Hi there, I'm quite new to Clojure, and was trying to do some very simple benchmarking with other languages. I was surprised by the floating-point results I got, which differed (for the same calculation, using doubles) compared to the other languages I tried (including C++, SuperCollider, Lua, Python). My benchmark iteratively runs a function 100M times: g(x) -- sin(2.3x) + cos(3.7x), starting with x of 0. In the other languages, I always got the result *0.0541718*..., but in Clojure I get *0.24788989* I realize this is a contrived case, but -- doing an identical sequence of 64-bit floating-point operations on the same machine should give the same answer. Note that if you only run the function for about ~110 iterations, you get the same answer in Clojure (or very close), but then it diverges. I assume my confusion is due to my ignorance of Clojure and/or Java's math library. I don't think I'm using 32-bit floats or the BigDecimal type (I even explicitly converted to double, but got the same results, and if I evaluate the *type* it tells me *java.lang.Double*, which seems right). Maybe Clojure's answer is better, but I do find it strange that it's different. Can someone explain this to me? Here are some results: *Clojure: ~23 seconds* (defn g [x] (+ (Math/sin (* 2.3 x)) (Math/cos (* 3.7 x (loop [i 1 x 0] (if (pos? i) (recur (dec i) (g x)) x)) ;; final x: *0.24788989279493556 **(???)* *C++ (g++ -O2): ~4 seconds* double g(double x) { return std::sin(2.3*x) + std::cos(3.7*x); } int main() { double x = 0; for (int i = 0; i 1; ++i) { x = g(x); } std::cout final x: x std::endl; return 0; } // final x: *0.0541718* *Lua: ~39 seconds* g = function(x) return math.sin(2.3*x) + math.cos(3.7*x) end x = 0; for i = 1, 1 do x = g(x) end -- Final x: *0.054171801051906* *Python: ~72 seconds* def g(x): return math.sin(2.3*x) + math.cos(3.7*x) x = 0 for i in xrange(1): x = g(x) # Final x: *0.05417180105190572* *SClang: ~26 seconds* g = { |x| sin(2.3*x) + cos(3.7*x) }; f = { |x| 1.do{ x = g.(x) }; x}; bench{ f.(0).postln }; // final x: *0.054171801051906* (same as C++, Lua, Python; different from Clojure) Thanks, Glen. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@googlegroups.com For more
Re: Confused by Clojure floating-point differences (compared to other languages)
Just to add a bit to the thread: the Java compiler treats java.lang.Math differently when more efficient alternatives are available. StrictMath is used only as a fallback. From the java.lang.Math javadochttp://docs.oracle.com/javase/7/docs/api/java/lang/Math.html : By default many of the Math methods simply call the equivalent method in StrictMath for their implementation. Code generators are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of Math methods. Such higher-performance implementations still must conform to the specification for Math. Also, check this StackOverflow questionhttp://stackoverflow.com/q/4232231/946814 . As most probably all your versions use the same native libraries or hardware instructions, the differences must rely either on float configuration parameters, like rounding modes, or the order of operations. On Wednesday, February 5, 2014 1:58:45 PM UTC-2, Glen Fraser wrote: Thanks for the tip. After reading your comment, I looked and discovered the Java library called StrictMath, and tried it (replacing Math/cos and Math/sin by the StrictMath versions). I did indeed get different results than with the regular library, but unfortunately still not the same answer as in other languages. I guess the Java implementation(s) are indeed different. It's not a big deal for me, just something I found confusing, wondering if I'd done something wrong. Thanks, Glen. On Wednesday, February 5, 2014 4:06:31 PM UTC+1, Jon Harrop wrote: IIRC, Java provides unusual trigonometric functions which, I’m guessing, Clojure is using. I think the Java ones are actually more accurate (and slower) so you may well find the answer obtained on the JVM is more precise than the others. Cheers, Jon. *From:* clo...@googlegroups.com [mailto:clo...@googlegroups.com] *On Behalf Of *Glen Fraser *Sent:* 05 February 2014 13:17 *To:* clo...@googlegroups.com *Subject:* Confused by Clojure floating-point differences (compared to other languages) (sorry if you received an earlier mail from me that was half-formed, I hit send by accident) Hi there, I'm quite new to Clojure, and was trying to do some very simple benchmarking with other languages. I was surprised by the floating-point results I got, which differed (for the same calculation, using doubles) compared to the other languages I tried (including C++, SuperCollider, Lua, Python). My benchmark iteratively runs a function 100M times: g(x) -- sin(2.3x) + cos(3.7x), starting with x of 0. In the other languages, I always got the result *0.0541718*..., but in Clojure I get *0.24788989* I realize this is a contrived case, but -- doing an identical sequence of 64-bit floating-point operations on the same machine should give the same answer. Note that if you only run the function for about ~110 iterations, you get the same answer in Clojure (or very close), but then it diverges. I assume my confusion is due to my ignorance of Clojure and/or Java's math library. I don't think I'm using 32-bit floats or the BigDecimal type (I even explicitly converted to double, but got the same results, and if I evaluate the *type* it tells me *java.lang.Double*, which seems right). Maybe Clojure's answer is better, but I do find it strange that it's different. Can someone explain this to me? Here are some results: *Clojure: ~23 seconds* (defn g [x] (+ (Math/sin (* 2.3 x)) (Math/cos (* 3.7 x (loop [i 1 x 0] (if (pos? i) (recur (dec i) (g x)) x)) ;; final x: *0.24788989279493556 **(???)* *C++ (g++ -O2): ~4 seconds* double g(double x) { return std::sin(2.3*x) + std::cos(3.7*x); } int main() { double x = 0; for (int i = 0; i 1; ++i) { x = g(x); } std::cout final x: x std::endl; return 0; } // final x: *0.0541718* *Lua: ~39 seconds* g = function(x) return math.sin(2.3*x) + math.cos(3.7*x) end x = 0; for i = 1, 1 do x = g(x) end -- Final x: *0.054171801051906* *Python: ~72 seconds* def g(x): return math.sin(2.3*x) + math.cos(3.7*x) x = 0 for i in xrange(1): x = g(x) # Final x: *0.05417180105190572* *SClang: ~26 seconds* g = { |x| sin(2.3*x) + cos(3.7*x) }; f = { |x| 1.do{ x = g.(x) }; x}; bench{ f.(0).postln }; // final x: *0.054171801051906* (same as C++, Lua, Python; different from Clojure) Thanks, Glen. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@googlegroups.com For more
Re: Confused by Clojure floating-point differences (compared to other languages)
Also, I've made a test for this function for all float values in C: https://gist.github.com/brunokim/8843039 Unfortunetely it doesn't work in my system, as it does not have other rounding modes available besides the default. If anyone suceeds in running it, please report. On Thursday, February 6, 2014 10:07:40 AM UTC-2, Bruno Kim Medeiros Cesar wrote: Just to add a bit to the thread: the Java compiler treats java.lang.Math differently when more efficient alternatives are available. StrictMath is used only as a fallback. From the java.lang.Math javadochttp://docs.oracle.com/javase/7/docs/api/java/lang/Math.html : By default many of the Math methods simply call the equivalent method in StrictMath for their implementation. Code generators are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of Math methods. Such higher-performance implementations still must conform to the specification for Math. Also, check this StackOverflow questionhttp://stackoverflow.com/q/4232231/946814 . As most probably all your versions use the same native libraries or hardware instructions, the differences must rely either on float configuration parameters, like rounding modes, or the order of operations. On Wednesday, February 5, 2014 1:58:45 PM UTC-2, Glen Fraser wrote: Thanks for the tip. After reading your comment, I looked and discovered the Java library called StrictMath, and tried it (replacing Math/cos and Math/sin by the StrictMath versions). I did indeed get different results than with the regular library, but unfortunately still not the same answer as in other languages. I guess the Java implementation(s) are indeed different. It's not a big deal for me, just something I found confusing, wondering if I'd done something wrong. Thanks, Glen. On Wednesday, February 5, 2014 4:06:31 PM UTC+1, Jon Harrop wrote: IIRC, Java provides unusual trigonometric functions which, I’m guessing, Clojure is using. I think the Java ones are actually more accurate (and slower) so you may well find the answer obtained on the JVM is more precise than the others. Cheers, Jon. *From:* clo...@googlegroups.com [mailto:clo...@googlegroups.com] *On Behalf Of *Glen Fraser *Sent:* 05 February 2014 13:17 *To:* clo...@googlegroups.com *Subject:* Confused by Clojure floating-point differences (compared to other languages) (sorry if you received an earlier mail from me that was half-formed, I hit send by accident) Hi there, I'm quite new to Clojure, and was trying to do some very simple benchmarking with other languages. I was surprised by the floating-point results I got, which differed (for the same calculation, using doubles) compared to the other languages I tried (including C++, SuperCollider, Lua, Python). My benchmark iteratively runs a function 100M times: g(x) -- sin(2.3x) + cos(3.7x), starting with x of 0. In the other languages, I always got the result *0.0541718*..., but in Clojure I get *0.24788989* I realize this is a contrived case, but -- doing an identical sequence of 64-bit floating-point operations on the same machine should give the same answer. Note that if you only run the function for about ~110 iterations, you get the same answer in Clojure (or very close), but then it diverges. I assume my confusion is due to my ignorance of Clojure and/or Java's math library. I don't think I'm using 32-bit floats or the BigDecimal type (I even explicitly converted to double, but got the same results, and if I evaluate the *type* it tells me *java.lang.Double*, which seems right). Maybe Clojure's answer is better, but I do find it strange that it's different. Can someone explain this to me? Here are some results: *Clojure: ~23 seconds* (defn g [x] (+ (Math/sin (* 2.3 x)) (Math/cos (* 3.7 x (loop [i 1 x 0] (if (pos? i) (recur (dec i) (g x)) x)) ;; final x: *0.24788989279493556 **(???)* *C++ (g++ -O2): ~4 seconds* double g(double x) { return std::sin(2.3*x) + std::cos(3.7*x); } int main() { double x = 0; for (int i = 0; i 1; ++i) { x = g(x); } std::cout final x: x std::endl; return 0; } // final x: *0.0541718* *Lua: ~39 seconds* g = function(x) return math.sin(2.3*x) + math.cos(3.7*x) end x = 0; for i = 1, 1 do x = g(x) end -- Final x: *0.054171801051906* *Python: ~72 seconds* def g(x): return math.sin(2.3*x) + math.cos(3.7*x) x = 0 for i in xrange(1): x = g(x) # Final x: *0.05417180105190572* *SClang: ~26 seconds* g = { |x| sin(2.3*x) + cos(3.7*x) }; f = { |x| 1.do{ x = g.(x) }; x}; bench{ f.(0).postln }; // final x: *0.054171801051906* (same as C++, Lua, Python; different from
Re: range-sum
This seems way too specialised to be in Clojure core. - James On 6 February 2014 10:59, Jim - FooBar(); jimpil1...@gmail.com wrote: Hi all, I often see this code for summing up a range from 0-N : `(reduce + (range N))` However there is a much faster way for this : `(/ (* N (dec N)) 2)` Do you think this should be in the language so that people do not use the slow version? 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Lessons Learned from Adopting Clojure
On Wed, Feb 5, 2014 at 10:40 PM, Sean Corfield s...@corfield.org wrote: FWIW, I find the language of Expectations to be much better suited to describing the desired behaviors of a system I want to build than the assertion-based language of clojure.test - so for me it's about test-before, not test-after. Thinking more on this, when I originally wrote expectations, I was doing all TDD at the time (in IntelliJ). The main focus on expectations syntax as always been around maintainability, and my tdd or test-after opinions would always take a back seat to maintainability. I'm glad it works well for you Sean; hopefully your team is just as happy. =) Cheers, Jay -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Lessons Learned from Adopting Clojure
I've been doing something very similar, but using IntelliJ + Cursive Clojure - run Midje autotest inside the IDE for running tests, and also for manually evaluating snippets of code. plug Cursive gives me a lot of what I had from Emacs - paredit editing, tight repl integration (alt-enter mapped to eval sexp in repl is used heavily), decent code formatting and indentation. And also all the Gui stuff I always found clunky in Emacs: graphical directory tree, tool tips autocomplete, graphical hints for things like git integration, code navigation including Java code. I love emacs, but I'm increasingly frustrated by the limitations of it's mostly-text interface /plug (p.s. I saw Jay's talk at Yow, and it was excellent, though a bit depressing - we had pain getting Clojure working at our client, but far less than Jay did. When the Yow videos come out you can compare his experiences with mine...) - Korny On 5 February 2014 09:09, Colin Yates colin.ya...@gmail.com wrote: Interesting - thanks all. My experience of Light Table is quite close to Norman's, although I discounted that *in my case* to not spending enough time with it. Knowing a little about who Sean is (from following your blog/comments/clojure.jdbc, not stalking! :)) I put a lot of weight behind his opinion. Brian's too, whose emacs's environment is similar to mine. I happen to run midge :autotest in a separate console rather than in emacs with xmonad as my desktop manager (I mention xmonad because if you haven't checked it out you should - you will love it or hate it). Guess I just need to carve out some time to play with it myself. On Wednesday, 5 February 2014 06:09:38 UTC, Sean Corfield wrote: On Tue, Feb 4, 2014 at 6:07 PM, Brian Marick mar...@exampler.com wrote: I always grate at the need to then immortalize the core of what I did in the REPL in repeatable tests. That's actually one of the things that bothered me in the Emacs REPL world: working in the REPL was separate from working in my production source and my test source. It's one of the things that has me really hooked on LightTable. I have my source and test namespaces both open. I have them both connected to a REPL. I can evaluate any code, in place, in either file. If I grow some code in the source file, I can put (defn some-name [args]) in front of it and M-) slurps it into a function - done! If I grow some code in the test file, I can put (expect result-value) in front of it and M-) slurps it into a test - done! Since I moved to LightTable, I've found myself doing even more REPL-Driven-Development than before because it's so much easier to turn the experiments into code - or tests - in place. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Kornelis Sietsma korny at my surname dot com http://korny.info .fnord { display: none !important; } -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [ANN] garden-watch
Lol, fair enough :) On Wed, Feb 5, 2014 at 11:44 PM, Joel Holdbrooks cjholdbro...@gmail.comwrote: Clojure. On Feb 5, 2014, at 8:42 PM, Timothy Washington twash...@gmail.com wrote: Ok, that's fine. Definitely good to have both ways to tackle the problem. But I'm curious. What do you feel is being given up by watching garden files? Thanks Tim Washington Interruptsoftware.com http://interruptsoftware.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 --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Confused by Clojure floating-point differences (compared to other languages)
Probably because you're using 0 through 3 as the arguments to fesetround(), rather than the proper #defined values: (e.g. on my Mac, from fenv.h) #define FE_TONEAREST0x #define FE_DOWNWARD 0x0400 #define FE_UPWARD 0x0800 #define FE_TOWARDZERO 0x0c00 You should use the defines. Glen. On Feb 6, 2014, at 1:18 PM, Bruno Kim Medeiros Cesar brunokim...@gmail.com wrote: Also, I've made a test for this function for all float values in C: https://gist.github.com/brunokim/8843039 Unfortunetely it doesn't work in my system, as it does not have other rounding modes available besides the default. If anyone suceeds in running it, please report. On Thursday, February 6, 2014 10:07:40 AM UTC-2, Bruno Kim Medeiros Cesar wrote: Just to add a bit to the thread: the Java compiler treats java.lang.Math differently when more efficient alternatives are available. StrictMath is used only as a fallback. From the java.lang.Math javadoc: By default many of the Math methods simply call the equivalent method in StrictMath for their implementation. Code generators are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of Math methods. Such higher-performance implementations still must conform to the specification for Math. Also, check this StackOverflow question. As most probably all your versions use the same native libraries or hardware instructions, the differences must rely either on float configuration parameters, like rounding modes, or the order of operations. On Wednesday, February 5, 2014 1:58:45 PM UTC-2, Glen Fraser wrote: Thanks for the tip. After reading your comment, I looked and discovered the Java library called StrictMath, and tried it (replacing Math/cos and Math/sin by the StrictMath versions). I did indeed get different results than with the regular library, but unfortunately still not the same answer as in other languages. I guess the Java implementation(s) are indeed different. It's not a big deal for me, just something I found confusing, wondering if I'd done something wrong. Thanks, Glen. On Wednesday, February 5, 2014 4:06:31 PM UTC+1, Jon Harrop wrote: IIRC, Java provides unusual trigonometric functions which, I'm guessing, Clojure is using. I think the Java ones are actually more accurate (and slower) so you may well find the answer obtained on the JVM is more precise than the others. Cheers, Jon. From: clo...@googlegroups.com [mailto:clo...@googlegroups.com] On Behalf Of Glen Fraser Sent: 05 February 2014 13:17 To: clo...@googlegroups.com Subject: Confused by Clojure floating-point differences (compared to other languages) (sorry if you received an earlier mail from me that was half-formed, I hit send by accident) Hi there, I'm quite new to Clojure, and was trying to do some very simple benchmarking with other languages. I was surprised by the floating-point results I got, which differed (for the same calculation, using doubles) compared to the other languages I tried (including C++, SuperCollider, Lua, Python). My benchmark iteratively runs a function 100M times: g(x) -- sin(2.3x) + cos(3.7x), starting with x of 0. In the other languages, I always got the result 0.0541718..., but in Clojure I get 0.24788989 I realize this is a contrived case, but -- doing an identical sequence of 64-bit floating-point operations on the same machine should give the same answer. Note that if you only run the function for about ~110 iterations, you get the same answer in Clojure (or very close), but then it diverges. I assume my confusion is due to my ignorance of Clojure and/or Java's math library. I don't think I'm using 32-bit floats or the BigDecimal type (I even explicitly converted to double, but got the same results, and if I evaluate the type it tells me java.lang.Double, which seems right). Maybe Clojure's answer is better, but I do find it strange that it's different. Can someone explain this to me? Here are some results: Clojure: ~23 seconds (defn g [x] (+ (Math/sin (* 2.3 x)) (Math/cos (* 3.7 x (loop [i 1 x 0] (if (pos? i) (recur (dec i) (g x)) x)) ;; final x: 0.24788989279493556 (???) C++ (g++ -O2): ~4 seconds double g(double x) { return std::sin(2.3*x) + std::cos(3.7*x); } int main() { double x = 0; for (int i = 0; i 1; ++i) { x = g(x); } std::cout final x: x std::endl; return 0; } // final x: 0.0541718 Lua: ~39 seconds g = function(x) return math.sin(2.3*x) + math.cos(3.7*x) end x = 0; for i = 1, 1 do x = g(x) end -- Final x: 0.054171801051906 Python: ~72 seconds def g(x): return math.sin(2.3*x) + math.cos(3.7*x) x = 0
Alternative - macro for threading sequences?
Hi folks, I seem to regularly find myself writing - threaded code that follows similar patterns: (- things (map wrangle) (map pacify) (filter effable) (map #(aggravate % :bees :sharks)) (reduce mapinate {}) i.e. all stages of the code actually operate on a collection rather than a single value - usually with a call to map at each stage. This example is over simplified - often many of the calls to map are inline functions, which makes this even more verbose. I wonder if there would be value in (yet another) variant on '-' that assumes you are threading a collection and calling 'map' by default. I'm not sure of the syntax that would work though. Something like: ([]- things wrangle pacify [:filter effable] (aggravate :bees :sharks) [:reduce mapinate {}]) I'm not sure about the syntax for non-map functions, I'm not even sure if this is worthwhile. Thoughts? - Korny -- Kornelis Sietsma korny at my surname dot com http://korny.info .fnord { display: none !important; } -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [ANN] Jig
Hi Joachim, I suggest you create a component, C, that assocs a channel in the system map. Now create a component, A that depends on C. A should start and stop a thread in the usual start/stop Lifecycle. The component should get the channel from the system map. The thread should check the resource, and if it changes, put messages on the channel. Components that are dependent on changes to the resource should also depend on C, start go blocks are read from the channel it provides. If you need multiple consumers, a pub/sub mechanism, all that stuff is provided by the core.async API. If you really need to automatically cause a reset, you can do that too - see the API in jig.reset, but it's rarely necessary. I don't think it's what you want to do in this case. Jig Version 2 is in RC status. This is mostly because the documentation (README) needs to catch up. As soon as I've fully updated the docs I'll release the final 2.0.0. Regards, Malcolm On 5 February 2014 10:19, Joachim De Beule joachim.de.be...@gmail.comwrote: Hi Malcolm, I have a follow up question if you don't mind. Suppose I want to define a component that starts a thread and regularly checks a resource. If the resource changes, this has repercussions for other (dependent) components. How would you do that in jig? Maybe this question is too broad, so let me ask some more specific questions. All components should get/set their state from/in the system map, right? Now the system map is a var defined in the user namespace. Does this mean then that the resource-checking thread should alter the system var? And then I guess it should also call user/reset? Or am I still missing something here? BTW, not that I want to press you, but do you have any idea when you will be finishing up version 2? I ask because it seems that the github code currently is kind of in-between versions... Thanks again, Joachim. -- 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 a topic in the Google Groups Clojure group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/E0BdR_AksiA/unsubscribe. To unsubscribe from this group and all its topics, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Alternative - macro for threading sequences?
To be honest I prefer the first although I get your point about the over simplification. If I were going anywhere with this it would be to generalise it into a provided processor, something like: (- :processor map things wrangle ... ) but I am not sure the cognitive load of the extra syntax buys us much. On Thursday, 6 February 2014 14:40:50 UTC, Korny wrote: Hi folks, I seem to regularly find myself writing - threaded code that follows similar patterns: (- things (map wrangle) (map pacify) (filter effable) (map #(aggravate % :bees :sharks)) (reduce mapinate {}) i.e. all stages of the code actually operate on a collection rather than a single value - usually with a call to map at each stage. This example is over simplified - often many of the calls to map are inline functions, which makes this even more verbose. I wonder if there would be value in (yet another) variant on '-' that assumes you are threading a collection and calling 'map' by default. I'm not sure of the syntax that would work though. Something like: ([]- things wrangle pacify [:filter effable] (aggravate :bees :sharks) [:reduce mapinate {}]) I'm not sure about the syntax for non-map functions, I'm not even sure if this is worthwhile. Thoughts? - Korny -- Kornelis Sietsma korny at my surname dot com http://korny.info .fnord { display: none !important; } -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: range-sum
Agreed, but this could be a nice rule for https://github.com/jonase/kibit, maybe? On 6 February 2014 12:42, James Reeves ja...@booleanknot.com wrote: This seems way too specialised to be in Clojure core. - James On 6 February 2014 10:59, Jim - FooBar(); jimpil1...@gmail.com wrote: Hi all, I often see this code for summing up a range from 0-N : `(reduce + (range N))` However there is a much faster way for this : `(/ (* N (dec N)) 2)` Do you think this should be in the language so that people do not use the slow version? 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Karsten Schmidt http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: having trouble with lein-ring :auto-refresh?
I'm starting to think my expectations are wrong and the :auto-refresh? doesn't make the browser refresh. I've never seen it work so what do I know. :) I tried making a new project using the compojure template... $ lein new compojure godoggo I then changed its project.clj to include the :auto-refresh? setting... (defproject godoggo 0.1.0-SNAPSHOT :description FIXME: write description :url http://example.com/FIXME; :dependencies [[org.clojure/clojure 1.5.1] [compojure 1.1.6]] :plugins [[lein-ring 0.8.10]] :ring {:handler godoggo.handler/app *:auto-refresh? true*} :profiles {:dev {:dependencies [[javax.servlet/servlet-api 2.5] [ring-mock 0.1.5]]}}) Ran the server... $ lein ring server The page pops up in my browser OK. But changes to src/godoggo/handler.clj do not show p unless I refresh manually. ... So have I just got it wrong? Does :auto-refresh? do something else? ??? boz On Wednesday, February 5, 2014 11:16:21 PM UTC-8, boz wrote: Hi, I've set up lein-ring with ring :auto-refresh? true but don't see updates in the browser unless I refresh manually. It seems I have something configured wrong but I can't see it. Does this look right?... (defproject mystuff 0.1.0-SNAPSHOT :description experiment :url http://example.com/FIXME; :license {:name Eclipse Public License :url http://www.eclipse.org/legal/epl-v10.html} :dependencies [[org.clojure/clojure 1.5.1] [hiccup 1.0.5]] :plugins [[lein-ring 0.8.10]] :ring {:handler mystuff.core/ring-handler :auto-reload? true :auto-refresh? true} :target-path target/%s) My ring-handler function is basically a copy of the hello world one on ring's site, but the body comes from a defined value. (def x (html [:h1 (hello)])) (defn ring-handler [request] {:status 200 :headers {Content-Type text/html} :body x}) The :auto-reload? true works as expected. But not :auto-refresh? true. I'm after the live coding experience here. And I want it to be with lein-ring if I can. (I tried Daniel Szmulewicz's cool emacs way but I think lein-ring will fit my needs better.) confuzzled, boz -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: having trouble with lein-ring :auto-refresh?
The :auto-refresh option adds in the ring-refresh middleware, which injects Javascript into HTML pages to automatically refresh the page when notified. The HTML page needs to be of content-type text/html, and should be well-formed with a head element. Try checking the source code of the HTML page being served to see if it's correctly injecting the script. - James On 6 February 2014 16:41, boz b...@cox.net wrote: I'm starting to think my expectations are wrong and the :auto-refresh? doesn't make the browser refresh. I've never seen it work so what do I know. :) I tried making a new project using the compojure template... $ lein new compojure godoggo I then changed its project.clj to include the :auto-refresh? setting... (defproject godoggo 0.1.0-SNAPSHOT :description FIXME: write description :url http://example.com/FIXME; :dependencies [[org.clojure/clojure 1.5.1] [compojure 1.1.6]] :plugins [[lein-ring 0.8.10]] :ring {:handler godoggo.handler/app *:auto-refresh? true*} :profiles {:dev {:dependencies [[javax.servlet/servlet-api 2.5] [ring-mock 0.1.5]]}}) Ran the server... $ lein ring server The page pops up in my browser OK. But changes to src/godoggo/handler.clj do not show p unless I refresh manually. ... So have I just got it wrong? Does :auto-refresh? do something else? ??? boz On Wednesday, February 5, 2014 11:16:21 PM UTC-8, boz wrote: Hi, I've set up lein-ring with ring :auto-refresh? true but don't see updates in the browser unless I refresh manually. It seems I have something configured wrong but I can't see it. Does this look right?... (defproject mystuff 0.1.0-SNAPSHOT :description experiment :url http://example.com/FIXME; :license {:name Eclipse Public License :url http://www.eclipse.org/legal/epl-v10.html} :dependencies [[org.clojure/clojure 1.5.1] [hiccup 1.0.5]] :plugins [[lein-ring 0.8.10]] :ring {:handler mystuff.core/ring-handler :auto-reload? true :auto-refresh? true} :target-path target/%s) My ring-handler function is basically a copy of the hello world one on ring's site, but the body comes from a defined value. (def x (html [:h1 (hello)])) (defn ring-handler [request] {:status 200 :headers {Content-Type text/html} :body x}) The :auto-reload? true works as expected. But not :auto-refresh? true. I'm after the live coding experience here. And I want it to be with lein-ring if I can. (I tried Daniel Szmulewicz's cool emacs way but I think lein-ring will fit my needs better.) confuzzled, boz -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: having trouble with lein-ring :auto-refresh?
Thanks James! That was it. Changed my original handler to this and it works perfectly (defn ring-handler [request] {:status 200 :headers {Content-Type text/html} :body (str htmlhead/headbody header change this text /body/html)}) On Thursday, February 6, 2014 9:03:25 AM UTC-8, James Reeves wrote: The :auto-refresh option adds in the ring-refresh middleware, which injects Javascript into HTML pages to automatically refresh the page when notified. The HTML page needs to be of content-type text/html, and should be well-formed with a head element. Try checking the source code of the HTML page being served to see if it's correctly injecting the script. - James On 6 February 2014 16:41, boz b...@cox.net javascript: wrote: I'm starting to think my expectations are wrong and the :auto-refresh? doesn't make the browser refresh. I've never seen it work so what do I know. :) I tried making a new project using the compojure template... $ lein new compojure godoggo I then changed its project.clj to include the :auto-refresh? setting... (defproject godoggo 0.1.0-SNAPSHOT :description FIXME: write description :url http://example.com/FIXME; :dependencies [[org.clojure/clojure 1.5.1] [compojure 1.1.6]] :plugins [[lein-ring 0.8.10]] :ring {:handler godoggo.handler/app *:auto-refresh? true*} :profiles {:dev {:dependencies [[javax.servlet/servlet-api 2.5] [ring-mock 0.1.5]]}}) Ran the server... $ lein ring server The page pops up in my browser OK. But changes to src/godoggo/handler.clj do not show p unless I refresh manually. ... So have I just got it wrong? Does :auto-refresh? do something else? ??? boz On Wednesday, February 5, 2014 11:16:21 PM UTC-8, boz wrote: Hi, I've set up lein-ring with ring :auto-refresh? true but don't see updates in the browser unless I refresh manually. It seems I have something configured wrong but I can't see it. Does this look right?... (defproject mystuff 0.1.0-SNAPSHOT :description experiment :url http://example.com/FIXME; :license {:name Eclipse Public License :url http://www.eclipse.org/legal/epl-v10.html} :dependencies [[org.clojure/clojure 1.5.1] [hiccup 1.0.5]] :plugins [[lein-ring 0.8.10]] :ring {:handler mystuff.core/ring-handler :auto-reload? true :auto-refresh? true} :target-path target/%s) My ring-handler function is basically a copy of the hello world one on ring's site, but the body comes from a defined value. (def x (html [:h1 (hello)])) (defn ring-handler [request] {:status 200 :headers {Content-Type text/html} :body x}) The :auto-reload? true works as expected. But not :auto-refresh? true. I'm after the live coding experience here. And I want it to be with lein-ring if I can. (I tried Daniel Szmulewicz's cool emacs way but I think lein-ring will fit my needs better.) confuzzled, boz -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@googlegroups.com javascript: 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: having trouble with lein-ring :auto-refresh?
Just realized I had name changes ... correction ... changed original to ... (defn ring-handler [request] {:status 200 :headers {Content-Type text/html} :body (str htmlhead/headbody x change this text /body/html)}) And. Of course. I'll change those string tags to hiccup asap :) On Thursday, February 6, 2014 9:25:30 AM UTC-8, boz wrote: Thanks James! That was it. Changed my original handler to this and it works perfectly (defn ring-handler [request] {:status 200 :headers {Content-Type text/html} :body (str htmlhead/headbody header change this text /body/html)}) On Thursday, February 6, 2014 9:03:25 AM UTC-8, James Reeves wrote: The :auto-refresh option adds in the ring-refresh middleware, which injects Javascript into HTML pages to automatically refresh the page when notified. The HTML page needs to be of content-type text/html, and should be well-formed with a head element. Try checking the source code of the HTML page being served to see if it's correctly injecting the script. - James On 6 February 2014 16:41, boz b...@cox.net wrote: I'm starting to think my expectations are wrong and the :auto-refresh? doesn't make the browser refresh. I've never seen it work so what do I know. :) I tried making a new project using the compojure template... $ lein new compojure godoggo I then changed its project.clj to include the :auto-refresh? setting... (defproject godoggo 0.1.0-SNAPSHOT :description FIXME: write description :url http://example.com/FIXME; :dependencies [[org.clojure/clojure 1.5.1] [compojure 1.1.6]] :plugins [[lein-ring 0.8.10]] :ring {:handler godoggo.handler/app *:auto-refresh? true*} :profiles {:dev {:dependencies [[javax.servlet/servlet-api 2.5] [ring-mock 0.1.5]]}}) Ran the server... $ lein ring server The page pops up in my browser OK. But changes to src/godoggo/handler.clj do not show p unless I refresh manually. ... So have I just got it wrong? Does :auto-refresh? do something else? ??? boz On Wednesday, February 5, 2014 11:16:21 PM UTC-8, boz wrote: Hi, I've set up lein-ring with ring :auto-refresh? true but don't see updates in the browser unless I refresh manually. It seems I have something configured wrong but I can't see it. Does this look right?... (defproject mystuff 0.1.0-SNAPSHOT :description experiment :url http://example.com/FIXME; :license {:name Eclipse Public License :url http://www.eclipse.org/legal/epl-v10.html} :dependencies [[org.clojure/clojure 1.5.1] [hiccup 1.0.5]] :plugins [[lein-ring 0.8.10]] :ring {:handler mystuff.core/ring-handler :auto-reload? true :auto-refresh? true} :target-path target/%s) My ring-handler function is basically a copy of the hello world one on ring's site, but the body comes from a defined value. (def x (html [:h1 (hello)])) (defn ring-handler [request] {:status 200 :headers {Content-Type text/html} :body x}) The :auto-reload? true works as expected. But not :auto-refresh? true. I'm after the live coding experience here. And I want it to be with lein-ring if I can. (I tried Daniel Szmulewicz's cool emacs way but I think lein-ring will fit my needs better.) confuzzled, boz -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Alternative - macro for threading sequences?
I agree with Colin, the cognitive load is greater than benefits of such approach. BTW you can use comp to chain consecutive map transformation functions. (map (comp pacify wrangle) things) JW On Thu, Feb 6, 2014 at 3:40 PM, Korny Sietsma ko...@sietsma.com wrote: Hi folks, I seem to regularly find myself writing - threaded code that follows similar patterns: (- things (map wrangle) (map pacify) (filter effable) (map #(aggravate % :bees :sharks)) (reduce mapinate {}) i.e. all stages of the code actually operate on a collection rather than a single value - usually with a call to map at each stage. This example is over simplified - often many of the calls to map are inline functions, which makes this even more verbose. I wonder if there would be value in (yet another) variant on '-' that assumes you are threading a collection and calling 'map' by default. I'm not sure of the syntax that would work though. Something like: ([]- things wrangle pacify [:filter effable] (aggravate :bees :sharks) [:reduce mapinate {}]) I'm not sure about the syntax for non-map functions, I'm not even sure if this is worthwhile. Thoughts? - Korny -- Kornelis Sietsma korny at my surname dot com http://korny.info .fnord { display: none !important; } -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
stch.schema a Prismatic Schema fork
Please check out the repo README page for motivations and differences. Thanks so much to the Prismatic people for open sourcing Schema. It's awesome and I love it. Some of my changes seemed too different to even consider a pull request, so I decided to create my own fork. All feedback is welcome. https://github.com/stch-library/schema -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
set vs hash-set
OK, this one has me stumped. What is the difference between clojure.core/set and clojure.core/hash-set ??? The source code is almost identical. Is one to be preferred over the other depending on circumstances? Alan (defn set Returns a set of the distinct elements of coll. {:added 1.0 :static true} [coll] (clojure.lang.PersistentHashSet/create (seq coll))) (defn hash-set Returns a new hash set with supplied keys. {:added 1.0 :static true} ([] #{}) ([ keys] (clojure.lang.PersistentHashSet/createWithCheck 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 --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: set vs hash-set
One takes a coll and the other a list of arguments user= (set [1 1]) #{1} user= (hash-set 1 1) #{1} On Thu, Feb 6, 2014 at 4:49 PM, Alan Thompson thompson2...@gmail.comwrote: OK, this one has me stumped. What is the difference between clojure.core/set and clojure.core/hash-set ??? The source code is almost identical. Is one to be preferred over the other depending on circumstances? Alan (defn set Returns a set of the distinct elements of coll. {:added 1.0 :static true} [coll] (clojure.lang.PersistentHashSet/create (seq coll))) (defn hash-set Returns a new hash set with supplied keys. {:added 1.0 :static true} ([] #{}) ([ keys] (clojure.lang.PersistentHashSet/createWithCheck 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 --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: range-sum
I think (reduce + (range N)) is commonly used in **examples**, not necessarily in real applications. -S On Thursday, February 6, 2014 5:59:43 AM UTC-5, Jim foo.bar wrote: Hi all, I often see this code for summing up a range from 0-N : `(reduce + (range N))` However there is a much faster way for this : `(/ (* N (dec N)) 2)` Do you think this should be in the language so that people do not use the slow version? 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[ANN] durable-queue: an in-process disk-backed queue
At Factual we get a lot of data thrown at us, and often don't have control over the rate at which it comes in. As such, it's preferable that our buffer isn't bounded by the process' memory, since a temporary blip in throughput may cause GC pauses, OOM exceptions, and other things that will only exacerbate the problem. It's also preferable that if the process dies, we won't lose any data which hasn't yet escaped the process. A disk-backed queue satisfies both of these requirements. As such, I'm happy to announce that we're open sourcing 'durable-queue': https://github.com/Factual/durable-queue. It's a small, fast, pure-Clojure implementation that in our production systems is responsible for processing billions of entries daily. We believe it has broad applications, and are excited to see how others will use it. Zach P.S. If this sort of work is interesting to you, Factual is hiring: https://groups.google.com/forum/#!searchin/clojure/factual/clojure/8bPIEnNpfyQ/lvv-9gkVozAJ -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: range-sum
On Feb 6, 2014, at 12:58 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: I think (reduce + (range N)) is commonly used in *examples*, not necessarily in real applications. I'd have to agree: I don't see anything like that in our 20kloc at World Singles. I see a handful of (reduce + data) for arbitrary series of data values. Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) signature.asc Description: Message signed with OpenPGP using GPGMail
Re: stch.schema a Prismatic Schema fork
fn* and letfn* are special forms. I would double-check that things work as you expect if you (use 'stch.schema). E.g.: (use 'stch.schema) (macroexpand '(fn* simple-fn :- Int [x :- Int] (inc x))) ; = (fn* simple-fn :- Int [x :- Int] (inc x)) ; nope, can't expand special form (macroexpand '(stch.schema/fn* simple-fn :- Int [x :- Int] (inc x))) ; = (let* [ufv__ stch.schema.util/use-fn-validation ...) ; works --Leif On Thursday, February 6, 2014 2:18:58 PM UTC-5, da...@dsargeant.com wrote: Please check out the repo README page for motivations and differences. Thanks so much to the Prismatic people for open sourcing Schema. It's awesome and I love it. Some of my changes seemed too different to even consider a pull request, so I decided to create my own fork. All feedback is welcome. https://github.com/stch-library/schema -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[ANN] clara-rules 0.4 released
The 0.4.0 release of Clara is up on Clojars. The github page is at [1]. The theme of this release is rules as data, which I wrote about at [2]. In a nutshell, all rules and the Rete network itself are defined by well-defined data structures (via Prismatic Schema), which opens a lot of doors: * Alternate front ends to Clara can now be written, generating rules in the schema-compliant format. If the defrule-style DSL isn't your thing, you can generate rules via any mechanism you want. * Tooling can now be written to inspect the rules and their relationships, with some examples in the blog at [2]. * The Rete network itself is also a schema-defined data structure, opening the door for visualizing the working memory itself. There are some breaking changes for the ClojureScript support: I moved the logic to generate a Rete network in ClojureScript to be driven at compile time...meaning we can assemble an optimized network on the server, rather than having the client do that computation every time it loads. Details and an example are linked at [3]. I haven't yet used the ClojureScript version in anger, but am maintaining it because there is interest and it's cool to see this running in a browser. ;) I expect future releases to be smaller and more frequent. Getting Clara on a solid basis of well-defined structures was a significant effort, but I think it puts it in a stronger position with a number of advantages over existing rule engines. [1] https://github.com/rbrush/clara-rules [2] http://www.toomuchcode.org/blog/2014/01/19/rules-as-data/ [3] https://github.com/rbrush/clara-rules/wiki/ClojureScript -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Lessons Learned from Adopting Clojure
On Feb 6, 2014, at 4:49 AM, Jay Fields j...@jayfields.com wrote: I'm glad it works well for you Sean; hopefully your team is just as happy. =) Yup, they love Expectations. Whenever we have to work on our WebDriver tests we always grumble because they are much more imperative and side-effecty so they are not really a match for Expectations - we use clojure.test instead because it's do a bunch of side effecting stuff in the browser, assert that a bunch of conditions are true about the DOM, do a bunch more side effecting stuff, assert more DOM conditions, rinse and repeat... Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) signature.asc Description: Message signed with OpenPGP using GPGMail
NoClassDefFoundError after I import with use on the repl?
I imagine this question has been asked a million times before, but I can not find the answer. I was looking at Raynes/fs library: https://github.com/Raynes/fs/blob/master/src/me/raynes/fs.clj I wanted to check and see if iterate-dir returned a seq of strings (paths) or a seq of File objects (or a seq of something else). So at the repl I: (use 'me.raynes.fs) and, as a test, I run this on my home directory on my Mac: (def all-from-dir (iterate-dir /Users/larry/)) but I get: NoClassDefFoundError me/raynes/fs$iterzip$fn__8508 me.raynes.fs/iterzip (fs.clj:329) While iterate-dir is public, iterzip is private. I assume I am getting this error because iterzip is private, but how am I suppose to work around that? I am calling a public function, why is it not able to call a private function from the namespace where I imported it from? I also tried: (require '[me.raynes.fs :as fsss]) (def all-from-dir (fsss/iterate-dir /Users/larry/)) but I got the same error. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Parsing Clojure with instaparse: how to handle special forms?
I'm trying to use instaparse to parse Clojure code so that I can reformat it, but I'm having an issue with how to handle special forms. Should I attempt to parse special forms such as let and defn into their own rules, or should I rely instead on the actual content of the terminal to determine what lists should be treated as special forms? For example, let's say I want to write a function which takes the parse tree returned by instaparse and arranges all the let bindings as recommended by the Clojure style guide (https://github.com/bbatsov/clojure-style-guide#source-code-layout--organization). There are two approaches I could take: 1) Build the recognition into the grammar itself: S = Form* Form = !SpecialForm List | ReaderMacro | Literal | Vector | Map | SpecialForm | !SpecialForm Symbol List = '(' Form* ')' ... SpecialForm = defn | let | try | JavaMemberAccess | JavaConstructor defn = '(' defn Symbol String? MapMetadata? VectorDestructuring Form* ')' Destructuring = VectorDestructuring | MapDestructuring VectorDestructuring = '[' (Symbol | Destructuring)* ('' (Symbol | Destructuring))? ']' MapDestructuring = Map 2) Don't try to detect the let bindings in the grammar. Instead, search the resulting parse tree for lists with let content. Which of these is a better approach? I sadly didn't take compilers in college so I'm kind of playing this by ear; I'm sure if I had I'd have a better idea of what the best practice is here. Thanks! (Full code for my project is at https://github.com/MoyTW/clojure-toys/tree/master/formatter if needed) -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. S = Form* Form = List | ReaderMacro | Literal | Vector | Map | SpecialForm | Symbol List = '(' Form* ')' ReaderMacro = Quote | SyntaxQuote | Var | Dispatch | Comment | Metadata | QuotedInternal (*TODO - Slash*) Quote = ' Form SyntaxQuote = '`' Form Dispatch = '#' DispatchMacro DispatchMacro = Set | Var | Regex | AnonFuncLit (*TODO - IgnoreForm*) Set = '{' Form* '}' Var = ' Form Regex = String AnonFuncLit = '(' Form* ')' Comment = ';' #'[^\n]*' Metadata = SymbolMetadata | KeywordMetadata | StringMetadata | MapMetadata SymbolMetadata = ^ Symbol Form KeywordMetadata = ^ Keyword Form StringMetadata = ^ String Form MapMetadata = ^ Map Form QuotedInternal = Unquote | UnquoteSplice | GenSym Unquote = '~' Form (*TODO - This should ONLY be used INSIDE a quoted form!*) UnquoteSplice = '~@' Form (*TODO - This should ONLY be used INSIDE a quoted form!*) GenSym = Symbol '#' (*TODO - This should ONLY be used INSIDE a quoted form!*) Symbol = Division | Custom Division = '/' Custom = #'[a-zA-Z\*\+\!\-\_\?\=%][a-zA-Z0-9\*\+\!\-\_\?\=\.%]*/?[a-zA-Z0-9\*\+\!\-\_\?\=\.%]*' Literal = String | Number | Character | Boolean | Keyword | NilLiteral String = '' #'(\\\|[^])*' '' (*Matches \\\ or any char not \*) Number = Integer | Float | Ratio (* TODO - add in support for hex/oct forms*) Integer = #'[+-]?[0-9]+r?[0-9]*' (*The r is so you can do 8r52 - 8 radix 52*) Float = #'[+-]?([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)' | (*Decimal form*) #'[+-]?[0-9]+\.?[0-9]*e[+-]?[0-9]+' (*Exponent form*) Ratio = #'[+-]?[0-9]+/[0-9]+' Character = #'\\.' | '\\newline' | '\\space' | '\\tab' | '\\formfeed' | '\\backspace' | '\\return' (* TODO - add in support for unicode character representations!*) Boolean = 'true' | 'false' Keyword = #'::?[a-zA-Z0-9\*\+\!\-\_\?]*' NilLiteral = 'nil' Vector = '[' Form* ']' Map = '{' (Form Form)* '}'S = Form* Destructuring = VectorDestructuring | MapDestructuring VectorDestructuring = '[' (Symbol | Destructuring)* ('' (Symbol | Destructuring))? ']' MapDestructuring = Map Form = !SpecialForm List | ReaderMacro | Literal | Vector | Map | SpecialForm | !SpecialForm Symbol List = '(' Form* ')' ReaderMacro = Quote | SyntaxQuote | Var | Dispatch | Comment |
Re: NoClassDefFoundError after I import with use on the repl?
I tried to reproduce this behavior with the following environment, and didn't get this error. You may want to provide similar information for your environment in case it helps someone else track down the problem: Mac OS X 10.8.5 Oracle Java 1.7.0_15 Clojure 1.5.1 Leiningen 2.3.4 The following in my project.clj dependencies: [me.raynes/fs 1.4.3] Andy On Thu, Feb 6, 2014 at 9:11 PM, larry google groups lawrencecloj...@gmail.com wrote: I imagine this question has been asked a million times before, but I can not find the answer. I was looking at Raynes/fs library: https://github.com/Raynes/fs/blob/master/src/me/raynes/fs.clj I wanted to check and see if iterate-dir returned a seq of strings (paths) or a seq of File objects (or a seq of something else). So at the repl I: (use 'me.raynes.fs) and, as a test, I run this on my home directory on my Mac: (def all-from-dir (iterate-dir /Users/larry/)) but I get: NoClassDefFoundError me/raynes/fs$iterzip$fn__8508 me.raynes.fs/iterzip (fs.clj:329) While iterate-dir is public, iterzip is private. I assume I am getting this error because iterzip is private, but how am I suppose to work around that? I am calling a public function, why is it not able to call a private function from the namespace where I imported it from? I also tried: (require '[me.raynes.fs :as fsss]) (def all-from-dir (fsss/iterate-dir /Users/larry/)) but I got the same error. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [ANN] Jig
Thanks so much for your suggestions Malcolm, very helpful and illuminating! Joachim. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.