Re: [ANN] Clojure 1.7.0-alpha2
Using my timings macro: https://gist.github.com/fsodomka/5890711 I am getting that: - creation derefing is 60% faster - swapping is 25% faster - resetting is about the same ;; volatile vs. atom ;; (report (timings 1e7 (deref (volatile! 42)) (deref (atom 42 ; | :expr | :time | :ratio | :perc | ; |+---++---| ; | (deref (volatile! 42)) | 30.688238 |1.0 | 39.81 | ; | (deref (atom 42)) | 77.081141 | 2.51 | 100.0 | (report (let [v (volatile! 42) a (atom 42)] (timings 1e7 (vswap! v inc) (swap! a inc ; | :expr | :time | :ratio | :perc | ; |+++---| ; | (vswap! v inc) | 136.052946 |1.0 | 75.08 | ; | (swap! a inc) | 181.218748 | 1.33 | 100.0 | (report (let [v (volatile! 42) a (atom 42)] (timings 1e7 (vreset! v 10) (reset! a 10 ; | :expr | :time | :ratio | :perc | ; |+---++---| ; | (reset! a 10) | 98.755318 |1.0 | 96.69 | ; | (vreset! v 10) | 102.13944 | 1.03 | 100.0 | On Thursday, September 11, 2014 6:18:08 AM UTC+2, puzzler wrote: I'm curious: how much faster are volatiles than atoms? -- 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/d/optout.
Re: [ANN] Clojure 1.7.0-alpha2
And just creation is about 3x faster: (report (timings 1e7 (do (volatile! 42) nil) (do (atom 42) nil))) ; | :expr | :time | :ratio | :perc | ; |-+---++---| ; | (do (volatile! 42) nil) | 22.849963 |1.0 | 31.63 | ; | (do (atom 42) nil) | 72.237439 | 3.16 | 100.0 | On Thursday, September 11, 2014 11:06:44 AM UTC+2, Frantisek Sodomka wrote: Using my timings macro: https://gist.github.com/fsodomka/5890711 I am getting that: - creation derefing is 60% faster - swapping is 25% faster - resetting is about the same ;; volatile vs. atom ;; (report (timings 1e7 (deref (volatile! 42)) (deref (atom 42 ; | :expr | :time | :ratio | :perc | ; |+---++---| ; | (deref (volatile! 42)) | 30.688238 |1.0 | 39.81 | ; | (deref (atom 42)) | 77.081141 | 2.51 | 100.0 | (report (let [v (volatile! 42) a (atom 42)] (timings 1e7 (vswap! v inc) (swap! a inc ; | :expr | :time | :ratio | :perc | ; |+++---| ; | (vswap! v inc) | 136.052946 |1.0 | 75.08 | ; | (swap! a inc) | 181.218748 | 1.33 | 100.0 | (report (let [v (volatile! 42) a (atom 42)] (timings 1e7 (vreset! v 10) (reset! a 10 ; | :expr | :time | :ratio | :perc | ; |+---++---| ; | (reset! a 10) | 98.755318 |1.0 | 96.69 | ; | (vreset! v 10) | 102.13944 | 1.03 | 100.0 | On Thursday, September 11, 2014 6:18:08 AM UTC+2, puzzler wrote: I'm curious: how much faster are volatiles than atoms? -- 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/d/optout.
Re: [ANN] Clojure 1.7.0-alpha2
Hello, I posted a question about volatiles on the github commit: https://github.com/clojure/clojure/commit/60440977823752f13a3fec3637538e9a1d68c5d4 I don't know if anybody noticed, so... why is volatile created with function volatile! and not volatile ? Atoms, refs and agents don't have exclamation mark in their constructor functions. Should I think about volatiles as mutable locals? :-) František On Friday, September 5, 2014 4:26:53 PM UTC+2, Alex Miller wrote: Clojure 1.7.0-alpha1 is now available. Try it via - Download: http://central.maven.org/maven2/org/clojure/clojure/1.7.0-alpha2/ - Download securely: https://repo1.maven.org/maven2/org/clojure/clojure/1.7.0-alpha2/ - Leiningen: [org.clojure/clojure 1.7.0-alpha2] Highlights below, full change log here: https://github.com/clojure/clojure/blob/master/changes.md For users of Clojure 1.7.0-alpha1, there have been a few important changes in transducers since alpha1: - Removed flatmap transducer - Added cat transducer - mapcat 1-arity is now a transducer, specifically: (comp (map f) cat) - The completing function has been lifted to be public Clojure 1.7.0-alpha2 has the changes below from 1.6.0: ## 1 New and Improved Features ### 1.1 Transducers Transducers is a new way to decouple algorithmic transformations from their application in different contexts. Transducers are functions that transform reducing functions to build up a recipe for transformation. Also see: http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming Many existing sequence functions now have a new arity (one fewer argument than before). This arity will return a transducer that represents the same logic but is independent of lazy sequence processing. Functions included are: * conj (conjs to []) * map * mapcat * filter * remove * take * take-while * drop * drop-while * cycle * take-nth * replace * partition-by * partition-all * keep * keep-indexed Additionally some new transducer functions have been added: * cat - concatenates the contents of each input * de-dupe - removes consecutive duplicated values * random-sample - returns items from coll with random probability And this function can be used to make completing transforms: * completing There are also several new or modified functions that can be used to apply transducers in different ways: * sequence - takes a transformation and a coll and produces a lazy seq * transduce - reduce with a transformation (eager) * iteration - returns an iterable/seqable/reducible seq of applications of the transducer to items in coll. Applications are re-performed with every iterator/seq/reduce. * run! - run the transformation for side effects on the collection There have been a number of internal changes to support transducers: * volatiles - there are a new set of functions (volatile!, vswap!, vreset!, volatile?) to create and use volatile boxes to hold state in stateful transducers. Volatiles are faster than atoms but give up atomicity guarantees so should only be used with thread isolation. * array iterators - added support for iterators over arrays Some issues created and addressed during development: * [CLJ-1511](http://dev.clojure.org/jira/browse/CLJ-1511) * [CLJ-1497](http://dev.clojure.org/jira/browse/CLJ-1497) ### 1.2 Keyword and Symbol Construction In response to issues raised in [CLJ-1439]( http://dev.clojure.org/jira/browse/CLJ-1439), several changes have been made in symbol and keyword construction: 1) The main bottleneck in construction of symbols (which also occurs inside keywords) was interning of the name and namespace strings. This interning has been removed, resulting in a performance increase. 2) Keywords are cached and keyword construction includes a cache check. A change was made to only clear the cache reference queue when there is a cache miss. ### 1.3 Warn on Boxed Math One source of performance issues is the (unintended) use of arithmetic operations on boxed numbers. To make detecting the presence of boxed math easier, a warning will now be emitted about boxed math if \*unchecked-math* is enabled. Example use: user (defn plus-2 [x] (+ x 2)) ;; no warning, but boxed #'user/plus-2 user (set! *unchecked-math* true) true user (defn plus-2 [x] (+ x 2)) ;; now we see a warning Boxed math warning, NO_SOURCE_PATH:10:18 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_add(java.lang.Object,long). #'user/plus-2 user (defn plus-2 [^long x] (+ x 2)) ;; use a hint to avoid boxing #'user/plus-2 * [CLJ-1325](http://dev.clojure.org/jira/browse/CLJ-1325) ### 1.4 update - like update-in for first level `update` is a new function that is like update-in specifically for first-level keys: (update m k f args...) Example use: user (update {:a 1} :a inc) {:a 2} user (update {:a 1} :a + 2) {:a 3} user (update {} :a identity) ;;
Re: wally: a alternative way to discover functions
Hello, this gist does the similar thing: https://gist.github.com/jaked/6084411 Maybe you can find some inspiration in it. Frantisek On Thursday, September 5, 2013 11:23:28 PM UTC+2, Islon Scherer wrote: Hey guys, I don't know about you but when I was a beginner in Clojure (and it still happens every now and then) I had a hard time finding functions using `doc` or `find-doc`, normally because I didn't remember the name of the function or because my only clue was a generic name so find-doc would return too much results. But one thing I knew: what to expect of the function, I knew the inputs and the outputs. That's why I decided to create wally, because sometimes you don't know the name of the function you want but you know how it should behave. With wally you can tell the inputs and the output and it'll search for functions that match those inputs/outputs. Ex: user= (find-by-sample {1 1, 2 3, 3 1, 4 2} [1 2 3 4 4 2 2])-clojure.core/frequencies([coll]) Returns a map from distinct items in coll to the number of times they appear. user= (find-by-sample '((1 2 3) (4 5)) (partial 3) [1 2 3 4 5]) - clojure.core/partition-by ([f coll]) Applies f to each value in coll, splitting it each time f returns a new value. Returns a lazy seq of partitions. https://github.com/stackoverflow/wally -- -- 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: Performance Patterns
For my own needs, I wrote a macro 'timings' - see Timing expressions and comparing results: https://groups.google.com/d/msg/clojure/o8pOLc6uxQQ/bui7sJ-F5_wJ Code and examples are here: https://gist.github.com/fsodomka/5890711 Your examples on my machine with Clojure 1.5.1: (report (let [x 2 y [0 1 2 3 4]] (timings 1000 (remove #{x} y) (remove #(= % x) y) (remove #(== % x) y) (remove #(.equals % x) y | :expr | :time | :ratio | :perc | |+---++---| | (remove (fn* [p1__435#] (== p1__435# x)) y) | 28.164219 |1.0 | 3.84 | | (remove (fn* [p1__436#] (.equals p1__436# x)) y) | 28.310134 | 1.01 | 3.86 | | (remove (fn* [p1__434#] (= p1__434# x)) y) | 29.038815 | 1.03 | 3.96 | | (remove #{x} y) | 733.326342 | 26.04 | 100.0 | Using set is 26 times slower than any other way and I would probably pick == for number comparison. (report (let [a (int-array 10)] (timings 1000 (aset a 1 2) (aset-int a 1 2 |:expr | :time | :ratio | :perc | |--+---++---| | (aset a 1 2) | 16.062221 |1.0 | 4.47 | | (aset-int a 1 2) | 359.22866 | 22.36 | 100.0 | aset-int is 22x slower than aset. I would definitely find some resource on performance useful. On the other side, things change and many recommendations are not valid anymore: http://gnuvince.wordpress.com/2009/05/11/clojure-performance-tips/ - destructuring is faster ;-) - spliting (+ 2 4 5) to (+ 2 (+ 4 5)) isn't needed - etc. Performance changes with versions of Clojure. Libraries to consider: https://github.com/hugoduncan/criterium https://github.com/davidsantiago/perforate Frantisek On Sunday, July 14, 2013 10:15:04 AM UTC+2, Marc Dzaebel wrote: I'm often in need of performance comparisons/recommendations about different ways to code the same usecases. E.g. (time(let [x 2 y [0 1 2 3 4]] (dotimes [_ 1000] (remove *#{x}*y ;~950 ms (time(let [x 2 y [0 1 2 3 4]] (dotimes [_ 1000] (remove *#(= % x)*y ;~150 ms (time(let [a (int-array 10)] (dotimes [_ 1000] (*aset *a 1 2;~7 ms (time(let [a (int-array 10)] (dotimes [_ 1000] (*aset-int *a 1 2;~430 ms I'd recommend to gather such information at a central place in a more systematic way. So I wonder: - where to place such information (Wiki?)http://en.wikibooks.org/wiki/Clojure_Programming - whether this information is of use - whether you have more recommendations regarding performance or the form, advices are presented *Thanks, Marc* -- -- 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.
Timing expressions and comparing results
Hi all, If you need to compare running times of different expressions, you could use 'timings' macro: https://gist.github.com/fsodomka/5890711 It takes the number of runs and expressions to time. For example: user= (timings 1e7 (+ 1 2 3 4) (+ 1 (+ 2 (+ 3 4 [{:time 55.028223, :expr (+ 1 2 3 4)} {:time 55.738369, :expr (+ 1 (+ 2 (+ 3 4)))}] Function 'report' prints out comparison of timings. For it to work, function 'clojure.pprint/print-table' is needed (Clojure 1.3+). Results of expressions must be equal (=), otherwise an exception is thrown: user= (timings 1e7 (+ 100 2 3 4) (+ 1 (+ 2 (+ 3 4 Exception Results of expressions are not equal user/eval1153 (NO_SOURCE_FILE:354) I hope you find it useful and it helps your programs to run faster, Frantisek -- -- 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: Compiler bug?
Thank you for the fix, now it works without the problem. It's fun to write grammars with Instaparse :-) On Friday, June 7, 2013 1:29:32 AM UTC+2, puzzler wrote: On Thu, Jun 6, 2013 at 4:27 PM, Mark Engelberg mark.en...@gmail.comjavascript: wrote: Short answer: This is fixed in 1.2.0-SNAPSHOT. To be clear, just change your project file to [instaparse 1.2.0-SNAPSHOT] and you should be good to go. As a bonus, there are some new perf improvements and features already in there, slated for the next release. -- -- 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] Instaparse 1.1.0
Hello Mark, I have few suggestions: 1. I was going through the tutorial and comparing EBNF and ABNF grammars. ABNF adds Bounded Repetition 3*5 A. Is there any chance of adding it also to EBNF? I don't know, how the syntax would be, but it can be useful at times. Repetition of characters can be done inside regular expression. Repetition of rules can be done also - 3*5 A would be: S = A A A A? A? Repetition of 100*120 A is not practical to encode like this anymore. I know about the combinators: {:S (rep 100 120 (nt :A))} and mixing of grammars: (abnf S = 100*130 A) but still, it would be nice to be able to do it inside the EBNF string. Reading through the: http://en.wikipedia.org/wiki/Ebnf 2. I found that EBNF implements an exception operator - http://en.wikipedia.org/wiki/Ebnf#Table_of_symbols used for example like this: string = '' , { all characters - '' }, '' ; Negative lookahead can be used instead string = '' , { !'' all characters }, '' ; Just wanted to let you know about this difference. I can imagine that there many modifications of EBNF grammar out there :-) 3. Returning back to the point 1. and reading http://en.wikipedia.org/wiki/Ebnf#Conventions There actually is a way, how to express repetitions in EBNF: aa = A; bb = 3 * aa, B; cc = 3 * [aa], C; dd = {aa}, D; ee = aa, {aa}, E; ff = 3 * aa, 3 * [aa], F; gg = {3 * aa}, G; Again, don't know if the syntax is optimal. ABNF and regular expressions define it better, in my opinion. Thank you for your good work! Frantisek On Tuesday, May 14, 2013 10:13:52 AM UTC+2, puzzler wrote: Instaparse is an easy-to-use, feature-rich parser generator for Clojure. The big idea behind instaparse is to make it simple to convert grammars to parsers without needing to know the idiosyncrasies of LL1, LALR, and other esoteric grammar restrictions imposed by most parser generators. When I announced instaparse a little over a month ago, I imagined that I had packed so many features into it, that surely there was nothing more that anyone could possibly want. Oh, how naive I was :) . Within a few days, there were a half-dozen great enhancement ideas posted on the github site. Here are the highlights of the new 1.1.0 release: 1. Support for comments in the grammar. (This was by far the most popular request.) 2. A new front-end for ABNF grammars. ABNF is a syntax popular for carefully defining protocols in formal specs. Instaparse's support for ABNF means that it is a simple copy-paste exercise to turn these specifications into an executable parser. 3. The ability to convert EBNF and ABNF *fragments* into Clojure data structures that can be easily merged with one another and with data structures built by the combinator library. https://github.com/Engelberg/instaparse for full feature list and extensive tutorial. https://github.com/Engelberg/instaparse/blob/master/CHANGES.md for a list of changes since the last version. https://github.com/Engelberg/instaparse/blob/master/docs/ABNF.md for detailed docs about the new ABNF syntax. It seems that whenever instaparse comes up, there is an outcry from people who have a visceral reaction against the notion of building a parser from a *string specification* of a grammar. So I want to be clear up front that instaparse supports *three *input formats that you can freely mix-and-match: EBNF strings, ABNF strings, and Clojure data structures. String input is particularly handy since most grammars are already written down somewhere in one of these two notations, but the data structures are an option if you need them. Instaparse also supports two output formats: hiccup and enlive. This release focused mostly on adding new features; the next version will primarily be another round of performance tuning. If you want to follow along and help test as I try out new optimization strategies, keep an eye on the 1.2.0-SNAPSHOT branch: https://github.com/Engelberg/instaparse/tree/v1.2 Special thanks to Alex Engelberg who implemented the new ABNF input format, and David Powell and Peter Monks who suggested the feature and helped test it. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To 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] Instaparse 1.1.0
EBNF syntax for bounded repetition could be just simply A 3*5 and these are equal: A? is A*1 A+ is A1* A* is A0* Frantisek On Monday, June 10, 2013 11:04:52 AM UTC+2, Frantisek Sodomka wrote: Hello Mark, I have few suggestions: 1. I was going through the tutorial and comparing EBNF and ABNF grammars. ABNF adds Bounded Repetition 3*5 A. Is there any chance of adding it also to EBNF? I don't know, how the syntax would be, but it can be useful at times. Repetition of characters can be done inside regular expression. Repetition of rules can be done also - 3*5 A would be: S = A A A A? A? Repetition of 100*120 A is not practical to encode like this anymore. I know about the combinators: {:S (rep 100 120 (nt :A))} and mixing of grammars: (abnf S = 100*130 A) but still, it would be nice to be able to do it inside the EBNF string. Reading through the: http://en.wikipedia.org/wiki/Ebnf 2. I found that EBNF implements an exception operator - http://en.wikipedia.org/wiki/Ebnf#Table_of_symbols used for example like this: string = '' , { all characters - '' }, '' ; Negative lookahead can be used instead string = '' , { !'' all characters }, '' ; Just wanted to let you know about this difference. I can imagine that there many modifications of EBNF grammar out there :-) 3. Returning back to the point 1. and reading http://en.wikipedia.org/wiki/Ebnf#Conventions There actually is a way, how to express repetitions in EBNF: aa = A; bb = 3 * aa, B; cc = 3 * [aa], C; dd = {aa}, D; ee = aa, {aa}, E; ff = 3 * aa, 3 * [aa], F; gg = {3 * aa}, G; Again, don't know if the syntax is optimal. ABNF and regular expressions define it better, in my opinion. Thank you for your good work! Frantisek On Tuesday, May 14, 2013 10:13:52 AM UTC+2, puzzler wrote: Instaparse is an easy-to-use, feature-rich parser generator for Clojure. The big idea behind instaparse is to make it simple to convert grammars to parsers without needing to know the idiosyncrasies of LL1, LALR, and other esoteric grammar restrictions imposed by most parser generators. When I announced instaparse a little over a month ago, I imagined that I had packed so many features into it, that surely there was nothing more that anyone could possibly want. Oh, how naive I was :) . Within a few days, there were a half-dozen great enhancement ideas posted on the github site. Here are the highlights of the new 1.1.0 release: 1. Support for comments in the grammar. (This was by far the most popular request.) 2. A new front-end for ABNF grammars. ABNF is a syntax popular for carefully defining protocols in formal specs. Instaparse's support for ABNF means that it is a simple copy-paste exercise to turn these specifications into an executable parser. 3. The ability to convert EBNF and ABNF *fragments* into Clojure data structures that can be easily merged with one another and with data structures built by the combinator library. https://github.com/Engelberg/instaparse for full feature list and extensive tutorial. https://github.com/Engelberg/instaparse/blob/master/CHANGES.md for a list of changes since the last version. https://github.com/Engelberg/instaparse/blob/master/docs/ABNF.md for detailed docs about the new ABNF syntax. It seems that whenever instaparse comes up, there is an outcry from people who have a visceral reaction against the notion of building a parser from a *string specification* of a grammar. So I want to be clear up front that instaparse supports *three *input formats that you can freely mix-and-match: EBNF strings, ABNF strings, and Clojure data structures. String input is particularly handy since most grammars are already written down somewhere in one of these two notations, but the data structures are an option if you need them. Instaparse also supports two output formats: hiccup and enlive. This release focused mostly on adding new features; the next version will primarily be another round of performance tuning. If you want to follow along and help test as I try out new optimization strategies, keep an eye on the 1.2.0-SNAPSHOT branch: https://github.com/Engelberg/instaparse/tree/v1.2 Special thanks to Alex Engelberg who implemented the new ABNF input format, and David Powell and Peter Monks who suggested the feature and helped test it. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send
Re: [ANN] Instaparse 1.1.0
Large bounded repetition is a theoretical question. My use case requires to ensure repetition of only small number of digits - one digit, two digits and similar. I would use bounded repetition to ensure the needed number of digits. Yes, different workarounds will work for me, so it is not a pressing problem. Googling the exception operator: http://avisynth.org/mediawiki/User:Gzarkadas/EBNF Exception The effect is the logical negation of the rule following. For example -a becomes ? all characters not equal to a ?. They use it here: stringliteral = quote , { -quote } , quote | tripleqouote , { -tripleqouote } , tripleqouote ; So it is something like everything else than. In Instaparse we would define exception + set S = !'a' #'.' They just define exception S = -'a' On Monday, June 10, 2013 11:26:13 AM UTC+2, puzzler wrote: On Mon, Jun 10, 2013 at 2:13 AM, Frantisek Sodomka fsod...@gmail.comjavascript: wrote: EBNF syntax for bounded repetition could be just simply A 3*5 and these are equal: A? is A*1 A+ is A1* A* is A0* Right now, in the EBNF syntax, numbers are valid non-terminal identifiers. So for example, rather than S = A B+, you could do 1 = 2 3+. I thought this might be useful for programmatically generated grammars. Adding a bounded repetition operator to EBNF is certainly possible, but the most obvious syntaxes would eliminate the use of numbers as identifiers. Have you actually encountered a real example where you wished for the large bounded repetition, or is this just a theoretical question? Even in the ABNF examples I've seen (which has the bounded repetition option), most instances of repetition correspond to the standard + * and ? operators. I've seen the exception operator listed on a couple of tables, but have never seen it in use, and didn't come across a clear explanation of its semantics. Can you point me to a fuller description of what it does? -- -- 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] Instaparse 1.1.0
I am just curious, not requesting this feature :-) How to represent negation in BNF? http://stackoverflow.com/questions/10922352/how-to-represent-negation-in-bnf http://pythonhosted.org/modgrammar/libref.html modgrammar.EXCEPT(grammar, exc_grammar, **kwargs) Match grammar, but only if it does not also match exception_grammar. (This is equivalent to the - (exception) operator in EBNF) EXCEPT() grammars can also be created by combining other grammars in python expressions using the except operator (-). Note: In many cases there are more efficient ways to design a particular grammar than using this construct. It is provided mostly for full EBNF compatibility. modgrammar.EXCEPT function would do difference or complement mentioned on stackoverflow. Seems like a sane approach - we know the set we are excluding from. Concerning negating characters - yes, it is quite tricky. I don't yet how to define it... Does S = -ab ab c matches abc or just c? Dne pondělí, 10. června 2013 12:10:00 UTC+2 puzzler napsal(a): Yeah, that's still not clear to me. It says it is the logical negation of a rule but then goes on to say that it negates the characters. What does -ab mean? If you're just negating characters, in instaparse you can just use regex's capability to express negative character classes. So, for example, every character but an a is most clearly and efficiently expressed as #[^a]. http://www.regular-expressions.info/charclass.html -- -- 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.
Compiler bug?
Hi all, I am trying new parsing library Instaparse. I setup a Leiningen project, included [instaparse 1.1.0] as my dependency and tried to run it. Unfortunately, I am getting this error: Exception in thread main java.lang.NoClassDefFoundError: instaparse/print$parser__GT_str (wrong name: instaparse/print$Parser__GT_str) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at instaparse.print__init.load(Unknown Source) at instaparse.print__init.clinit(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at clojure.lang.RT.loadClassForName(RT.java:2098) at clojure.lang.RT.load(RT.java:430) Inside compiled class: target\classes\instaparse\print$parser__GT_str.class is a string instaparse/print$Parser__GT_str, which I believe is a name of a class. Class name and file name do not match - lowercase p versus uppercase P in $parser. Windows 7 64-Bit Leiningen 2.2.0 on Java 1.6.0_35 Java HotSpot(TM) 64-Bit Server VM Instaparse 1.1 has a dependency on [org.clojure/clojure 1.5.1]. Is this a bug inside the Clojure compiler? Or is my setup wrong? Downloading just Instaparse (branch 1.1) from github and compiling it yields the same class/file name difference. Thank you for your help, Frantisek -- -- 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: Logos - core.logic
Hello David, thanks for your work. It is very interesting addition. One thing that came to my mind, is a language Mercury: http://en.wikipedia.org/wiki/Mercury_(programming_language) http://www.mercury.csse.unimelb.edu.au/ Mercury is a new logic/functional programming language, which combines the clarity and expressiveness of declarative programming with advanced static analysis and error detection features. Its highly optimized execution algorithm delivers efficiency far in excess of existing logic programming systems, and close to conventional programming systems. Mercury addresses the problems of large-scale program development, allowing modularity, separate compilation, and numerous optimization/time trade-offs. It is based on both Prolog and Haskell and claims to be very fast. Maybe you could check it out and see, what makes it different and maybe worthwhile studying. Some parts could be useful and shed some light on union of functional and logical universes :-) Lots of fun with logical programming wishes, Frantisek PS: Not meant as advertisement of Mercury. On Thu, Apr 28, 2011 at 9:19 PM, David Nolen dnolen.li...@gmail.com wrote: On Thu, Apr 28, 2011 at 3:05 PM, Nick Zbinden nick...@gmail.com wrote: Hallo David, Very cool that this is moving to contrib. I saw that you gave a presentation at NYC Clojure User Groupe. Was that tapped? If not I think it would be very cool if you could do a screencast with simular content. The videos of rich showing of clojure a reason why some of use are here (including me) and I think it would be great if we had something like this for your library (and logic programming spezially). Sadly it wasn't recorded, but it went over very well. Like you sad logic programming is not well known yet and its hard to tell people what it is spezially if your not an expert yourself. It would be great to just be able to send somebody a link of a video expmlaing a little bit about it (in clojure). Nick Well I wouldn't consider myself an expert in any of these matters, but I'm interested in making the library more accessible so tutorials and screencasts are something I'm thinking about. 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: Performance question (newbie)
If you make it into a function and use type hints, that should help: (defn sum [n] (let [n (int n)] (loop [ret (long 0) i (int 1)] (if ( i n) (recur (+ ret i) (inc i)) ret user= (time (reduce + (range 1 100))) Elapsed time: 116.959837 msecs 4950 user= (time (sum 100)) Elapsed time: 6.151341 msecs 4950 Frantisek On Jul 15, 1:51 pm, Dragan draga...@gmail.com wrote: Hi, I am trying to compare the performance of java loops to clojure reduce function. Noting special, Since I am just learning. Java code is something like: [code] long sum = 0; for (int i = 1; i 100; i++ ){ sum = sum + i;} [/code] while in Clojure I used: [code] (reduce + (range 1 i)) [/code] Execution time for the Java version is 7 ms, while Clojure needs 60 - 160 ms. Now, that is expected, since Clojure runs in REPL. Next, I tried the gen-class of the Clojure, and called that Class from Java (so no REPL involved), but the code haven't speed up at all! Am I missing something or such 10x performance penalty is usual for such operations? --~--~-~--~~~---~--~~ 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: Performance question (newbie)
PS: Read tips on: http://clojure.org/java_interop On Jul 15, 1:51 pm, Dragan draga...@gmail.com wrote: Hi, I am trying to compare the performance of java loops to clojure reduce function. Noting special, Since I am just learning. Java code is something like: [code] long sum = 0; for (int i = 1; i 100; i++ ){ sum = sum + i;} [/code] while in Clojure I used: [code] (reduce + (range 1 i)) [/code] Execution time for the Java version is 7 ms, while Clojure needs 60 - 160 ms. Now, that is expected, since Clojure runs in REPL. Next, I tried the gen-class of the Clojure, and called that Class from Java (so no REPL involved), but the code haven't speed up at all! Am I missing something or such 10x performance penalty is usual for such operations? --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
Jonathan showed destructuring/indexing very nicely. Here are some timings for vector/list creation: (let [lst '(1 2 3)] (timings 1e7 (list 1 2 3) (cons 1 (cons 2 (cons 3 ( (conj (conj (conj () 3) 2) 1) (vector 1 2 3) (vec lst) (conj (conj (conj [] 1) 2) 3))) 6590.33 ms 61.2% 1.6x (list 1 2 3) 7571.30 ms 70.3% 1.4x (cons 1 (cons 2 (cons 3 ( 7773.67 ms 72.2% 1.4x (conj (conj (conj () 3) 2) 1) 9601.74 ms 89.1% 1.1x (vector 1 2 3) 8612.29 ms 79.9% 1.3x (vec lst) 10772.88 ms 100.0% 1.0x (conj (conj (conj [] 1) 2) 3) Yes, it looks that list creation is faster than vector creation. Frantisek On Jul 9, 12:17 am, John Harrop jharrop...@gmail.com wrote: On Wed, Jul 8, 2009 at 4:57 PM, Frantisek Sodomka fsodo...@gmail.comwrote: So far it seems that vectors win in Clojure: (timings 3e5 (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c))) = 680.63 ms 83.6% 1.2x (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) 813.79 ms 100.0% 1.0x (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c)) Does using vec instead of vector make a difference? Using first, rest, first, rest instead of nth to destructure the list? --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
If result is a vector v, then from these 4 cases: (let [v [1 2 3]] (let [[a b c] v] a b c) (let [a (v 0) b (v 1) c (v 2)] a b c) (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z)) using 'nth' (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) is the fastest. Frantisek On Jul 7, 11:10 pm, John Harrop jharrop...@gmail.com wrote: Problem: Passing primitives from an inner loop to an outer loop efficiently. Here is what I've found. The fastest method of result batching, amazingly, is to pass out a list and: (let [foo (loop ... ) x (double (first foo)) r1 (rest foo) y (double (first r1)) r2 (rest r1) z (double (first r2))] ... ) (here passing out three doubles). About half as fast is: (let [[x y z] (loop ... )] ... ) with (double x), (double y), and (double z) used later in place of x y z and only one occurrence of each (so no more (double foo) conversions than before). The destructuring bind apparently exerts a higher run-time overhead compared to manual destructuring. (with-locals [x (double 0) y (double 0) z (double 0)] (loop ... ) (do-something-with (double (var-get x)) (double (var-get y)) (double (var-get z is two full orders of magnitude slower (here the loop doesn't return a list but uses var-set). Using atoms is even worse. (let [#^doubles xyz (double-array (int 3))] (loop ... ) (do-something-with (aget xyz (int 0)) (aget xyz (int 1)) (aget xyz (int 2 with the loop using aset-double to pass out values is, surprisingly, no faster. Using plain aset makes no difference, as does removing the (int ...) wrappings around the numbers. Intermediate in speed is using a clojure vector to pass out values, e.g. [result-x result-y result-z] is the expression that returns a value from the loop, and (do-something-with (get results (int 0)) (get results (int 1)) (get results (int 2))) It's surprising that this is faster than using a primitive Java array with type-hints, and interesting that retrieving sequential items from a list is faster than a like number of in-order indexed retrievals from a vector, which could theoretically be optimized to a pointer-walk with each retrieval involving an increment and a dereference and a store, rather than an increment, three dereferences, and a store. (Dereference linked list entry item pointer, store, increment pointer, dereference to get next-entry pointer, dereference again, repeat.) Whatever, these results may be useful to someone, along with: (defn- extract-result-list-into [conv hint gensyms result-generator] (let [rs (take (count gensyms) (repeatedly gensym))] (into [(first rs) result-generator] (loop [r rs g (if hint (map #(with-meta % {:tag hint}) gensyms) gensyms) output []] (if (empty? r) output (let [fr (first r) rr (rest r) frr (first rr)] (recur (rest r) (rest g) (into output (concat [(first g) (if conv `(~conv (first ~fr)) `(first ~fr))] (if frr [frr `(rest ~fr)])) This helper function can be used in a macro to suck the contents of a list into variables with conversions, type hints, or both; conv would be a symbol like `double, hint something like BigInteger, gensyms some gensyms (or other symbols) for the variable names (in order), and result-generator some code (e.g. resulting from a backtick expression). The output is a vector resembling [G__5877 (loop ... whatever code) #^hint G__5874 (conv (first G__5877)) G_5878 (rest G__5877) #^hint G__5875 (conv (first G__5878)) G_5879 (rest G__5878) #^hint G__5876 (conv (first G__5879))] which can be used in a let, loop, or other construct that uses bindings with the usual clojure syntax, and can even have other things added to it by macro code. The downside is relative inflexibility. If you pass in a gensyms seq with an embedded vector of two gensyms you'll get a valid destructuring bind for a composite item in the results, but it won't work with type hints or conversions, nor can those be mixed. Making it more sophisticated would be possible, though. This arose when I had a performance-critical double-barreled loop to optimize, and found that the outer loop was spending several thousand iterations of the inner loop worth of time just to extract the results via with-locals. I did some experimenting and benchmarking of various ways to get the output of the inner loop to code in the outer loop, using System/nanoTime, millions of repetitions, and averaging to determine the winner. An efficient labeled recur would be nice for clojure 2.0. :) (Limited though it would be to when the inner loop was in tail position in the outer loop.) --~--~-~--~~~---~--~~ 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
Re: Passing primitives from an inner loop to an outer loop efficiently
To compare timings, I use this macro: (defmacro time-ms [n expr] `(let [start# (. System (nanoTime))] (dotimes [i# ~n] ~expr) (/ (double (- (. System (nanoTime)) start#)) 100.0))) (defmacro timings [n expr] (let [expr-are-not-equal (cons 'not= expr) expr-times (cons 'vector (map #(list 'time-ms n %) expr))] `(if ~expr-are-not-equal (do (println Expressions:\n) (dorun (map prn '~expr)) (println \nare NOT equal!)) (let [ts# ~expr-times max-time# (apply max ts#)] (dorun (map (fn [~'t ~'e] (printf %8.2f ms %6.1f%% %5.1fx ~'t (* 100.0 (/ ~'t max-time#)) (/ max-time# ~'t)) (prn ~'e)) ts# '~expr)) Use is: user= (timings 1e6 (+ 2 4 5) (+ 2 (+ 4 5))) 727.50 ms 100.0% 1.0x (+ 2 4 5) 353.18 ms 48.5% 2.1x (+ 2 (+ 4 5)) For our case: (let [v [1 2 3] lst '(1 2 3)] (timings 1e5 (let [[a b c] v] [a b c]) (let [a (v 0) b (v 1) c (v 2)] [a b c]) (let [a (nth v 0) b (nth v 1) c (nth v 2)] [a b c]) (let [a (first v) b (second v) c (first (rest (rest v)))] [a b c]) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] [x y z]) (let [[a b c] lst] [a b c]) ;; (let [a (lst 0) b (lst 1) c (lst 2)] [a b c]) (let [a (nth lst 0) b (nth lst 1) c (nth lst 2)] [a b c]) (let [a (first lst) b (second lst) c (first (rest (rest lst)))] [a b c]) (let [x (first lst) r1 (rest lst) y (first r1) r2 (rest r1) z (first r2)] [x y z]))) And on my computer I get these numbers: 145.86 ms 64.5% 1.6x (let [[a b c] v] [a b c]) 97.37 ms 43.1% 2.3x (let [a (v 0) b (v 1) c (v 2)] [a b c]) 94.66 ms 41.9% 2.4x (let [a (nth v 0) b (nth v 1) c (nth v 2)] [a b c]) 226.15 ms 100.0% 1.0x (let [a (first v) b (second v) c (first (rest (rest v)))] [a b c]) 205.05 ms 90.7% 1.1x (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] [x y z]) 219.42 ms 97.0% 1.0x (let [[a b c] lst] [a b c]) 171.32 ms 75.8% 1.3x (let [a (nth lst 0) b (nth lst 1) c (nth lst 2)] [a b c]) 179.03 ms 79.2% 1.3x (let [a (first lst) b (second lst) c (first (rest (rest lst)))] [a b c]) 170.41 ms 75.4% 1.3x (let [x (first lst) r1 (rest lst) y (first r1) r2 (rest r1) z (first r2)] [x y z]) Frantisek On Jul 8, 9:53 am, John Harrop jharrop...@gmail.com wrote: On Wed, Jul 8, 2009 at 3:42 AM, Frantisek Sodomka fsodo...@gmail.comwrote: If result is a vector v, then from these 4 cases: (let [v [1 2 3]] (let [[a b c] v] a b c) (let [a (v 0) b (v 1) c (v 2)] a b c) (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) (let [x (first v) r1 (rest v) y (first r1) r2 (rest r1) z (first r2)] x y z)) using 'nth' (let [a (nth v 0) b (nth v 1) c (nth v 2)] a b c) is the fastest. Is it faster than using list and manually destructuring the list? If so, that would mean that (nth v n) is faster than (get v n), which would be odd since the latter should turn into the former anyway and be inlinable by the JIT. --~--~-~--~~~---~--~~ 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: Passing primitives from an inner loop to an outer loop efficiently
So far it seems that vectors win in Clojure: (timings 3e5 (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c))) = 680.63 ms 83.6% 1.2x (let [v (vector 1 2 3) a (nth v 0) b (nth v 1) c (nth v 2)] (+ a b c)) 813.79 ms 100.0% 1.0x (let [lst (list 1 2 3) a (nth lst 0) b (nth lst 1) c (nth lst 2)] (+ a b c)) Frantisek On Jul 8, 7:29 pm, John Harrop jharrop...@gmail.com wrote: Interesting. How are these timings affected if you add in the time taken to pack the list or vector in the first place, though? I have the feeling it may be slightly cheaper to unpack a vector, but noticeably cheaper to pack a list... --~--~-~--~~~---~--~~ 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 performance and timings
Hello all! After reading this article: Clojure performance tips http://gnuvince.wordpress.com/2009/05/11/clojure-performance-tips/ I wrote a macro to better compare different timings of functions and expressions: (defmacro time-ms [n expr] `(let [start# (. System (nanoTime))] (dotimes [i# ~n] ~expr) (/ (double (- (. System (nanoTime)) start#)) 100.0))) (defmacro timings [n expr] (let [expr-are-not-equal (cons 'not= expr) expr-times (cons 'vector (map #(list 'time-ms n %) expr))] `(if ~expr-are-not-equal (do (println Expressions:\n) (dorun (map prn '~expr)) (println \nare NOT equal!)) (let [~'ts ~expr-times ~'max-time (apply max ~'ts)] (dorun (map (fn [~'t ~'e] (printf %8.2f ms %6.1f%% %5.1fx ~'t (* 100.0 (/ ~'t ~'max-time)) (/ ~'max-time ~'t)) (prn ~'e)) ~'ts '~expr)) Here are the examples: (timings 1e6 (+ 2 4 5) (+ 2 (+ 4 5))) 787.96 ms 100.0% 1.0x (+ 2 4 5) 360.94 ms 45.8% 2.2x (+ 2 (+ 4 5)) ;;; (timings 1 (dotimes [i 1e6] (= i i)) (dotimes [i 1e6] (== i i))) 444.39 ms 100.0% 1.0x (dotimes [i 100.0] (= i i)) 237.29 ms 53.4% 1.9x (dotimes [i 100.0] (== i i)) (timings 1 (dotimes [i 1e6] (= i 10)) (dotimes [i 1e6] (== i 10))) 368.37 ms 100.0% 1.0x (dotimes [i 100.0] (= i 10)) 324.65 ms 88.1% 1.1x (dotimes [i 100.0] (== i 10)) ;;; (let [v [1 2 3]] (timings 1e6 (let [[a b c] v] a b c) (let [a (v 0) b (v 1) c (v 2)] a b c))) 920.15 ms 100.0% 1.0x (let [[a b c] v] a b c) 486.82 ms 52.9% 1.9x (let [a (v 0) b (v 1) c (v 2)] a b c) ;;; (def v 3) (let [l 3] (timings 1e6 v l)) 172.42 ms 100.0% 1.0x v 118.20 ms 68.6% 1.5x l ;;; (defn len [x] (.length x)) (defn len2 [#^String x] (.length x)) (def s abcdef) (timings 1e5 (len s) (len2 s)) 1655.12 ms 100.0% 1.0x (len s) 32.82 ms2.0% 50.4x (len2 s) Interesting is that the speed difference is smaller than in the article. Bug reports and suggestions are welcome! Frantisek --~--~-~--~~~---~--~~ 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: Contributing tests
Hello Richard, any contributions to test_clojure are very welcome! As a general rule to contribute, you need to fill-in and mail the CA: http://clojure.org/contributing When Rich receives your CA and updates the clojure.org website, you can start creating issues in clojure-contrib and attaching patches to it. Example: http://code.google.com/p/clojure-contrib/issues/detail?id=22 Then somebody can come and check-in your tests. After a while, you could get your own clojure-contrib check-in rights, but that is solely Rich's decision. I am currently writing tests for java_interop, so please don't do any of those now. http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/test_clojure/java_interop.clj Good way to contribute is also to write regression tests as for example in vars: http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/test_clojure/vars.clj Files in test_clojure represent different areas - feel free to take your pick and do whatever you like :-) Happy testing, Frantisek On Jun 4, 6:31 pm, Richard Newman holyg...@gmail.com wrote: One of the things that occurred to me at last night's Meetup is that there seems to be a sizable group of people who are keen on contributing to Clojure, including basic drudge work. It also seems apparent that having a decent test suite is valuable (if only for the sake of appearances and adoption), though I tend to agree that it's not a good use of Rich's time. While this contribution would indeed be easier with git, I'm disinclined to wait: I'm personally intending to take a look at the existing tests in contrib, and if I can figure out the test framework, I'll crank out a few tests for the core. If a few people did this, tests will accrue over time. Perhaps more importantly, if we manage to inculcate the attitude that questions, bugs, and misunderstandings should be captured as tests, then the important areas — edge cases and bug fixes — will grow coverage, all without Rich wasting his time. Thoughts? Opinions? Advice on the test framework? Would my time be better spent documenting what I learn about the test framework? Should I go back to bed and get more sleep? :) --~--~-~--~~~---~--~~ 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: svn r1370 appears to have broken binding
Hello Steve! When I write a test for binding for this case (using deftest) and run test_clojure, it doesn't error out. I wonder why is that? (def a) (deftest test-binding (are (= _1 _2) (binding [a 4] a) 4 ; regression in Clojure SVN r1370 )) Frantisek PS: Rich, have you seen my bug report? Minor bug in int-array, long-array, float-array and double-array http://groups.google.com/group/clojure/browse_frm/thread/0f4e5090770d8a5a# On May 25, 11:35 am, Stephen C. Gilardi squee...@mac.com wrote: With svn r1370, I get this: % java -cp clojure.jar clojure.main Clojure 1.1.0-alpha-SNAPSHOT user= (def a) #'user/a user= (binding [a 4] a) java.lang.IllegalStateException: Var user/a is unbound. (NO_SOURCE_FILE:0) user= With svn r1369, I get this: % java -cp clojure.jar clojure.main Clojure 1.1.0-alpha-SNAPSHOT user= (def a) #'user/a user= (binding [a 4] a) 4 user= I expected the r1369 behavior. --Steve smime.p7s 3KViewDownload --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Minor bug in int-array, long-array, float-array and double-array
It looks that there is a bug in int-array, long-array, float-array and double-array when creating an array using an empty sequence. Doc: clojure.core/int-array ([size-or-seq] [size init-val-or-seq]) Creates an array of ints This works: user= (int-array 0) #int[] [...@11978b user= (vec (int-array 0)) [] user= (alength (int-array 0)) 0 This throws NPE: user= (int-array []) java.lang.NullPointerException (NO_SOURCE_FILE:0) user= (long-array []) java.lang.NullPointerException (NO_SOURCE_FILE:0) user= (float-array []) java.lang.NullPointerException (NO_SOURCE_FILE:0) user= (double-array []) java.lang.NullPointerException (NO_SOURCE_FILE:0) All other possible combinations seem to work. Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: Minor bug in int-array, long-array, float-array and double-array
Sorry, forgot to mention: Found when testing Clojure 1.0.0. Frantisek --~--~-~--~~~---~--~~ 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 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: I'm experimenting clojure - sorted-set-by?
Hello! Yes, you are right, sorted-set-by is missing. Good news is - it is on the way :-) See issue 76: http://code.google.com/p/clojure/issues/detail?id=76 Frantisek On Mar 24, 5:35 am, hjlee hj.d@gmail.com wrote: Hi, all. I don't know why my previous posts ignored. spam filtering? so i changed title. I'm experimenting clojure. Some code, I needed something like sorted-set-by, but no such thing. So i used sorted-map-by ignoring value part. Is it deliberate for some reason? Or just not there? --~--~-~--~~~---~--~~ 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 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: Possible Bug In clojure.zip/remove
On Mar 19, 12:58 pm, Jason Sankey ja...@zutubi.com wrote: Also, is there somewhere I can contribute test cases for this to prevent a future regression? Tests for clojure.zip can from now on go to test-clojure.clojure-zip: http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/test_clojure/clojure_zip.clj On Mar 20, 1:24 pm, Jason Sankey ja...@zutubi.com wrote: 3) Test-is reports results for all (is ...) expressions separately, but there is no good way to name them separately. At the moment I am reporting on each (is ...) as a separate test case by using the test name plus line number, but this is clunky. I think combining the results so one deftest == one JUnit report test case would be more sensible. If there are any troubles with test-is, you can consult Stuart Sierra (the author of test-is). Greetings, Frantisek --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Behavior of clojure.set/union and hinting function arguments
Hello Rich everybody! clojure.set/union currently accepts 'nil' as a valid argument: (union nil) = nil (union nil nil) = nil (union nil #{1 2}) = #{1 2} (union #{1 2} nil) = #{1 2} (union #{} nil) = #{} (union nil #{}) = nil ; not consistent Possible solution would be to ban 'nil' as an argument. While playing with type hinting, I discovered things that I don't understand: (defn f [#^Double x] (+ x 2)) = #'user/f (f 3) = 5 (f nil) = java.lang.NullPointerException (NO_SOURCE_FILE:0) ; why NPE? (f 2/3) = 8/3 ; why not an error that argument isn't java.lang.Double? (f a) = java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) ; wants java.lang.Number, but I was hinting for java.lang.Double Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: test-is: new feature suggestion
On Mar 19, 11:08 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Frantisek! I can see where this is useful, and the only reason I haven't implemented something like it for a test-is already is that I don't expect it would be very commonly used outside of the very specific case of testing the language itself. Where else, other than a language specification or a math library, are you going to be testing every combination of arguments? Secondly, remember that tests are just functions, with a little extra metadata. I thought about allowing them to accept arguments, but then I didn't know how to call them in run-tests. But you can define ordinary functions and use them in your tests. It turns out to be pretty easy to define all-all are this way: (defn all-are [pred args] (doseq [[x y] (combinations args 2)] (is (pred x y (deftest equality (all-are = 0 0.0 0M 0/1) (all-are #(and (= %1 %2) (not= (class %1) (class %2))) (sorted-map :a 1) (array-map :a 1) (hash-map :a 1))) Very nice! This will improve readability and ease the writing of the tests! I will remember to create a new function if needed. The only disadvantage to this is that you won't get some of the nice error reporting features, like individual line numbers, that you get when you use is by itself. But you would have the same problem if all-all are were a macro. I like to see the line numbers, but it isn't anything necessary. Usually, figuring out what went wrong, is much harder. So I guess, overall, I'm saying you shouldn't feel limited to using just the basic constructs that the library provides. They're just building blocks for your own, larger abstractions. If there's a particular abstraction that shows up repeatedly in lots of different contexts, then I'll want to add it to the library. I agree with keeping the core small. As for the fate of are, I've always been a little uncertain about it because it relies heavily on the templates library. And I've always been uncertain about templates because they rely heavily on code walking and code transformation. For example, in early versions of the lazy branch, are didn't work, and I never could figure out why. Fundamentally, I think anonymous functions are a more robust abstraction than templates, and my future work will probably rely more on functions than templates. Still, several people have said they like are, so I wouldn't drop it lightly. I don't like too many library dependencies and it is something to watch for. I haven't given any deep thoughts about how to improve 'are', but its utility is great. Since 'all-are' depends on 'combinations', we just gonna have to keep this organism healthy from the bottom to the top :-) Thanks for the help, Frantisek --~--~-~--~~~---~--~~ 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 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: Possible Bug In clojure.zip/remove
On Mar 19, 11:37 pm, Jason Sankey ja...@zutubi.com wrote: I pretty much have it working for the test-clojure suite now, although I'm sure the code could use review by a more experienced eye. I've been looking at adding the other two top-level suites (test-contrib and datalog) too, but their test clojure scripts are structured slightly differently such that requiring them leads them to run their tests immediately. It would be nice if some convention could be established for a top-level suite to be defined/exposed, and in such a way that I could wrap them with my script which defines special reporting methods to spit out XML. Nice! I took the liberty and changed the test-contrib and the datalog top- level tests to match test-clojure. Let me know if that helps or if something is broken :) Frantisek --~--~-~--~~~---~--~~ 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 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: Possible Bug In clojure.zip/remove
On Mar 19, 12:58 pm, Jason Sankey ja...@zutubi.com wrote: Also, is there somewhere I can contribute test cases for this to prevent a future regression? In order to contribute, you must fill-in and send The Contributor Agreement (CA) to Rich Hickey: http://clojure.org/contributing Tests for clojure.core are currently in clojure-contrib in test- clojure: http://code.google.com/p/clojure-contrib/source/browse/#svn/trunk/src/clojure/contrib/test_clojure There is no place yet where to put clojure.xml tests, but it shouldn't be hard to create something for it. After Rich receives your CA, you can create an issue and post a patch for it: http://code.google.com/p/clojure-contrib/issues/list An example issue: http://code.google.com/p/clojure-contrib/issues/detail?id=15 Your help with testing Clojure is very welcome! Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: Improving the test suite
Test-clojure is updated and ready for new tests :-) Frantisek On Mar 17, 5:03 am, Phil Hagelberg p...@hagelb.org wrote: OK, so I've posted a fair amount of smack talk about test suites and how important they are--I figure it's time to help out. What are some ways in which test-clojure is lacking? How can I help improve the coverage? -Phil --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
test-is: new feature suggestion
Hello Stuart all! As discussed in this thread: test-is: generating and processing testing data http://groups.google.com/group/clojure/browse_frm/thread/3e84efefd7c0bebc/3652a4a9a124cc6b , sometimes it is necessary to test each value against each value. Example is zeros-are-equal (as you suggested): (deftest zeros-are-equal (doall (map (fn [[a b]] (is (= a b))) (combinations [0 0.0 0M] 2 Truth is that these combinations are more common than I thought. For example, when testing equality of maps (test-equality in data_structures.clj in test_clojure), values of maps equal, but their classes are not. (= (sorted-map :a 1) (hash-map :a 1) (array-map :a 1)) = true (class (sorted-map :a 1)) = clojure.lang.PersistentTreeMap (class (hash-map :a 1)) = clojure.lang.PersistentHashMap (class (array-map :a 1)) = clojure.lang.PersistentArrayMap To test for this property, we can either write down all combinations (as I did) or write deftest function for each case (equality and non-equality). Each of these seem too verbose to me. I see 2 different solutions: 1) Allow deftest (new version of it?) to accept parameters: (deftest each-equals-each [parameter] (doall (map (fn [[a b]] (is (= a b))) (combinations parameter 2 This way we could call it: (each-equals-each [0 0.0 0M]) and (each-equals-each [(sorted-map :a 1) (hash-map :a 1) (array-map :a 1)]) 2) Create new version of 'are' - 'are-combinations' or more preferably 'are-all', which uses 'combinations' in itself: (are-all (= _1 _2) 0 0.0 0M) = (is (= 0 0.0)) (is (= 0 0M)) (is (= 0.0 0M)) This way we can easily do: (are-all (= _1 _2) (sorted-map :a 1) (hash-map :a 1) (array-map :a 1) ) and (are-all (not= _1 _2) (class (sorted-map :a 1)) (class (hash-map :a 1)) (class (array-map :a 1)) ) or combined? ;-) (are-all (and (= _1 _2) (not= (class _1) (class _2))) (sorted-map :a 1) (hash-map :a 1) (array-map :a 1) ) Personally, I prefer the second solution. It looks really elegant. The first solution - tests with parameters - is useful too and we could use it under different conditions. Thank you, Frantisek PS: What is the status of 'are' macro? Documentation still says Experimental. May be removed in the future.. Do you have any plans for it? I really like it and use it heavily in test-clojure. --~--~-~--~~~---~--~~ 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 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: Improving the test suite
Hello Phil, I see that you have your CA in already: http://clojure.org/contributing so you can start with creating issues and posting patches for them: http://code.google.com/p/clojure-contrib/issues/list Then somebody from clojure-contrib members looks at it and eventually checks it in. (Stephen C. Gilardi is very good at this - thanks!!!). Rich Hickey also might eventually give you a commit rights. Example issue: http://code.google.com/p/clojure-contrib/issues/detail?id=22 Tests are divided into similar groups as clojure.org website. I have been working on sequences http://clojure.org/sequences and data structures http://clojure.org/data_structures If at all possible, we should test the core and the most used functions first. Also, if there are any changes in Clojure being made (e.g. lazy sequences), there should be tests for it. If Rich Hickey decides to do changes in numbers, it would be great to test numbers. I have some tests ready for +, -, *, /, but they are not complete (see attachment to this message). Tests for numbers should contain different data types (byte, short, long, ...) and also test for boundaries (MAX_VALUE, MIN_VALUE), which generates many more assertions than I currently have. My suggestions are: - numbers - finish reader and evaluation - flow control - do, loop/recur, while, cond, condp, ... [overlaps with logic and special forms category] - higher order functions (hof) - apply, map, filter, remove, comp, partial, ... - vars, refs, agents, atoms - whatever you like to use and test :-) Your help is very welcome!! Frantisek On Tue, Mar 17, 2009 at 5:03 AM, Phil Hagelberg p...@hagelb.org wrote: OK, so I've posted a fair amount of smack talk about test suites and how important they are--I figure it's time to help out. What are some ways in which test-clojure is lacking? How can I help improve the coverage? -Phil --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~--- test-numbers.clj Description: Binary data
Re: Behavior of 'empty'
And what about lazy sequences? Is this behavior correct? user= (lazy-seq ()) () user= (empty (lazy-seq ())) nil user= (empty (lazy-seq [])) nil user= (lazy-seq [1 2]) (1 2) user= (empty (lazy-seq [1 2])) nil Thank you, Frantisek On 17 Bře, 13:54, Rich Hickey richhic...@gmail.com wrote: On Mar 16, 7:13 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Mon, Mar 16, 2009 at 3:54 PM, Frantisek Sodomka fsodo...@gmail.com wrote: (empty (seq [1 2])) = nil Now that there is the concept of empty sequences, maybe this should actually return an empty sequence, such as (). Yes. I've made (empty aseq) - (), (empty non-IPersistentCollection) - nil, svn 1331. Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -~--~~~~--~~--~--~---
Reading decimal numbers (doubles)
Hello Rich all! I have question about the reader http://clojure.org/reader Numbers say as per Java. I found that e.g. 2. reads Java as double and Clojure as int. All these read as double in Java: 2. .1 +.0 -.0 +2. -2. Clojure either sees them as ints or errors out. I am wondering about consistency between Java vs. Clojure reader. Do we want to copy all Java behavior exactly? Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Behavior of 'empty'
Hello Rich all! I am digging into behavior of function 'empty': user= (doc empty) - clojure.core/empty ([coll]) Returns an empty collection of the same category as coll, or nil (empty [1 2]) = [] (empty (seq [1 2])) = nil (empty '(1 2)) = () (empty (seq '(1 2))) = () ; ok because of: (seq '(1 2)) = (1 2) (class (seq '(1 2))) = clojure.lang.PersistentList (class '(1 2)) = clojure.lang.PersistentList One trouble is with nil: (empty nil) = java.lang.NullPointerException (NO_SOURCE_FILE:0) Would it make sense to return nil? (empty nil) = nil Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: New mod code is broken
Latest SVN r1327 works ok: user= (mod 9 -3) 0 user= (map #(mod % 3) (range -10 10)) (2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0) Test-clojure runs ok too. Frantisek On Mar 12, 10:30 am, bOR_ boris.sch...@gmail.com wrote: Mod seems to have broken again (mod 9 -3) gives -3 (map #(mod % 3) (range -10 10)) (2 3 1 2 3 1 2 3 1 2 0 1 2 0 1 2 0 1 2 0) svn 1372. Chouser wrote: On Sat, Feb 14, 2009 at 12:45 AM, Stephen C. Gilardi squee...@mac.com wrote: The new mod isn't working properly though: Testing clojure.contrib.test-clojure.numbers FAIL in (test-mod) (numbers.clj:104) expected: (= (mod 9 -3) 0) actual: (not (= -3 0)) FAIL in (test-mod) (numbers.clj:104) expected: (= (mod -9 3) 0) actual: (not (= 3 0)) So true: http://groups.google.com/group/clojure/browse_thread/thread/2a0ee4d24... It will need a fix. Indeed it will. Fortunately it already has one: http://code.google.com/p/clojure/issues/detail?id=23#c6 --Chouser --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
test-clojure: trouble with the latest Clojure SVN version
There is a problem with the latest Clojure SVN version. Try running in clojure-contrib: ant test_clojure It generates failures and errors. There is some confusion between nil and () by the reader/compiler it seems. Also: user= (pop '(1 2 3)) java.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.IPersistentStack user= (peek '(1 2 3)) java.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.IPersistentStack Many tests pass in REPL, but fail when loaded from file it seems. Thanks for your attention, Frantisek --~--~-~--~~~---~--~~ 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 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: test-clojure: eval failure
Hmm, interesting error. After the merge of the lazy branch was everything ok, so it has to be a recent change. user= (eval (list + 1 2 3)) java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0) user= (eval '(+ 1 2 3)) 6 user= (list + 1 2 3) (#core$_PLUS___243 clojure.core$_plus___...@153f141 1 2 3) user= '(+ 1 2 3) (+ 1 2 3) Frantisek On 2 Bře, 17:08, Stephen C. Gilardi squee...@mac.com wrote: A test like this in clojure.contrib.test-clojure.evaluation is currently failing: user= (eval (list + 1 2 3)) java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0) --Steve smime.p7s 3KZobrazitStáhnout --~--~-~--~~~---~--~~ 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 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: bug? ClassNotFoundException from macro
I get different error (running from REPL): (test2 (+ 1 1)) = java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0) (test2 10) = java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0) I think that it has to do with 'test1' in your macro. Function 'test1' gets compiled into a Java class and it seems that compiler cannot find it or use it properly. Try to quote it (since map {} evaluates its elements}: (defmacro test2 [form] (list 'list form {:a 'test1})) (macroexpand-1 '(test2 (+ 1 1))) = (list (+ 1 1) {:a test1}) (test2 (+ 1 1)) = (2 {:a #user$test1__1 user$test1...@12611a7}) I am not sure if this is a bug or not... On Feb 24, 11:35 pm, MikeM michael.messini...@invista.com wrote: Under SVN 1303, I'm getting a ClassNotFoundException from a macro. Here's a simplified example of the problem: (defn test1 [x] (+ x 1)) (defmacro test2 [form] (list 'list form {:a test1})) (test2 (+ 1 1)) = java.lang.ClassNotFoundException: user$test1__3765 Is this a bug? --~--~-~--~~~---~--~~ 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 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: 6 + 7 = 13
I see only 6 + 36 = 42 Frantisek On Feb 24, 11:25 am, Marko marko.van.doo...@gmail.com wrote: Hi, just reporting an error on the following page:http://clojure.org/dynamic 6 + 7 should really be 13, and not 42. --~--~-~--~~~---~--~~ 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 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: Changed clojure.contrib.test-clojure to load without running, add run method
I wonder about testing clojure.contrib in general. Some libraries like math, miglayout, monads, sql and test-is define their own tests tests.clj in their subdirectory. Others - shell_out and str_utils - have their tests in test_contrib. Should we merge these two approaches into one? Frantisek On Feb 23, 12:12 am, Stephen C. Gilardi squee...@mac.com wrote: On Feb 22, 2009, at 5:41 PM, Frantisek Sodomka wrote: There was a functionality in build.xml to run tests from the command line. When you correctly set clojure.jar path, you could just do: ant test_clojure Fixed. Thanks for the report. Regarding test_contrib, I would like to update it along the lines of the recent changes to test_clojure because I think they make things cleaner, more composable, and more modular. Discussion welcome. Thanks, --Steve smime.p7s 3KViewDownload --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Issue 52 looks solved
Hello! Just a quick note: Issue 52: Make set/union accept any number of arguments http://code.google.com/p/clojure/issues/detail?id=52 seems to be solved already by: SVN 1276 http://code.google.com/p/clojure/source/detail?r=1276 added multi-arg clojure.set/union/difference/intersection, patch from jawolfe Frantisek --~--~-~--~~~---~--~~ 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 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: nth with regex Matchers
Thanks Chouser!! I needed it just to test the 'nth'. I had to ask, just couldn't figure it out :-) Yes, I prefer re-seq - especially with such nice tools like http://cljre.com/ from Mark McGranaghan http://groups.google.com/group/clojure/browse_frm/thread/bbc9fd453667d953/a79a738cbe7f41e9 Frantisek On 22 Ún, 02:37, Chouser chou...@gmail.com wrote: On Sat, Feb 21, 2009 at 1:34 PM, Frantisek Sodomka fsodo...@gmail.com wrote: nth claims to also work on regex Matchers: user= (doc nth) - clojure.core/nth ([coll index] [coll index not-found]) Returns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-found is supplied. nth also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences. Please, could somebody show me an example of that? I tried things along the lines of: user= (re-seq #a ababaa) (a a a a) user= (re-matcher #a ababaa) #Matcher java.util.regex.Matcher[pattern=a region=0,6 lastmatch=] user= (nth (re-matcher #a ababaa) 0) java.lang.IllegalStateException: No match found (NO_SOURCE_FILE:0) user= (seq (re-matcher #a ababaa)) java.lang.IllegalArgumentException: Don't know how to create ISeq from: Matcher (NO_SOURCE_FILE:0) ... but no success so far. Valiant attempts, all. But Matcher is a mutable Java object -- you're trying to use nth on it before it's been fully initialized. Calling it's find method (or using the single-arg form of re-find) will cause it to refer to the first match in the string, at which point nth can be used to pick out the group you want: user= (def m (re-matcher #(a)(b) ababaa)) #'user/m user= (re-find m) [ab a b] user= (class m) java.util.regex.Matcher user= (nth m 1) a I would recommend avoiding using re-matcher or the single-arg re-find unless you're sure you need the performance or flexibility in some particular kind of loop. It's much more pleasant to work with re-seq. --Chouser --~--~-~--~~~---~--~~ 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 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: Should (pop nil) throw an exception?
Any thoughts on this one? Impatient Frantisek :-) On 21 Ún, 22:28, Frantisek Sodomka fsodo...@gmail.com wrote: Hello! Currently, 'pop' throws an exception if the collection is empty: clojure.core/pop ([coll]) For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same as next/butlast. user= (pop ()) java.lang.IllegalStateException: Can't pop empty list (NO_SOURCE_FILE: 0) user= (pop []) java.lang.IllegalStateException: Can't pop empty vector (NO_SOURCE_FILE:0) Should (pop nil) also throw an exception or is returning 'nil' ok?? user= (pop nil) nil Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: Directed Graphs for Contrib
Graphs has always inspired me and seeing implementation in Clojure will be no less inspiring. http://www.visualcomplexity.com/vc/ http://planarity.net/ Frantisek On 22 Ún, 16:11, Jeffrey Straszheim straszheimjeff...@gmail.com wrote: Just as a point of fact, I don't plan to make a complete *every algorithm you can think of* package, just the ones I need. However, it would be easy to add others submitted by the community. I could be a gathering place of graph algorithms. On Sun, Feb 22, 2009 at 7:31 AM, Francesco Bellomi francesco.bell...@gmail.com wrote: +1 Francesco On Feb 22, 2:59 am, Jeffrey Straszheim straszheimjeff...@gmail.com wrote: As part of my Datalog work I'm putting together some directed graph algorithms, mostly things like finding strongly connected components, and building dependency stratifications (think topological sort but with the results groups in tiers of non-interdependent nodes). Anyhow, I'm thinking this stuff will be usefull outside of Datalog, and am wondering if I should just add it to contrib as a stand-alone library? --~--~-~--~~~---~--~~ 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 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: where is contrib?
For example, lazy-cons is still present in: combinatorics.clj lazy_xml/with_pull.clj monads/examples.clj Frantisek On 21 Ún, 15:54, James Reeves weavejes...@googlemail.com wrote: On Feb 21, 2:36 pm, bOR_ boris.sch...@gmail.com wrote: Note that clojure just changed the lazy branch to be the main version of clojure, so right now clojure-contrib and the latest svn do not play nicely yet. I belief there is a old version of clojure-contrib available and probably also for clojure-main. All the clojure.contrib libraries I've used recently play nicely with the new lazy seqs. What libraries are left to convert? - James --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
nth with regex Matchers
nth claims to also work on regex Matchers: user= (doc nth) - clojure.core/nth ([coll index] [coll index not-found]) Returns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-found is supplied. nth also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences. Please, could somebody show me an example of that? I tried things along the lines of: user= (re-seq #a ababaa) (a a a a) user= (re-matcher #a ababaa) #Matcher java.util.regex.Matcher[pattern=a region=0,6 lastmatch=] user= (nth (re-matcher #a ababaa) 0) java.lang.IllegalStateException: No match found (NO_SOURCE_FILE:0) user= (seq (re-matcher #a ababaa)) java.lang.IllegalArgumentException: Don't know how to create ISeq from: Matcher (NO_SOURCE_FILE:0) ... but no success so far. Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Should (pop nil) throw an exception?
Hello! Currently, 'pop' throws an exception if the collection is empty: clojure.core/pop ([coll]) For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same as next/butlast. user= (pop ()) java.lang.IllegalStateException: Can't pop empty list (NO_SOURCE_FILE: 0) user= (pop []) java.lang.IllegalStateException: Can't pop empty vector (NO_SOURCE_FILE:0) Should (pop nil) also throw an exception or is returning 'nil' ok?? user= (pop nil) nil Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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 class hierarchy
You can read: http://clojure.org/data_structures http://clojure.org/sequences and: http://en.wikibooks.org/wiki/Clojure_Programming Frantisek On 21 Ún, 22:24, linh nguyenlinh.m...@gmail.com wrote: where can i find information about clojure's data-structure class hierarchy? i would like to know how seq, map, list, vector and set are related. i'm new to clojure and i don't always understand the api doc. a class hierarchy would make it easier for me to understand what functions can be appied to what data-structures. 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 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 -~--~~~~--~~--~--~---
Possible bug in sorted-set, question about comparisons
sorted-set works for vectors, but doesn't work for lists, maps and sets: user= (sorted-set [1 4]) #{[1 4]} user= (sorted-set [1 4] [1 4]) #{[1 4]} user= (sorted-set [4 1] [1 4]) #{[1 4] [4 1]} user= (sorted-set '(1 4)) #{(1 4)} user= (sorted-set '(1 4) '(1 4)) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) user= (sorted-set {:a 1 :b 2}) #{{:a 1, :b 2}} user= (sorted-set {:a 1 :b 2} {:a 1 :b 2}) java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) user= (sorted-set #{1 2}) #{#{1 2}} user= (sorted-set #{1 2} #{1 2}) java.lang.ClassCastException: clojure.lang.PersistentHashSet cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) --- How does sorted-set know which value is bigger or smaller? Could this functionality be exported? user= (sorted-set [4 3] [2 1]) #{[2 1] [4 3]} user= ( [4 3] [2 1]) java.lang.ClassCastException: clojure.lang.LazilyPersistentVector cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) user= (= [4 3] [2 1]) false user= ( xyz abc) java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: Possible bug in sorted-set, question about comparisons
It looks that it is more complicated than that: user= (sorted-set () ()) #{()} user= (sorted-set {} {}) #{{}} user= (sorted-set #{} #{}) #{#{}} Frantisek On 20 Ún, 20:33, Vincent Foley vfo...@gmail.com wrote: I'm pretty sure that sorted-set works only with values that are instances of a class that implements Comparable. user= (instance? Comparable []) true user= (instance? Comparable {}) false user= (instance? Comparable ()) false user= On Feb 20, 2:21 pm, Frantisek Sodomka fsodo...@gmail.com wrote: sorted-set works for vectors, but doesn't work for lists, maps and sets: user= (sorted-set [1 4]) #{[1 4]} user= (sorted-set [1 4] [1 4]) #{[1 4]} user= (sorted-set [4 1] [1 4]) #{[1 4] [4 1]} user= (sorted-set '(1 4)) #{(1 4)} user= (sorted-set '(1 4) '(1 4)) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) user= (sorted-set {:a 1 :b 2}) #{{:a 1, :b 2}} user= (sorted-set {:a 1 :b 2} {:a 1 :b 2}) java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) user= (sorted-set #{1 2}) #{#{1 2}} user= (sorted-set #{1 2} #{1 2}) java.lang.ClassCastException: clojure.lang.PersistentHashSet cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) --- How does sorted-set know which value is bigger or smaller? Could this functionality be exported? user= (sorted-set [4 3] [2 1]) #{[2 1] [4 3]} user= ( [4 3] [2 1]) java.lang.ClassCastException: clojure.lang.LazilyPersistentVector cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) user= (= [4 3] [2 1]) false user= ( xyz abc) java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: Possible bug in sorted-set, question about comparisons
Thanks for explanation, all! Frantisek On 20 Ún, 20:57, Jason Wolfe jawo...@berkeley.edu wrote: It probably does an identical? call on a pair before calling compare, for efficiency. In other words, it may work on non- comparable types, but only when passed n instances of the exact same object: user (sorted-set '(1) '(1)) ; Exception user (let [x '(1)] (sorted-set x x)) #{(1)} This is almost certainly not documented behavior and should not be relied upon. Cheers, Jason On Feb 20, 11:42 am, Frantisek Sodomka fsodo...@gmail.com wrote: It looks that it is more complicated than that: user= (sorted-set () ()) #{()} user= (sorted-set {} {}) #{{}} user= (sorted-set #{} #{}) #{#{}} Frantisek On 20 Ún, 20:33, Vincent Foley vfo...@gmail.com wrote: I'm pretty sure that sorted-set works only with values that are instances of a class that implements Comparable. user= (instance? Comparable []) true user= (instance? Comparable {}) false user= (instance? Comparable ()) false user= On Feb 20, 2:21 pm, Frantisek Sodomka fsodo...@gmail.com wrote: sorted-set works for vectors, but doesn't work for lists, maps and sets: user= (sorted-set [1 4]) #{[1 4]} user= (sorted-set [1 4] [1 4]) #{[1 4]} user= (sorted-set [4 1] [1 4]) #{[1 4] [4 1]} user= (sorted-set '(1 4)) #{(1 4)} user= (sorted-set '(1 4) '(1 4)) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) user= (sorted-set {:a 1 :b 2}) #{{:a 1, :b 2}} user= (sorted-set {:a 1 :b 2} {:a 1 :b 2}) java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) user= (sorted-set #{1 2}) #{#{1 2}} user= (sorted-set #{1 2} #{1 2}) java.lang.ClassCastException: clojure.lang.PersistentHashSet cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) --- How does sorted-set know which value is bigger or smaller? Could this functionality be exported? user= (sorted-set [4 3] [2 1]) #{[2 1] [4 3]} user= ( [4 3] [2 1]) java.lang.ClassCastException: clojure.lang.LazilyPersistentVector cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) user= (= [4 3] [2 1]) false user= ( xyz abc) java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: Fully lazy sequences are here!
There is something that confuses me: user= (cycle []) () user= (= (cycle []) ()) true user= (= (cycle []) nil) true user= (= () nil) false Thanks for answering, Frantisek On Feb 18, 3:54 am, Rich Hickey richhic...@gmail.com wrote: On Feb 17, 4:16 pm, Frantisek Sodomka fsodo...@gmail.com wrote: That was fast! ;-) Rich, I am porting test_clojure and old 'cycle' worked as: (cycle []) = nil Currently: (cycle []) = java.lang.StackOverflowError Fixed in svn 1290 - thanks for the report. Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: Fully lazy sequences are here!
I believe it's already done. Frantisek On Feb 18, 12:39 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: Now that next is recommended over rest, should nthrest be renamed to nthnext? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Fully lazy sequences are here!
What about 'conj'? Documentation says: (conj nil item) returns (item). Currently: user= (conj nil 1) (1) user= (conj () 1) (1) Idiom conj nil is used in 'reverse': (reduce conj nil coll) Currently: user= (reverse [1 2]) (2 1) user= (reverse [1]) (1) user= (reverse []) nil It looks that now all sequence functions return () instead of nil. Is 'reverse' correct? Thank you, Frantisek On Feb 17, 8:43 pm, Rich Hickey richhic...@gmail.com wrote: I've merged the lazy branch into trunk, SVN rev 1287 Please do not rush to this version unless you are a library/tool developer. Let them do their ports and chime in on their progress. Move only when the libs/tools you depend upon have been ported. Thanks to all for your feedback and input! Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: Fully lazy sequences are here!
Or maybe more general question: Is there any function in Clojure which when returning empty sequence, returns nil instead of () ??? user= (butlast [1 2 3]) (1 2) user= (butlast [1]) nil user= (butlast []) nil Thanks, Frantisek On Feb 18, 5:46 pm, Frantisek Sodomka fsodo...@gmail.com wrote: What about 'conj'? Documentation says: (conj nil item) returns (item). Currently: user= (conj nil 1) (1) user= (conj () 1) (1) Idiom conj nil is used in 'reverse': (reduce conj nil coll) Currently: user= (reverse [1 2]) (2 1) user= (reverse [1]) (1) user= (reverse []) nil It looks that now all sequence functions return () instead of nil. Is 'reverse' correct? Thank you, Frantisek On Feb 17, 8:43 pm, Rich Hickey richhic...@gmail.com wrote: I've merged the lazy branch into trunk, SVN rev 1287 Please do not rush to this version unless you are a library/tool developer. Let them do their ports and chime in on their progress. Move only when the libs/tools you depend upon have been ported. Thanks to all for your feedback and input! Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: bug affecting clojure.core/bean?
Or maybe: next ??? :- Frantisek On Feb 18, 5:27 pm, Rich Hickey richhic...@gmail.com wrote: On Feb 18, 11:04 am, Chouser chou...@gmail.com wrote: On Wed, Feb 18, 2009 at 12:35 AM, Rob rob.nikan...@gmail.com wrote: I'm wondering if I found a bug. I have the latest source from svn (r1291). user= (bean 1) java.lang.IllegalArgumentException: Wrong number of args passed to: core$bean--5161$fn--5179$thisfn You sure did. The conversion to lazy-seq code appears to introduce a paren typo and an incorrect nil pun. Patch attached. Patch applied, svn 1293 - thanks! Rich, I think it'd be pretty useful to have as you mentioned in IRC a variant of destructuring that provided an unforced lazy-seq. It seems pretty common to want, in the body of a lazy-seq, a destructured 'first' but an unforced 'rest'. This is already the third or fourth time I've wanted to be able to do something like: (fn thisfn [plseq] (lazy-seq (when-let [[pkey rest etc] plseq] (cons (new clojure.lang.MapEntry pkey (v pkey)) (thisfn etc) Yes, sure. It just comes down to the name: rest others? Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: Fully lazy sequences are here!
How should I say it... It just didn't look symmetrical to me. So, basically, there is a difference between functions returning sequences - depending on if they are lazy or eager. Hmm... user= (reverse []) nil user= (if (reverse []) true false) false user= (if (seq (reverse [])) true false) false user= (lazy-seq nil) () user= (seq (lazy-seq nil)) nil user= (if (lazy-seq nil) true false) true user= (if (seq (lazy-seq nil)) true false) false As long as I remember which function is lazy and which one is eager, I should be fine then. Just wanted to really understand it. Thanks, Frantisek On Feb 18, 5:58 pm, Chouser chou...@gmail.com wrote: On Wed, Feb 18, 2009 at 11:46 AM, Frantisek Sodomka fsodo...@gmail.com wrote: What about 'conj'? Documentation says: (conj nil item) returns (item). Currently: user= (conj nil 1) (1) user= (conj () 1) (1) Is there something wrong with that? It looks right and like it matches the docs to me. Idiom conj nil is used in 'reverse': (reduce conj nil coll) Currently: user= (reverse [1 2]) (2 1) user= (reverse [1]) (1) user= (reverse []) nil It looks that now all sequence functions return () instead of nil. Is 'reverse' correct? Things that return lazy seqs now return an empty lazy seq, which prints as (), instead of nil. However, 'reverse' is not lazy and normally returns a PersistentList. I don't know that it'd be more correct to return an empty PersistentList than to return nil as it does now. --Chouser --~--~-~--~~~---~--~~ 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 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: Fully lazy sequences are here!
At this point test-clojure doesn't generate any new failures or errors (except the old 'mod' function failures). Coverage is still relatively small, but (cycle []) bug and case of (reverse []) were caught with its help when rewriting tests :-) Thanks for all the fixes! Frantisek On Feb 18, 8:02 pm, Rich Hickey richhic...@gmail.com wrote: On Feb 18, 12:20 pm, Frantisek Sodomka fsodo...@gmail.com wrote: How should I say it... It just didn't look symmetrical to me. So, basically, there is a difference between functions returning sequences - depending on if they are lazy or eager. Hmm... user= (reverse []) nil user= (if (reverse []) true false) false user= (if (seq (reverse [])) true false) false user= (lazy-seq nil) () user= (seq (lazy-seq nil)) nil user= (if (lazy-seq nil) true false) true user= (if (seq (lazy-seq nil)) true false) false As long as I remember which function is lazy and which one is eager, I should be fine then. Just wanted to really understand it. It shouldn't be that subtle. Sequence functions shouldn't return nil unless they are variants of seq/next. I've fixed reverse and sort to return () when passed empty colls - SVN 1294. Rich. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: Fully lazy sequences are here!
That was fast! ;-) Rich, I am porting test_clojure and old 'cycle' worked as: (cycle []) = nil Currently: (cycle []) = java.lang.StackOverflowError Frantisek On Feb 17, 8:43 pm, Rich Hickey richhic...@gmail.com wrote: I've merged the lazy branch into trunk, SVN rev 1287 Please do not rush to this version unless you are a library/tool developer. Let them do their ports and chime in on their progress. Move only when the libs/tools you depend upon have been ported. Thanks to all for your feedback and input! Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -~--~~~~--~~--~--~---
'nil 'false 'true - symbols or Clojure keywords?
Usual symbol: 'abc = abc (symbol? 'abc) = true (symbol abc) = abc (symbol? (symbol abc)) = true Special symbol: 'nil = nil (symbol? 'nil) = false (symbol nil) = nil (symbol? (symbol nil)) = true (= 'nil (symbol nil)) = false (= 'nil nil) = true We can see that (symbol nil) truly evaluates to symbol nil. On the other side, reader evalutes 'nil to nil (nothing). (The same holds true for 'false and 'true.) Is this consistent and correct behavior? If it is correct, page http://clojure.org/Reader could tell more about 'nil, 'false and 'true. Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: Bugs in set and sorted-set (?)
It is making more sense now. One other interesting thing that surprised me is: There is not a total ordering across types. See discussion: http://groups.google.com/group/clojure/browse_frm/thread/710848919c68981f/51ede18b2fd7ab96?lnk=gstq=sorted-set#51ede18b2fd7ab96 Therefore things like (sort [nil true 42 abc]) will throw an exception. This is understandable since there can be many types in Clojure and we cannot really easily define their ordering. Many thanks for explanation, Frantisek On Feb 15, 3:22 pm, Rich Hickey richhic...@gmail.com wrote: On Feb 14, 11:10 pm, Chouser chou...@gmail.com wrote: On Sat, Feb 14, 2009 at 7:19 PM, Stephen C. Gilardi squee...@mac.com wrote: set is a hash set. It will never contain two items with equal hashes. I don't think that's quite right. I don't think it matters in this case, but hash values aren't guaranteed unique. A hash-map can have two keys with the same hash value as long as = returns false. Vectors and lists with the same values evaluate as equal: user= (= '(1 2) [1 2]) true Right, and therein lies the key to understanding the set behavior. A set will contain at most one of any set of equal values. Equal objects should have equivalent, but not necessarily unique, hash codes. When you have polymorphic collections, as does Clojure, you need to decide the type bounds of the equality test. If two collections needed to be precisely the same type in order to be equal, the system would be quite rigid, with lots of explicit copying and coercion. Essentially, the polymorphism would be worthless. It ends up being most flexible and useful to place the type bound as high up as possible in the hierarchy, but not so high as to blur the core distinctions between collection families. Clojure divides the collections up into families for equality purposes - sequential, maps and sets. I can't overstate how important collection polymorphism is to the design of Clojure. One tradeoff is that sometimes you'd like explicit type to be part of collection equality, but it would still beg the question as to where to place the bounds, if other than exact match. For instance: (count #{(hash-set 1) (sorted-set 1)}) === ??? they are both sets but not the same exact type. Note that things are no different in Java, which also has polymorphic collections: (java.util.HashSet. [(java.util.ArrayList. [1 2]) (java.util.LinkedList. [1 2])]) - #HashSet [[1, 2]] (class (first *1)) - java.util.ArrayList Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -~--~~~~--~~--~--~---
Trojan horse in our Files section
My antivirus doesn't like the Gift from the Stranger: http://groups.google.com/group/clojure/files?sort=date Not really nice of you, Stranger... Frantisek --~--~-~--~~~---~--~~ 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 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: Bugs in set and sorted-set (?)
Similar is: user= #{[] ()} #{[]} user= #{[] [1 2]} #{[] [1 2]} user= (hash-set [] ()) #{[]} Frantisek On Feb 15, 12:38 am, Frantisek Sodomka fsodo...@gmail.com wrote: Hello! Function 'set' looses some of its data. It seems that there is a problem with comparison between lists and vectors: user= (count [nil false true 0 42 0.0 3.14 2/3 0M 1M \c abc 'sym :kw () '(1 2) [] [1 2] {} {:a 1 :b 2} #{} #{1 2}]) 23 user= (set [nil false true 0 42 0.0 3.14 2/3 0M 1M \c abc 'sym :kw () '(1 2) [] [1 2] {} {:a 1 :b 2} #{} #{1 2}]) #{nil 0 0.0 0M {} #{} 2/3 () abc {:a 1, :b 2} (1 2) #{1 2} \c 3.14 42 sym true :kw false 1M} user= (count (set [nil false true 0 42 0.0 3.14 2/3 0M 1M \c abc 'sym :kw () '(1 2) [] [1 2] {} {:a 1 :b 2} #{} #{1 2}])) 21 ; missing are [] and [1 2] user= (set [()]) #{()} user= (set [() []]) #{()} user= (set [() [] {}]) #{{} ()} user= (set [[] [1 2]]) #{[] [1 2]} user= (set [[] [1 2] 1]) #{[] 1 [1 2]} user= (set [[] [1 2] ()]) #{[] [1 2]} user= (set [() [] [1 2]]) #{() [1 2]} What data types is sorted-set supposed to work on? When used with different data types, it errors out:http://clojure.org/data_structures user= (doc sorted-set) - clojure.core/sorted-set ([ keys]) Returns a new sorted set with supplied keys. user= (sorted-set 4 2) #{2 4} user= (sorted-set () []) java.lang.ClassCastException: clojure.lang.PersistentList$EmptyList cannot be cast to clojure.lang.IPersistentVector (NO_SOURCE_FILE:0) user= (sorted-set nil false true 0 42 0.0 3.14 2/3 0M 1M \c abc 'sym :kw () '(1 2) [] [1 2] {} {:a 1 :b 2} #{} #{1 2}) java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) user= (sorted-set '(1 2) 1) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) user= (sorted-set '(1 2) abc) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.String (NO_SOURCE_FILE:0) user= (sorted-set abc #{1 2}) java.lang.ClassCastException: clojure.lang.PersistentHashSet cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) user= (sorted-set 42 #{1 2}) java.lang.ClassCastException: clojure.lang.PersistentHashSet cannot be cast to java.lang.Comparable (NO_SOURCE_FILE:0) It works when types are the same: user= (sorted-set z b) #{b z} user= (sorted-set 42 2.0) #{2.0 42} user= (sorted-set [2 3] [1]) #{[1] [2 3]} Frantisek --~--~-~--~~~---~--~~ 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 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: is mod correct?
Also, mod seems too strict about numbers it accepts (only integers!): user= (rem 1 2/3) 1/3 user= (mod 1 2/3) java.lang.IllegalArgumentException: mod requires two integers (NO_SOURCE_FILE:0) user= (rem 4.5 2.0) 0.5 user= (mod 4.5 2.0) java.lang.IllegalArgumentException: mod requires two integers (NO_SOURCE_FILE:0) Frantisek On Feb 10, 10:30 pm, Chouser chou...@gmail.com wrote: Is 'mod' working correctly? user= (map #(mod % 3) (range -9 9)) (3 1 2 3 1 2 3 1 2 0 1 2 0 1 2 0 1 2) It disagrees with, for example, Ruby: irb(main):002:0 (-9..9).map{|x| x % 3} = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0] And python: map( lambda x: x % 3, range(-9,9) ) [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] --Chouser --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
test-is: (is (thrown? ...)) exceptions REPL
Hello Stuart and all! There is something strange going on with (is (thrown? ...)) form: user= (use 'clojure.contrib.test-is) nil user= (is (= 2 2)) true ; this works user= (/ 1 0) java.lang.ArithmeticException: Divide by zero (NO_SOURCE_FILE:0) user= (is (thrown? ArithmeticException (/ 1 0))) #ArithmeticException java.lang.ArithmeticException: Divide by zero ; this doesn't work user= (if) java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:10) user= (is (thrown? Exception (if))) java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:13) user= (if true) java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:29) user= (is (thrown? Exception (if true))) java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:14) ; this works user= (- 2) -2 user= (-) java.lang.IllegalArgumentException: Wrong number of args passed to: core$- (NO_SOURCE_FILE:0) user= (is (thrown? IllegalArgumentException (-))) #IllegalArgumentException java.lang.IllegalArgumentException: Wrong number of args passed to: core$- Even though 'if' is a special form, shouldn't (is (thrown? Exception (if))) catch the Exception correctly? Also, notice that (if) throws different exception than (-) - would it make sense to unify these exceptions? Another example: user= (vals {:a 1 :b 2}) (1 2) user= (vals [1 2]) java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Map$Entry (user= (is (thrown? ClassCastException (vals [1 2]))) FAIL in (:20) expected: (thrown? ClassCastException (vals [1 2])) actual: nil nil We can see that exception doesn't get processed/caught correctly. Also see REPL - it prints redundant ( character after exception was thrown. Hitting ENTER fixes it: user= (vals [1 2]) java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Map$Entry (user= user= Thank you for looking at this, Frantisek --~--~-~--~~~---~--~~ 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 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: test-is: (is (thrown? ...)) exceptions REPL
user= (deftest test-if (is (thrown? Exception (if java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:35) user= (deftest test-div (is (thrown? ArithmeticException (/ 1 0 #'user/test-div Yes, looks like it. Compile-time and run-time exceptions - will have to remember that ;-) Frantisek PS: I still wonder why REPL has that ( char after exception. Bug? On 5 Ún, 15:28, Jeffrey Straszheim straszheimjeff...@gmail.com wrote: From a quick glance, it looks like the exceptions that are *not* being caught are those generated by the compiler, who can't understand the code. test-is can't find those because the code doesn't even run in that 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 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: SVN branches
Streams were also intended for I/O. Is lazier addition also able to cope with I/O sucessfully? Can we have both - streams and lazy-seq? My thought about streams is that if they get included, they could be looked at as unsafe operations in Java/C# or unchecked math operations - as long as programmer knows what he is doing, it is fine... Frantisek On 3 Ún, 15:31, Rich Hickey richhic...@gmail.com wrote: On Feb 2, 2:27 pm, Chouser chou...@gmail.com wrote: On Mon, Feb 2, 2009 at 2:05 PM, MikeM michael.messini...@invista.com wrote: There is a lazy branch in SVN. The streams branch has been discussed, but I haven't seen any discussion of the lazy branch - perhaps I missed it. Here's a discussion from earlier today, mainly about the lazy branch: http://clojure-log.n01se.net/date/2009-02-02.html#09:47 I've started documenting the lazy branch work here: http://clojure.org/lazier Feedback welcome, Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: test-is: generating and processing testing data
Thank you for explanation. I will use is for tests with messages. Otherwise, I am quite happy with are macro. It really helps with not repeating myself. I created 3 new issues and added 2 patches: http://code.google.com/p/clojure-contrib/issues/list Issue for sequences is to inform that I am working on it. Too sad, I cannot add file/patch to it later. (Sorry, I didn't know, just had to try.) If somebody wants to look at them and apply patches, I would be excited :-) Frantisek --~--~-~--~~~---~--~~ 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 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: Bug? overflow check in Numbers.minus
user= (- Integer/MAX_VALUE Integer/MIN_VALUE) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0) user= (- Long/MAX_VALUE Long/MIN_VALUE) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0) Is this behavior correct? Frantisek On Jan 10, 5:25 am, Chouser chou...@gmail.com wrote: On Thu, Jan 8, 2009 at 2:07 PM, Achim Passen achim.pas...@gmail.com wrote: Hi all! I encountered some corner cases where overflow checking for - doesn't work as I would expect: user= (- Integer/MAX_VALUE Integer/MIN_VALUE) -1 user= (- Long/MAX_VALUE Long/MIN_VALUE) -1 The problem seems to be that negating MIN_VALUE yields MIN_VALUE again, so it slips through the overflow check (see below). Shall I add that to the issues list? I think you should go ahead. I don't see how this could not be a bug. --Chouser --~--~-~--~~~---~--~~ 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 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: changes to test_clojure and test_contrib
Hello Steve, I attached file predicates.patch for type and number predicates. Let me know, if this is an acceptable patch (I haven't worked with them before). We can then create an issue for Clojure-contrib if necessary. Shawn, I keep wondering where is the best place to put tests for bug fixes. One way would be to create a separate file (bugs.clj) and put all these tests there. Another way is to include these tests into their respective categories - although I wonder for example test for (= () []) = true ... where should it go? Should it go equality.clj or to sequences.clj??? Any suggestions/opinions about where is the best place for bug fixes??? Thank you, Frantisek On Tue, Jan 27, 2009 at 2:05 AM, Stephen C. Gilardi squee...@mac.comwrote: On Jan 26, 2009, at 7:43 PM, Shawn Hoover wrote: I have a few tests in the works and am lacking commit access as well. Should test contributions follow the procedure of group discussion, then file an issue, then post a patch? If so, what would you like to know about the patch(es)? I consider the call for good unit tests covering areas of clojure or contrib that currently lack them to be permanently open. One of the purposes of discussing things on the mailing list first is to attract good ideas and thoughts from its denizens and avoid duplicating large-ish bits of effort. You may even occasionally find a collaborator that you can work with. That remains a good idea even in the case of unit tests. Of course that's all best done when you are beginning to think about some contribution rather than when it's nearly complete. Please do make a post here describing what you have. Then generate one or more issues (in groupings that make good common sense) against clojure-contrib describing which areas of clojure or contrib your contribution will test and attach the patches to them. Thanks, --Steve --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~--- predicates.patch Description: Binary data
New functions and possible bugs
Hello all! During writing tests for type predicates, I noticed that these - possibly useful - predicates are not in clojure.core: boolean? character? regex? array? Since this is correct: user= (= () []) true Shouldn't these be also 'true'? user= (= {} []) false user= (= {} #{}) false user= (= {} ()) false user= (= #{} []) false user= (= #{} ()) false Thank you, Frantisek --~--~-~--~~~---~--~~ 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 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: New functions and possible bugs
Talking about equality of: user= (= [1, 2] '(1, 2)) true I also wondered if there could be something as strict equal, which returns true only if both the operands are equal and of the same type. See JavaScript: http://www.devguru.com/Technologies/ecmascript/quickref/comparison_operators.html http://www.devguru.com/Technologies/ecmascript/quickref/javascript_index.html Frantisek On Jan 28, 9:17 pm, Cosmin Stejerean cstejer...@gmail.com wrote: On Wed, Jan 28, 2009 at 11:13 AM, Frantisek Sodomka fsodo...@gmail.comwrote: [...] Since this is correct: user= (= () []) true Shouldn't these be also 'true'? user= (= {} []) false user= (= {} #{}) false user= (= {} ()) false user= (= #{} []) false user= (= #{} ()) false Well, I'm not yet sure if I like it but lists and vectors that have identical elements in them appear to be equal, not just empty ones. user= (= [1, 2] '(1, 2)) true Since any list can be represented as an equivalent vector (and any vector as an equivalent list) I can imagine this making sense. user= (apply list [1 2 1]) (1 2 1) user= (apply vector '(1 2 1)) [1 2 1] But I don't see how this would ever apply to sets or maps so I don't see why empty sets and maps should be an exception. -- Cosmin Stejereanhttp://offbytwo.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 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 -~--~~~~--~~--~--~---
test-is: generating and processing testing data
Hello, I have suggestion about clojure.contrib.test-is. It is useful and sometimes necessary to generate testing data. Currently, data can be generated by a piece of code and passed to an 'is' function. For example, I want to test for equality of many things, to see if each is equal to each: (use 'clojure.contrib.combinatorics) (use 'clojure.contrib.test-is) (deftest each-is-equal-to-each (let [data [0 0.0 0M] test-data (combinations data 2)] (doseq [td test-data] (is (apply = td) Now, I can easily extend 'data' to do more tests (e.g. byte 0, float 0, ...). This will work, but it is not as readable as I would like it to be. Another approach would be to allow 'are' macro to accept generated testing data: user= (combinations [0 0.0 0M] 2) ((0 0.0) (0 0M) (0.0 0M)) user= (apply concat (combinations [0 0.0 0M] 2)) (0 0.0 0 0M 0.0 0M) (are (= _1 _2) (apply concat (combinations [0 0.0 0M] 2))) Older style of tests could be then rewritten as: (are (= _1 _2) 3 (+ 1 2) 0 (+ -1 1)) becomes (are (= _1 _2) (list 3 (+ 1 2) 0 (+ -1 1))) or nicer: (are (= _1 _2) [3 (+ 1 2) 0 (+ -1 1)]) Comments welcome, Frantisek --~--~-~--~~~---~--~~ 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 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: test-is: generating and processing testing data
Oops, error. Sequence passed to 'are' cannot be evaluated = use quoted list '( or quoted vector '[ ... (are (= _1 _2) '(3 (+ 1 2) 0 (+ -1 1))) Hm... Since 'are' is basically creating bunch of 'is' tests, I wonder how to also add a description message for each test. Thinking along the lines: (are (= _1 _2) '(3 (+ 1 2) should be 3 0 (+ -1 1) -x + x = 0)) (are (is (= _1 _2) _3) '(3 (+ 1 2) should be 3 0 (+ -1 1) -x + x = 0)) (do-parse (is (= _1 _2) _3) '(3 (+ 1 2) should be 3 0 (+ -1 1) -x + x = 0)) Frantisek --~--~-~--~~~---~--~~ 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 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: changes to test_clojure and test_contrib
I have some tests ready for test_clojure. I asked Rich for SVN access rights. There is gonna be more tests soon :-) Frantisek On Sun, Jan 25, 2009 at 8:55 PM, Stuart Halloway stuart.hallo...@gmail.comwrote: In SVN 412 I have made the following changes to contrib: * a test_contrib.clj file which does for contrib what test_clojure.clj does for clojure * a test_clojure task in build.xml * a test_contrib task in build.xml * a test task to aggregate all test tasks This is *very* minimal, but I wanted it so I could TDD some other changes I am making to contrib. Feedback or further improvement most welcome. Let's write some tests! Stuart --~--~-~--~~~---~--~~ 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 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: Streams work
Word streams invokes association to data-flow languages. For a while, I was following Project V: Simple Example of the Difference Between Imperative, Functional and Data Flow. http://my.opera.com/Vorlath/blog/2008/01/06/simple-example-of-the-difference-between-imperative-functional-and-data-flow Project V Redefined http://my.opera.com/Vorlath/blog/2008/04/04/project-v-redefined Project V: Dealing With Components http://my.opera.com/Vorlath/blog/2007/10/12/project-v-dealing-with-components Is there any connection whatsoever? Could we reuse something in Clojure? (I am still a newbie, so sorry for noise otherwise.) Greetings, Frantisek --~--~-~--~~~---~--~~ 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 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: Streams work
Hello Rich, Looking forward to using them! It is pleasure to see such nice development! Frantisek --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Functional Geometry
Hello all! I ported beatiful functional geometry: http://www.frank-buss.de/lisp/functional.html http://intricatevisions.com/index.cgi?page=nlcodetk into Clojure: http://intricatevisions.com/source/clojure/fg.clj (link from the page http://intricatevisions.com/index.cgi?page=clojure) When you run it, it should generate postscript file fish.ps. Enjoy, Frantisek --~--~-~--~~~---~--~~ 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 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.contrib.test-is: first major rewrite
2. each= and all-true are gone, replaced by the new macro are, which works with any predicate: (are = 2 (+ 1 1) 4 (+ 2 2)) -Stuart Sierra Hello and thanks for additions! Happy to see additions and work done on tests :-) I just wonder - how do you define all-true using are? Since are always makes pairs for predicate, it might not be possible. (defn logically-true? [x] (if x true false)) (are logically-true? 43 abc true (not false) (not nil)) My guess: Fails because logically-true? accepts only 1 argument and (not nil) never gets tested even if predicate accepts 2 arguments (are doesn't test for odd number of params). Possible solution: Add another number-of-arguments parameter to are: (are 2 = (+ 1 2) 3 (+ 1 -1) 0 ) (are 1 logically-true? 43 abc true (not false) (not nil)) Also [syntactic sugar]: (are 1 pred? ...) could be (are-all pred? ...) (are 2 pred? ...) could be (are-pairs pred? ...) Thanks for considering these ideas, Frantisek PS: Still writing tests - latest are 'and', 'or', 'first', 'rest', 'ffirst'. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Testing Clojure - progress sign up
Hello all! I started writing some unit tests for Clojure. This is what I got so far: http://intricatevisions.com/source/clojure/fs_test_clojure.clj I am almost done with 'first' and 'rest'. I will do ffirst, frest, rfirst, rrest, second. Since I did 'if', I would also like to do 'and' and 'or'. I am almost done with majority of predicates (mainly type predicates list? number? nil? false? ...). If you want to contribute to function testing, please: 1) Make sure you have contribution agreement (CA) with Rich 2) Reply to this message and say what are you going to be working on, so that we don't do anything twice Stephen C. Gilardi started this effort and I believe he is willing to coordinate us :-) Thanks, Frantisek --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: clojure.contrib.test-is changes
Thanks Stuart! It will certainly make writing tests more enjoyable :-) Inspiration for :equal-pairs/each= came from the test framework I wrote for newLISP: http://newlisp-on-noodles.org/wiki/index.php/Function_Testing Tests there are written as each= with 2 exceptions: '-' evaluates the next expression without testing it 'err' works as 'throws' Function 'test-fn' evaluates tests and returns the list of results. Function 'print-test-fn' can take these results and just print them out. Feel free to get inspired from it. If you see something nice, we can use it. Frantisek PS: newLISP is changing fast. Test framework was written for older version so many things might not work at this moment. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: clojure.contrib.test-is changes
Thinking about test-is little more... Lets look at this test for minus: (deftest test-minus (all-true (number? (- 1 2)) (integer? (- 1 2)) (float? (- 1.0 2)) (ratio? (- 2/3 1)) (float? (- 2/3 (/ 1.0 3 (throws IllegalArgumentException (-)) (each= (- 1) -1 (- 1 2) -1 (- 1 2 3) -4 (- -2) 2 (- 1 -2) 3 (- 1 -2 -3) 6 (- 1 1) 0 (- -1 -1) 0 (- 2/3) -2/3 (- 2/3 1) -1/3 (- 2/3 1/3) 1/3 (- 1.2) -1.2 (- 2.2 1.1) 1.1 (- 6.6 2.2 1.1) 3.3) ; no underflow :) (is ( (- Integer/MIN_VALUE 10) Integer/MIN_VALUE))) There are currently 4 elements - all-true, throws, each=, is. I am scratching my head, trying to figure out, how to merge these together or to make it read better... Ideas: A) Lets merge 'is' and 'all-true' Would it be possible to abandon the optional message 'is' macro has? I am sure, I will not use it. Then 'is' could accept multiple params and we are down to 3! (all-true is out) B) What about 'throws' macro? Could this become a function returning true/false? Then we could stick it inside 'is' or 'all-true'. (I guess it doesn't matter that much, does it?) C) Lets name them more similar, so it reads better: 'is', 'is-each', 'is-true'. Just what came to my mind :-) Greetings, Frantisek --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Testing Clojure (was Re: Bug? Strange set equality (r1075))
Using this, test t-Symbols (deftest t-Symbols (is (= 'abc (symbol abc))) (is (= '*+!-_? (symbol *+!-_?))) (is (= 'abc:def:ghi (symbol abc:def:ghi))) (is (= 'abc/def (symbol abc def))) (is (= 'abc.def/ghi (symbol abc.def ghi))) (is (= 'abc/def.ghi (symbol abc def.ghi))) (is (= 'abc:def/ghi:jkl.mno (symbol abc:def ghi:jkl.mno))) (is (instance? clojure.lang.Symbol 'alphabet)) ) becomes: (deftest t-Symbols (check (:equal 'abc (symbol abc) '*+!-_? (symbol *+!-_?) 'abc:def:ghi (symbol abc:def:ghi) 'abc/def (symbol abc def) 'abc.def/ghi (symbol abc.def ghi) 'abc/def.ghi (symbol abc def.ghi) 'abc:def/ghi:jkl.mno (symbol abc:def ghi:jkl.mno) ) (instance? clojure.lang.Symbol 'alphabet))) which is in my opinion much more readable. Any comments to this syntactic enhancement? Thank you, Frantisek --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Testing Clojure (was Re: Bug? Strange set equality (r1075))
On Thu, 13 Nov 2008 16:35:52 +0100, Dave Newton [EMAIL PROTECTED] wrote: --- On Thu, 11/13/08, Frantisek Sodomka wrote: [...] becomes: (deftest t-Symbols (check (:equal 'abc (symbol abc) '*+!-_? (symbol *+!-_?) 'abc:def:ghi (symbol abc:def:ghi) 'abc/def (symbol abc def) 'abc.def/ghi (symbol abc.def ghi) 'abc/def.ghi (symbol abc def.ghi) 'abc:def/ghi:jkl.mno (symbol abc:def ghi:jkl.mno) ) (instance? clojure.lang.Symbol 'alphabet))) which is in my opinion much more readable. Any comments to this syntactic enhancement? My first impression when I read that is that it's expecting each arg to be equal to each other, not the reality of being a list of (expected to be) equal pairs. That's probably just me, I'm sure, but I find the original more readable and precise--something I think is key in tests, as tests are also documentation. Dave Yes, I am just trying to save on typing... ;-) :equal could be also :equal-pairs. It introduces new (and maybe strange) syntax... Anyway, accepting multiple expressions would be nice. Frantisek --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Testing Clojure (was Re: Bug? Strange set equality (r1075))
Hello, I would like to contribute to testing Clojure. (Rich has my CA already.) I have been thinking about it and going through some unit tests for different language. I am proposing this syntax change to macro 'is': Instead of writing: (deftest test-+ (is (= (+) 0)) (is (= (+ 1) 1)) (is (= (+ 1 2) 3)) (is (= (+ 1 2 3) 6)) (is (number? (+ 1 2))) (is (integer? (+ 1 2))) (throws ClassCastException (+ abc 2))) 1) Take multiple expressions instead of just one (deftest test-+ (is (= (+) 0) (= (+ 1) 1) (= (+ 1 2) 3) (= (+ 1 2 3) 6) (number? (+ 1 2)) (integer? (+ 1 2))) (throws ClassCastException (+ abc 2))) 2) Abstract equality tests (the most common tests): (deftest test-+ (is (:equal (+) 0 (+ 1) 1 (+ 1 2) 3 (+ 1 2 3) 6 ) (number? (+ 1 2)) (integer? (+ 1 2))) (throws ClassCastException (+ abc 2))) I believe that this syntax change would make writing tests easier and less tedious. Also, personally, I would prefer the name 'check' instead of 'is', but that's just me :-) Greetings, Frantisek On Mon, 20 Oct 2008 00:43:44 +0200, Stephen C. Gilardi [EMAIL PROTECTED] wrote: On Oct 19, 2008, at 5:11 PM, J. McConnell wrote: I've been thinking the same thing for awhile now and I'd love to help contribute to an effort like this. Thanks for getting the idea out there. You're welcome. It seems like clojure.contrib could be a more convenient place to keep this than the wiki. Direct or indirect contributions to clojure.contrib require that the contributed code be written by the contributor and that the contributor have a contributor agreement on file with Rich. Would that be acceptable to people interested in participating? I appreciate the care Rich showed and long view he took in coming up with the Contributor Agreement process. I think it would be a good idea to leverage that process for this effort as well. Discussion of alternative proposals for a good way to do this and place to keep it are welcome. I made a start on this today. I started with the Reader page at clojure.org and started making tests. I'm thinking of a structure like this: Run tests with: (require 'clojure.contrib.test-clojure) The definition of clojure.contrib.test-clojure requires subordinate test namespaces like 'clojure.contrib.test-clojure.Reader 'clojure.contrib.test-clojure.Evaluation 'clojure.contrib.test-clojure.Special-Forms ... with names that correspond to pages on the Clojure web site. After requiring the individual test namespaces, test-clojure runs clojure.contrib.test-is/run-tests on each one. Here's a sample from clojure.contrib.test-clojure. (ns clojure.contrib.test-clojure.Reader (:use clojure.contrib.test-is)) (deftest t-Symbols (is (= 'abc (symbol abc))) (is (= '*+!-_? (symbol *+!-_?))) (is (= 'abc:def:ghi (symbol abc:def:ghi))) (is (= 'abc/def (symbol abc def))) (is (= 'abc.def/ghi (symbol abc.def ghi))) (is (= 'abc/def.ghi (symbol abc def.ghi))) (is (= 'abc:def/ghi:jkl.mno (symbol abc:def ghi:jkl.mno))) (is (instance? clojure.lang.Symbol 'alphabet)) ) ; additional tests to flesh out (deftest t-Numbers) (deftest t-Characters) (deftest t-nil) (deftest t-Booleans) (deftest t-Keywords) (deftest t-Lists) (deftest t-Vectors) (deftest t-Maps) (deftest t-Sets) (deftest t-Quote) (deftest t-Character) (deftest t-Comment) (deftest t-Meta) (deftest t-Deref) (deftest t-Regex) (deftest t-Metadata) (deftest t-read) and a run: user= (require 'clojure.contrib.test-clojure) Testing #Namespace: clojure.contrib.test-clojure.Reader Ran 18 tests with 10 assertions. 0 failures, 0 exceptions. nil user= (Currently the number of tests exceeds the number of assertions by so much because of the placeholders.) Tesing Clojure is a big project and will take a lot of work over time. There many pieces and many interactions among them to test. The hope is that having it available will allow Rich to make changes with an even higher degree of confidence that they didn't have unintended consequences and to support efforts like Chouser's ClojureScript to bring Clojure to new platforms Discussion and suggestions are welcome. --Steve --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
debugging, logging, ... and code sections
Hello! It is very common pattern to include parts of code which are used for specific purposes - for example debugging, logging, etc. While these parts can be used when developing code, they can be removed from finished application. One way is to comment these parts out, when we are done. Since commenting can be tedious and error-prone, it makes sense to make a macro for this: (def *debug* true) ; true/false (defmacro debug [ body] (if *debug* `(do [EMAIL PROTECTED]))) (defn myfn [x] (debug (println Print some debug info...) (print x = ) (prn x)) (* 2 x)) (myfn 5) To extend this idea little further, lets define code sections: (def *section-tags* {:debug true :log0 true :log1 false}) (defmacro section [tag body] (if (*section-tags* tag) `(do [EMAIL PROTECTED]))) (defn myfn [x] (section :debug (println debugging info...) (print x = ) (prn x)) (section :log0 (println logging info...)) (section :log1 (println detailed logging info...)) (* 2 x)) (myfn 10) Latest addition for libs to boot.clj also has this pattern, when using *loading-verbosely* flag. Any comments welcome, Frantisek --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---