Re: (count (filter ...)) much slower in 1.3 Alpha 2?
Could someone else also try the sample code I included to see if they also experience the same ~10x slowdown for (count (filter ...)) in 1.3 Alpha 2? On Oct 28, 12:34 pm, Btsai benny.t...@gmail.com wrote: I have some code that counts the elements in a list that map to true in a lookup table, looking something like this: (def lookup-table {1 true, 2 false}) (def elements (range 100)) (count (filter lookup-table elements)) On my machine, with server mode enabled, the count + filter got ~10 times slower when I updated from 1.3 Alpha 1 to 1.3 Alpha 2: (Alpha 1) user= (time (count (filter lookup-table elements))) Elapsed time: 181.262702 msecs 1 (Alpha 2) user= (time (count (filter lookup-table elements))) Elapsed time: 2017.744155 msecs 1 Which is weird because looking up elements in the table did not become any slower: (Alpha 1) user= (time (doseq [x elements] (lookup-table x))) Elapsed time: 159.033341 msecs nil (Alpha 2) user= (time (doseq [x elements] (lookup-table x))) Elapsed time: 159.965861 msecs nil -- 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: (count (filter ...)) much slower in 1.3 Alpha 2?
Awesome, thank you :) On Oct 29, 2:29 pm, Stuart Halloway stuart.hallo...@gmail.com wrote: Rich has fixed this on master:http://github.com/clojure/clojure/commit/e354b01133e7cff8dc0d0eb9e90c... Thanks for the report! Stu I have some code that counts the elements in a list that map to true in a lookup table, looking something like this: (def lookup-table {1 true, 2 false}) (def elements (range 100)) (count (filter lookup-table elements)) On my machine, with server mode enabled, the count + filter got ~10 times slower when I updated from 1.3 Alpha 1 to 1.3 Alpha 2: (Alpha 1) user= (time (count (filter lookup-table elements))) Elapsed time: 181.262702 msecs 1 (Alpha 2) user= (time (count (filter lookup-table elements))) Elapsed time: 2017.744155 msecs 1 Which is weird because looking up elements in the table did not become any slower: (Alpha 1) user= (time (doseq [x elements] (lookup-table x))) Elapsed time: 159.033341 msecs nil (Alpha 2) user= (time (doseq [x elements] (lookup-table x))) Elapsed time: 159.965861 msecs nil -- 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
(count (filter ...)) much slower in 1.3 Alpha 2?
I have some code that counts the elements in a list that map to true in a lookup table, looking something like this: (def lookup-table {1 true, 2 false}) (def elements (range 100)) (count (filter lookup-table elements)) On my machine, with server mode enabled, the count + filter got ~10 times slower when I updated from 1.3 Alpha 1 to 1.3 Alpha 2: (Alpha 1) user= (time (count (filter lookup-table elements))) Elapsed time: 181.262702 msecs 1 (Alpha 2) user= (time (count (filter lookup-table elements))) Elapsed time: 2017.744155 msecs 1 Which is weird because looking up elements in the table did not become any slower: (Alpha 1) user= (time (doseq [x elements] (lookup-table x))) Elapsed time: 159.033341 msecs nil (Alpha 2) user= (time (doseq [x elements] (lookup-table x))) Elapsed time: 159.965861 msecs nil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting this error regarding duck-streams/spit ...
Awesome! Thanks for the great work, Tom :) clojuredocs has quickly become my go-to reference source. On Oct 26, 11:46 pm, Tom Faulhaber tomfaulha...@gmail.com wrote: You remind me that I need to markhttp://richhickey.github.com/clojure... as obsolete and redirect users to the new place. Zack Kim and I are working to have clojuredocs pull data from the autodoc system and, at that point, I assume that he'll add deprecation info over there as well. Sorry for any confusion! Clojure's still a fast moving target. Tom On Oct 26, 12:48 pm, Btsai benny.t...@gmail.com wrote: I'm fairly positive duck-streams is deprecated, as it is no longer present in the clojure-contrib git repository: http://github.com/clojure/clojure-contrib/tree/master/modules/ http://richhickey.github.com/clojure-contrib/doesn'thave the deprecation info most likely because it is the documentation for the original (now outdated) clojure-contrib repository, and doesn't have 1.2 info. http://clojure.github.com/clojure-contrib/isthe documentation for the current repository. clojuredocs should probably be updated to include the deprecation info, and also have its link to clojure-contrib point to the current repository. On Oct 26, 12:44 pm, Victor Olteanu bluestar...@gmail.com wrote: Thank you Btsai. I checked bothhttp://richhickey.github.com/clojure-contrib/io-api.html#clojure.cont... andhttp://clojuredocs.org/clojure_contrib/clojure.contrib.duck-streams/s... and couldn't find any reference to deprecation. If you can confirm that this deprecation was made official then we could update those docs so other people won't run into these same issues. Victor On Tue, Oct 26, 2010 at 12:46 AM, Btsai benny.t...@gmail.com wrote: I don't think it's a mistake or accident that spit exists in clojure.core. In 1.2, duck-streams became deprecated and functions such as spit were incorporated into clojure.core: http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/... http://clojure.github.com/clojure-contrib/duck-streams-api.html Are you using anything beyond spit and slurp*? If not, I think you can switch to clojure.core's slurp and spit and drop duck-streams altogether. On Oct 25, 8:59 pm, Victor Olteanu bluestar...@gmail.com wrote: Thank you. The following statement worked for me: (:require [clojure.contrib.duck-streams :as d]) As I was using slurp and slurp*, I then had to do the following: use the form d/slurp* instead (prefixed with d/) use slurp without a change This brings up a related point - I can see that there are functions with the same name in different packages, which I believe it's quite unfortunate. There is slurp in clojure.core and there is duck-streams/slurp* , along with other functions such as spit... I hope this kind of things might be addressed in future versions of 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 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure-contrib 1.3.0-alpha2 deployed to build.clojure.org
Thanks, that's great info to have :) Although I have to confess that I'm still doing only small exploratory projects, so I haven't gotten my feet wet with build systems like maven or lein yet. On Oct 27, 7:21 am, Stuart Sierra the.stuart.sie...@gmail.com wrote: Yes, to get one big JAR containing all of clojure-contrib, you can depend on: groupId: org.clojure.contrib artifactId: standalone version: 1.3.0-alpha2 Or in Leiningen: [org.clojure.contrib/standalone 1.3.0-alpha2] To get lots of little JARs for each of the contrib libraries, you can depend on: groupId: org.clojure.contrib artifactId: complete version: 1.3.0-alpha2 Or in Leiningen: [org.clojure.contrib/complete 1.3.0-alpha2] To get just a single library, check out the list athttp://build.clojure.org/releases/org/clojure/contrib/ and depend on: groupId: org.clojure.contrib artifactId: NAME-OF-THE-LIBRARY version: 1.3.0-alpha2 Or in Leiningen: [org.clojure.contrib/NAME-OF-THE-LIBRARY 1.3.0- alpha2] -S On Oct 26, 10:37 pm, Btsai benny.t...@gmail.com wrote: Is there still a complete jar somewhere that has all the modules? If so, I can't seem to find it. Or is that a thing of the past now? -- 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: challenge with vectors
Is it ok if the index starts at 0? (use '[clojure.contrib.seq :only (indexed)]) (defn get-min-and-index [coll] (apply min-key #(second (second %)) (indexed coll))) user= (get-min-and-index [[22 5] [56 8] [99 3] [43 76]]) [2 [99 3]] On Oct 26, 7:54 pm, Glen Rubin rubing...@gmail.com wrote: I have a sequence like this: [ [a b] [a b] [a b] [a b] ] where a and b are numbers. I would like to return the vector and its index for which b is the least in this collection. For example, if my data is as follows [ [22 5] [56 8] [99 3] [43 76] ] I would like to return 3rd vector in the collection where b is lowest [99 3], but I also would like to know that it is the 3rd vector, so maybe something like: [99 3 3] any suggestions??? thx a mil!! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure-contrib 1.3.0-alpha2 deployed to build.clojure.org
Is there still a complete jar somewhere that has all the modules? If so, I can't seem to find it. Or is that a thing of the past now? On Oct 26, 6:03 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: blah -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting this error regarding duck-streams/spit ...
I don't think it's a mistake or accident that spit exists in clojure.core. In 1.2, duck-streams became deprecated and functions such as spit were incorporated into clojure.core: http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/spit http://clojure.github.com/clojure-contrib/duck-streams-api.html Are you using anything beyond spit and slurp*? If not, I think you can switch to clojure.core's slurp and spit and drop duck-streams altogether. On Oct 25, 8:59 pm, Victor Olteanu bluestar...@gmail.com wrote: Thank you. The following statement worked for me: (:require [clojure.contrib.duck-streams :as d]) As I was using slurp and slurp*, I then had to do the following: use the form d/slurp* instead (prefixed with d/) use slurp without a change This brings up a related point - I can see that there are functions with the same name in different packages, which I believe it's quite unfortunate. There is slurp in clojure.core and there is duck-streams/slurp* , along with other functions such as spit... I hope this kind of things might be addressed in future versions of 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 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: Help to optimize palindrome search from input file
I think the indexing in all-combs may be off, causing it to miss certain combinations/substrings. user= (all-combs abc) (a ab) I used this instead: (defn substrings [s] (let [length (count s)] (for [i (range length) j (range (inc i) (inc length))] (subs s i j user= (substrings abc) (a ab abc b bc c) On Oct 12, 1:02 pm, tonyl celtich...@gmail.com wrote: Hi, I just started to learn clojure in a more serious way and I am doing the first level of the greplin challenge. I made it to work with a short palindrome like the example they give me, but when it comes to work with the input file, it takes for ever and I have to stop it. $ time clj level1.clj ^C real 11m35.477s user 1m44.431s sys 9m3.878s This is my code: (defn palindrome? [s] (= s (reduce str (reverse s (defn all-combs [in] (let [len (count in)] (for [i (range 0 (- len 2)), j (range (+ i 1) len)] (subs in i j (defn max-comp [x y] (let [lenx (count x), leny (count y)] (cond ( lenx leny) 1 (= lenx leny) 0 ( lenx leny) -1))) ;;(let [input I like racecars that go fast] (let [input (slurp ../_input/level1.in)] (println (nth (sort max-comp (filter palindrome? (all-combs input))) 0))) The input file is thishttp://challenge.greplin.com/static/gettysburg.txt It looks a bit procedural. It is long, but I don't think is the biggest bottleneck, I think it is my approach to create all the combinations possible for substrings. Maybe I should be using a lazy seq? How would I go to do that? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure 1.3 alpha 1 report - bitwise operations extremely slow
Some more data points on 1.3 alpha 1 performance: bit operations appear to be much faster on hinted args. For example, (defn unhinted-shift [n] (bit-shift-left n 1)) (defn ^:static hinted-shift [^long n] (bit-shift-left n 1)) user= (time (doseq [x (range 10)] (unhinted-shift x))) Elapsed time: 2533.935459 msecs user= (time (doseq [x (range 10)] (hinted-shift x))) Elapsed time: 33.889503 msecs On the other hand, / seems to be much faster on unhinted args. (defn unhinted-divide [n] (/ n 2)) (defn ^:static hinted-divide [^long n] (/ n 2)) user= (time (doseq [x (range 10)] (unhinted-divide x))) Elapsed time: 37.612043 msecs user= (time (doseq [x (range 10)] (hinted-divide x))) Elapsed time: 2687.836862 msecs I checked the enhanced operations (+, -, *, inc, dec) and their prime counterparts (+', -', *', inc', dec'). All 10 perform equally fast with unhinted and hinted args. On Sep 30, 12:19 am, Mark Engelberg mark.engelb...@gmail.com wrote: bitwise-and and bitwise-shift-right and bitwise-shift-left run more than 50 times slower in clojure 1.3 alpha 1 versus clojure 1.2. Could the 1.3 gurus please investigate this? Try something like this to see the difference: (time (doseq [x (range 10)] (bit-shift-left x 1))) This points to another issue with Clojure 1.3. I can't figure out how to determine what is a primitive and what isn't. Are the values produced by range primitives? Are the values produced by bitwise operations primitive? How can I determine this? -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
Hi Mark, I tested the change to expt-int. Unfortunately, still no performance gain. I'm afraid I don't have a solid enough grasp of Clojure to know what tweaks are needed to get performance fast again. Do you think you'll have time to play with 1.3 soon? On Sep 27, 1:00 am, Mark Engelberg mark.engelb...@gmail.com wrote: Thanks for the info. I'd need to research how clojure.lang.BigInt differs from java.math.BigInteger, but I'm sure that adding the extra case for BigInt in the multimethods wouldn't be too hard. I'm still stumped as to why expt and sqrt would be 100x slower. My first thought is that the loop/recur machinery has changed in 1.3, to support primitives in the recur, so perhaps there's some extra back and forth boxing/unboxing going on, or perhaps loop/recur is just fundamentally slower now? Another possibility is that all the literal numbers are now longs instead of Integers, so maybe that's slowing down the computations? I'd be curious to know whether explicitly boxing everything in the second line of expt-int helps the performance at all (along with the ' math operators), i.e., (defn- expt-int [base pow] (loop [n pow, y (num 1), z base] to (defn- expt-int [base pow] (loop [n (num pow), y (num 1), z (num base)] -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
I found that even without patching, most functions in clojure.contrib.math already correctly handle big nums in 1.3: Handles big nums in 1.3? absYes ceil Yes exact-integer-sqrt No expt No floor Yes gcdYes lcmYes round No sqrt Yes After patching the code to use +', -', *', inc', and dec', expt handled big nums correctly as well. However, exact-integer-sqrt and round still didn't. math= (exact-integer-sqrt 234523454564564565435456456456) IllegalArgumentException No method in multimethod 'integer-length' for dispatch value: class clojure.lang.BigInt clojure.lang.MultiFn.getFn (MultiFn.java:121) math= (round 23450928345029834502983450283405.1) 9223372036854775807 exact-integer-sqrt appears to need the integer-length multi-method to support the new clojure.lang.BigInt class. I'm guessing that's also why round is returning an incorrect result; since there's currently no case for clojure.lang.BigInt, it's falling through to the default of using Math/round, leading to truncation. Just replacing +, -, *, inc, dec with +', -', *', inc', and dec' did not result in any performance gains. I didn't want to clutter up this email with my test code, but if anyone wishes to see the code I used, just let me know. -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
Thanks Eric :) Have you considered submitting that change as a patch? On Sep 24, 5:35 pm, Eric Lavigne lavigne.e...@gmail.com wrote: I think I read somewhere that max-key applies f more times than is necessary, so should not be pass any f that takes significant time to compute. Yes, max-key calls f more times than necessary. http://code.google.com/p/clojure/issues/detail?id=95 We ran into this problem yesterday on a tic-tac-toe project, in which f was a function that determines who is winning for a given board position. Tests that previously ran in under a minute now took over 10 minutes (that's roughly how long I waited before stopping it). We fixed our program by replacing max-key with the alternative implementation from the above link. http://github.com/ericlavigne/tic-tac-toe/commit/0d172c45c9d462620af8... -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
I went through the rest of my Project Euler code. In addition to even?, there are some functions in clojure.contrib that are also much slower in 1.3 Alpha 1. clojure.contrib.math - expt (Clojure 1.2) user= (time (doseq [x (range 10)] (expt x 2))) Elapsed time: 119.417971 msecs (Clojure 1.3) user= (time (doseq [x (range 10)] (expt x 2))) Elapsed time: 10314.24357 msecs clojure.contrib.math - sqrt (Clojure 1.2) user= (time (doseq [x (range 10)] (sqrt x))) Elapsed time: 176.063438 msecs (Clojure 1.3) user= (time (doseq [x (range 10)] (sqrt x))) Elapsed time: 16323.254492 msecs For now, I've switched to using sqrt in the clojure.contrib.generic.math-functions module (no slow-down in 1.3). That module also has a pow function, which I was going to use as a replacement for expt. But pow doesn't seem to handle very large numbers: user= (pow 999 999) Infinity So for now I'm using this as a temporary stop-gap: (defn expt [base pow] (reduce *' (repeat pow base))) Also found that sequences from clojure.contrib.lazy-seqs that used to produce arbitrarily large numbers in 1.2 no longer do so in 1.3: (Clojure 1.2) user= (nth (fibs) 100) 354224848179261915075 user= (nth (powers-of-2) 100) 1267650600228229401496703205376 (Clojure 1.3) user= (nth (fibs) 100) ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1575) user= (nth (powers-of-2) 100) 0 ... probably also because of 1.3's changes to numeric operations (http://dev.clojure.org/display/doc/Enhanced+Primitive+Support). I guess the take-away is that while playing with 1.3, be prepared to deal with performance and/or overflow issues when using existing numeric code (whether your own or someone else's) that doesn't yet take into account the changes to numeric 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
Awesome, thanks :) On Sep 25, 8:44 pm, Mark Engelberg mark.engelb...@gmail.com wrote: http://code.google.com/p/clojure/issues/detail?id=95 I just looked over this code. You can speed it up even more by manually encoding the loop, rather than using reduce. (defn faster-max-key ([k x] x) ([k x more] (loop [x x, kx (k x) s more] (if-not s x (let [y (first s), ky (k y)] (if ( kx ky) (recur x kx (next s)) (recur y ky (next s 5x faster than the one at the code.google.com link above in my own benchmarks. -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
I haven't tried 1.3 yet, but I'd recommend downloading a copy of clojure.contrib.math locally and replace any instances of +, -, *, inc, dec with +', -', *', inc', dec'. This should at least make the functions produce the correct results. I'd be curious to know whether performance continues to be bad after making those changes, so if you do this experiment, please report your results. I'd be happy to try this out. Will report back later. -- 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
Some code dramatically slower in Clojure 1.3 Alpha 1?
After updating from Clojure 1.2 to Clojure 1.3 Alpha 1, I noticed that one of my Project Euler solutions became dramatically slower. The solution was for Problem 14, finding the number less than N that produces the longest Collatz sequence. For N = 100,000, the time required to find the answer was as follows: Clojure 1.2 = 1327.45 msecs Clojure 1.3 Alpha 1 = 191186.76 msecs (For Problem 14, N is actually 1,000,000, but I ran out of patience waiting for the code to produce the answer in Clojure 1.3 Alpha 1) Has anyone run into something like this, or know what might have caused the dramatic difference in speed? The code: (defn next-term [n] (if (even? n) (/ n 2) (inc (* n 3 (defn count-terms [n] (if (= 1 n) 1 (inc (count-terms (next-term n) (let [pair (juxt identity count-terms) pairs (map pair (range 1 10))] (println (first (apply max-key second pairs Machine specs: Intel Core 2 Duo T9300 @ 2.5 GHz 2 GB RAM JVM is running on server mode P.S. I originally wanted to write that last part of the code a little more elegantly, like this: (println (apply max-key count-terms (range 1 10))) But that made things even slower: Clojure 1.2 = 2764.48 msecs Clojure 1.3 Alpha 1 = 740025.36 msecs I think I read somewhere that max-key applies f more times than is necessary, so should not be pass any f that takes significant time to compute. -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
FYI, I tried re-writing count-terms using loop/recur, but it didn't really make a difference: (defn count-terms-recur [n] (loop [n n count 1] (cond (= 1 n) count (even? n) (recur (/ n 2) (inc count)) :else (recur (inc (* n 3)) (inc count) Clojure 1.2 = 1153.43 msecs Clojure 1.3 Alpha 1 = 190769.86 msecs On Sep 24, 10:41 am, Btsai benny.t...@gmail.com wrote: After updating from Clojure 1.2 to Clojure 1.3 Alpha 1, I noticed that one of my Project Euler solutions became dramatically slower. The solution was for Problem 14, finding the number less than N that produces the longest Collatz sequence. For N = 100,000, the time required to find the answer was as follows: Clojure 1.2 = 1327.45 msecs Clojure 1.3 Alpha 1 = 191186.76 msecs (For Problem 14, N is actually 1,000,000, but I ran out of patience waiting for the code to produce the answer in Clojure 1.3 Alpha 1) Has anyone run into something like this, or know what might have caused the dramatic difference in speed? The code: (defn next-term [n] (if (even? n) (/ n 2) (inc (* n 3 (defn count-terms [n] (if (= 1 n) 1 (inc (count-terms (next-term n) (let [pair (juxt identity count-terms) pairs (map pair (range 1 10))] (println (first (apply max-key second pairs Machine specs: Intel Core 2 Duo T9300 @ 2.5 GHz 2 GB RAM JVM is running on server mode P.S. I originally wanted to write that last part of the code a little more elegantly, like this: (println (apply max-key count-terms (range 1 10))) But that made things even slower: Clojure 1.2 = 2764.48 msecs Clojure 1.3 Alpha 1 = 740025.36 msecs I think I read somewhere that max-key applies f more times than is necessary, so should not be pass any f that takes significant time to compute. -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
David, Nicolas, thank you for finding the culprit so quickly :) What profiling technique/tool did you use? I have some other code that is also much slower in 1.3, and thought I'd take a crack at finding the culprit myself before spamming the list again. On Sep 24, 11:26 am, Nicolas Oury nicolas.o...@gmail.com wrote: Try (defn even? Returns true if n is even, throws an exception if n is not an integer {:added 1.0 :static true} [n] (zero? (bit-and (long n) (long 1 before your example. It is fast on my computer. (I believe there is a reflective call, without the explicit cast.) -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?
Thank you David. Time for me to dig in! On Sep 24, 3:36 pm, David Nolen dnolen.li...@gmail.com wrote: On Fri, Sep 24, 2010 at 5:25 PM, Btsai benny.t...@gmail.com wrote: David, Nicolas, thank you for finding the culprit so quickly :) What profiling technique/tool did you use? I have some other code that is also much slower in 1.3, and thought I'd take a crack at finding the culprit myself before spamming the list again. Your code was simple enough for me to make a couple of educated guesses. For more complex code I'd use VisualVM,https://visualvm.dev.java.net/ David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure meetup group listing
I second the motion. Just moved to Edmonton, and have been looking around for fellow Clojurians. I've created an Edmonton meetup (I think), and hopefully some kindred souls will turn up :) On Sep 20, 9:33 am, Andrew Gwozdziewycz apg...@gmail.com wrote: Hey All, I know there are certainly a few groups out there (organized via Meetup.com or otherwise) which I see things posted about from time to time on the list. I'd like to propose that we make an effort to list these groups on Meetup Everywhere (http://www.meetup.com/everywhere), which is a free platform useful for finding a nearby meetup about a given topic. Please note, this is not meant to overtake your existing organization method. Everywhere is designed to be agnostic in regards to organization platform. If enough groups start listing there, it might make sense to then post a link on the Clojure site to help people find their local user group: http://www.meetup.com/Clojure I can make changes to the page as necessary. Cheers, Andrew --http://www.apgwoz.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
My poor brain can't handle nested calls to update-in, so this is what I came up with: (defn add-meetings [data k meetings] (cond (nil? (data k)) (assoc data k {:title title :meetings meetings}) :else (update-in data [k :meetings] concat meetings))) On Sep 16, 8:53 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com wrote: you don't like my one-liner ? :-) I saw your message only after I sent mine. :) (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp vec concat) data) Hmm... (comp vec concat) == into? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) -- 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: thinking in clojure
That pattern will be a great addition to the toolbox, thank you :) On Sep 16, 9:58 am, Laurent PETIT laurent.pe...@gmail.com wrote: And note that the pattern works at any level, and is easily readable, since update-in flattens the arguments of the modifying function : If you want to touch the path [:a :b :c :d] and provide specific default values at each level if the key is not found, it's as simple as : (update-in coll [:a] (fnil update-in default-for-first-level) [:b] (fnil update-in default-for-second-level) [:c] (fnil update-in default-for-third-level) [:d] (fnil update-in default-for-fourth-level) the-function-you-wanted-to-use-in-the-first-place arg2-for-the-function arg3-for-the-function ...) 2010/9/16 Laurent PETIT laurent.pe...@gmail.com So nested calls to update-in are needed in order to be able to provide a specific default value, everytime just having an empty map created isn't sufficient. So instead of (update-in {} [:a :b] identity) which returns {:a {:b nil}} , you can break the key path at :a so that the default value if no :a is specified by (fnil XXX default-value). And by specifying that XXX is update-in, you can continue your key path where you stopped (after :a), either using the found value at :a, either the provided default value : (update-in {} [:a] (fnil update-in {:label great label}) [:b] identity) = {:a {:b nil, :label great label}} or you can also decide that it's not a map which should be the default value, imagine you want to modify a path [:a 2] : (update-in {} [:a] (fnil update-in [:foo :bar :baz]) [2] str) = {:a [:foo :bar :baz]} 2010/9/16 Btsai benny.t...@gmail.com My poor brain can't handle nested calls to update-in, so this is what I came up with: (defn add-meetings [data k meetings] (cond (nil? (data k)) (assoc data k {:title title :meetings meetings}) :else (update-in data [k :meetings] concat meetings))) On Sep 16, 8:53 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com wrote: you don't like my one-liner ? :-) I saw your message only after I sent mine. :) (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp vec concat) data) Hmm... (comp vec concat) == into? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Generating functions programmatically
I'm sorry, but despite reading through the rest of the thread, it's not clear to me why that is a problem. icemaze, could you elaborate on what your use case is? I think with all of our powers combined, we can come up with something that fits your needs :) On Sep 10, 7:24 pm, Robert McIntyre r...@mit.edu wrote: That is very elegant but has the exact same problem in that the macro must be called on a literal vector of keywords. --Robert McIntyre On Fri, Sep 10, 2010 at 5:41 PM, Btsai benny.t...@gmail.com wrote: This is probably not the prettiest way to do it, but I think it gets the job done: (defn make-sym [keyword] (- keyword name (str prefix-) symbol)) (defn make-fn [keyword] (let [n (gensym)] (list 'defn (make-sym keyword) [n] (list '= n keyword (defmacro make-fns [keywords] `(do ~@(map make-fn keywords))) user= (make-fns [:a :b :c]) #'user/prefix-c user= (prefix-a :a) true user= (prefix-a :x) false user= (prefix-b :b) true user= (prefix-b :x) false user= (prefix-c :c) true user= (prefix-c :x) false The credit belongs to Alan, and Mr. Stuart Halloway for his examples from Ch. 7 of Programming Clojure. On Sep 10, 2:37 pm, icemaze icem...@gmail.com wrote: Alan, thank you for your reply. Unfortunately your solution is very similar to mine and it suffers from the same problem (maybe I'm using it incorrectly, I don't know). If I write: (doseq [x '(:a :b)] (make-fn x)) it defines a single function synthetic-x. Is there a way to make this work? I tried everything but both eval and var-get don't work for local bindings. Thanks again. -- 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: Generating functions programmatically
Ah ok. I couldn't come up with anything, but I think Kent has a nice eval-free (and macro-free) solution. My thanks to you, and everyone who chimed in, for helping me better understand the read-time/compile-time/run-time distinction. On Sep 11, 8:29 am, icemaze icem...@gmail.com wrote: Hi Btsai, thank you for your offer for help. As I said before I *could* use literals but it wouldn't be convenient. I have a big structure which contains information about types (they are types of domain-specific objects). I would like to extract the methods I need from this structure and define them programmatically. Previous solutions to this problem (both by me and other helpful posters) required to pass keywords as literals. While I could do that, maintaining a separate list would be a hassle. Right now I'm using: (doseq [t (an-expession-which-extracts-a-list-of-keywords)] (eval `(defobjecttype ~t))) So the problem is solved for me, although I have to use eval. I'm not sure exactly how dirty this trick is and especially *why* it is considered a smell. I read it on Paul Graham's On Lisp and he vehemently opposes its use but he doesn't explain why or where it is acceptable. Note that he also considered Common Lisp let* a smell, which is standard practice in Clojure (and in fact there's no equivalent of Common Lisp let). So maybe we are just making too much a big deal of this eval thing. I feel however that this problem should be addressed by the macro system somehow (although maybe that's not possible by design). If someone could find a solution which doesn't involve eval it would definitely be more elegant. -- 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: Generating functions programmatically
This is probably not the prettiest way to do it, but I think it gets the job done: (defn make-sym [keyword] (- keyword name (str prefix-) symbol)) (defn make-fn [keyword] (let [n (gensym)] (list 'defn (make-sym keyword) [n] (list '= n keyword (defmacro make-fns [keywords] `(do ~@(map make-fn keywords))) user= (make-fns [:a :b :c]) #'user/prefix-c user= (prefix-a :a) true user= (prefix-a :x) false user= (prefix-b :b) true user= (prefix-b :x) false user= (prefix-c :c) true user= (prefix-c :x) false The credit belongs to Alan, and Mr. Stuart Halloway for his examples from Ch. 7 of Programming Clojure. On Sep 10, 2:37 pm, icemaze icem...@gmail.com wrote: Alan, thank you for your reply. Unfortunately your solution is very similar to mine and it suffers from the same problem (maybe I'm using it incorrectly, I don't know). If I write: (doseq [x '(:a :b)] (make-fn x)) it defines a single function synthetic-x. Is there a way to make this work? I tried everything but both eval and var-get don't work for local bindings. Thanks again. -- 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: 1.2 contrib shuffles
How are you grabbing the sources? I'm also running under Windows, and get the source from github via msysgit, which handles the crlf vs. cr issue nicely. On Aug 27, 8:07 am, gary ng garyng2...@gmail.com wrote: I need to exclude/modify a few test when running under windows, due to the crlf vs cr stuff -- 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: trouble using nested map fn
Ah, so this is the context for your previous thread about multiplying lists. Re-using some of the code from that thread: (def target [[1 2 3 4] [2 3 4 5]]) (def signal [[[1 2 3 4] [2 3 4 5] [3 4 5 6]] [[2 3 4 5] [3 4 5 6] [4 5 6 7]]]) (defn correlate [target signal] (let [mult-lists (fn [x y] (map * x y)) mult-list-by-lists (fn [l ls] (map #(mult-lists l %) ls))] (map mult-list-by-lists target signal))) user= (correlate target signal) (((1 4 9 16) (2 6 12 20) (3 8 15 24)) ((4 9 16 25) (6 12 20 30) (8 15 24 35))) On Aug 23, 9:26 am, Glen Rubin rubing...@gmail.com wrote: I am trying to write a fn to correlate 2 signals using 3 nested map fn. I have 2 collections of data. THe first group of signals called target looks something like this. target: ( (1,2,3,4) (2,3,4,5) ...) The second collection is called signal and looks like this: signal: ( ((1,2,3,4)(2,3,4,5)(3,4,5,6)) ((2,3,4,5)(3,4,5,6)(4,5,6,7)) ... ) I would like to take the first list in target and multiply it by every list in the first group of signal. And then continue on processing the second list, etc... which would result in something like: ( ((1,4,9,16)(2,6,12,20)(3,8,15,24)) ((4,9,16,25) (6,12,20,30) (8,15,24,35)) ... ) I try a nested map fns like this, but can't get it to work: (map #(map #(map * %1 %2) %1 %2) target signal) -- 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: Feedback on idiomatic clojure
I believe duck-streams is deprecated since clojure 1.2. You may want to consider bringing back f-to-seq, which can be simplified slightly using reader from clojure.java.io: (ns clojure.example.anagrams (:use [clojure.java.io :only (reader)]) (:gen-class)) (defn f-to-seq [file] (with-open [rdr (reader file)] (doall (line-seq rdr On Aug 19, 10:39 pm, Damon Snyder drsny...@gmail.com wrote: Hi Meikel, Nicolas, and Justin, Thank you for the great feedback! I learned a lot. I was puzzled about (update-in (update-in)) and after doing that the - operator makes a lot of sense. The reduce is clever and fits nicely as well. I dropped the function that read in the lines of the file and used read-lines instead. Below is what I put together after the feedback. Thanks, Damon PS- I was mistaken before. The first version was taking over a minute. This version takes about 15s. (ns clojure.example.anagrams (:require clojure.contrib.duck-streams) (:gen-class)) (defn str-sort[string] (when string (apply str (sort string (defn str-to-lower[string] (when string (.toLowerCase string))) (defn anagram-add[anagrams akey word] (if (contains? anagrams akey) (- anagrams (update-in [akey :count] inc) (update-in [akey :words] conj word)) (assoc anagrams akey {:count 1 :words [word]}))) (def normalise (comp str-to-lower str-sort)) (defn build-anagrams[words] (reduce #(anagram-add %1 (normalise %2) %2) {} words)) (defn print-anagram[v] (println (str (:count (second v)) (first v) : (:words (second v) (defn print-anagrams[ana] (doseq [v ana] (print-anagram v))) (defn anagram-key[elem] (- (:count (second elem ;(def *words* (f-to-seq /usr/share/dict/web2)) ;(def *anagrams* (sort-by anagram-key (build-anagrams *words*))) ;(print-anagrams (take 10 *anagrams*)) (defn -main[file] (time (print-anagrams (take 10 (sort-by anagram-key (build-anagrams (clojure.contrib.duck-streams/read-lines file))) On Aug 19, 5:41 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, here my turn. Comments inline. Hope this helps. Sincerely Meikel (defn f-to-seq [file] (with-open [rdr (java.io.BufferedReader. (java.io.FileReader. file))] (doall (line-seq rdr ; Yes. doall is required here. Alternatively you can wrap the whole thing ; in the with-open. Then you can process also larger files without keeping ; all data in memory. YMMV. (defn str-sort [string] (when string (apply str (sort string ; One can also skip the when here. Then nil input returns an empty string. ; Whether that is better depends on the usage of the return value. YMMV. ; (if (nil? x) x ...) is usually written as (when x ...). (defn str-to-lower [string] (when string (.toLowerCase string))) (defn anagram-add [anagrams akey word] (if (contains? anagrams akey) (- anagrams (update-in [akey :count] inc) (update-in [akey :words] conj word)) (assoc anagrams akey {:count 1 :words [word]}))) ; I would prefer vectors over lists to store stuff. You get nice ; things for free, like O(1) appending, O(1) reverse, O(1) random ; access, ... (defn word [s] (first s)) ; or: (def word first) ; not needed for my solution (def normalise (comp str-to-lower str-sort)) (defn build-anagrams [words] (reduce #(anagram-add %1 (normalise %2) %2) {} words)) ; Looping with an accumulator, just returning the latter when the ; input is exhausted cries for reduce. (defn print-anagram [v] (println (str (:count (second v)) (first v) : (:words (second v) ; one could use destructuring to access things. (defn print-anagram [anagram] (let [[normal-form {:keys [count words]}] anagram] (println (str count normal-form : words (defn print-anagrams [ana] (doseq [v ana] (print-anagram v))) ; more descriptive names would be good, I guess (defn anagram-key [elem] (- (:count (second elem ; the minus should take care of the reverse? (def *words* (f-to-seq /usr/share/dict/web2)) (def *anagrams* (sort-by anagram-key (build-anagrams *words*))) (print-anagrams (take 10 *anagrams*)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure 1.2 Release
Congratulations! Just as a heads-up, the download link for Clojure Contrib on http://clojure.org/downloads is currently broken. It's pointing to: http://github.com/downloads/clojure/clojure/clojure-contrib-1.2.0.zip .. when I'm guessing it should be: http://github.com/downloads/clojure/clojure-contrib/clojure-contrib-1.2.0.zip On Aug 19, 9:45 am, Stefan Kamphausen ska2...@googlemail.com wrote: Hi, On 19 Aug., 17:25, Rich Hickey richhic...@gmail.com wrote: I'm pleased to announce today the release of Clojure 1.2. this is a great achievement. Congratulations to all involved and thank you! For us it the release is just on time. We will finish our book / tomorrow/ and I had been hoping for weeks now, that 1.2 would come out before we have to finalize things. So, we don't have to use an RC for our examples. Funny how life organizes itself sometime. :-) Kind regards, Stefan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What is the reason Lisp code is not written with closing parenthesis on new lines?
Yet another one for Emacs users that don't use paredit: I have Paren Match Highlighting enabled and set to highlight the entire expression within matching parens (the highlighting kicks in when the cursor is before the opening paren or after the closing paren): (show-paren-mode 1) (setq show-paren-style 'expression) In addition to helping me match up parens, it also helps me see the scope of extended expressions like let or for at a glance. On Aug 19, 10:08 am, Brian Goslinga quickbasicg...@gmail.com wrote: On Aug 19, 1:55 am, michele michelemen...@gmail.com wrote: Thanks everyone for the your answers (and the internal debates). I will not put closing parenthesis on new lines. Even though the editor helps me with the parenthesis, there have been situations - while editing inside functions - that I had to count them. Here is another trick that works for me in Emacs: delete most of the stack of closing parens, and then spam the ) key until the Emacs matches it to the desired opening paren. I can't remember a time that I had to manually count the parens when using that technique. Using paredit would be another solution, though (like most things) you have to invest some time in learning it to put it to good use. -- 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: multiplying lists
This should work: (defn mult-list-by-lists [a b] (let [mult-lists (fn [x y] (map * x y))] (map #(mult-lists a %) b))) On Aug 19, 5:56 pm, Glen Rubin rubing...@gmail.com wrote: I want to multiply a list of n items by h lists of n items, so that for example if i have list 'a' and 'b' (def a (list 1 2 3)) (def b (list '(4 5 6) '(7 8 9))) when multiplied I will get: ((4 10 18) (7 16 27)) -- 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: Argument order / Documentation Mismatch
No worries :) On Aug 16, 12:55 pm, Timothy Washington twash...@gmail.com wrote: Ahh, my bad. Cheers Tim On Sun, Aug 15, 2010 at 8:40 PM, Btsai benny.t...@gmail.com wrote: I think the mismatch is because page you looked at is for clojure.string, not clojure-contrib.string. The documentation for the split from clojure-contrib.string is here: http://clojure.github.com/clojure-contrib/string-api.html#clojure.con... On Aug 15, 5:12 pm, Timothy Washington twash...@gmail.com wrote: Hope I'm not missing something here, but the documentation for the split function ( http://clojure.github.com/clojure/clojure.string-api.html#clojure.str...) on 'clojure/contrib/string' says that the input args are: *Usage: (split s re)* * (split s re limit)* But I took a look at the source and they are the reverse of that ( clojure-contrib-1.2.0-RC3/src/main/clojure/clojure/contrib/string.clj ): (defn split Splits string on a regular expression. Optional argument limit is the maximum number of splits. {:deprecated 1.2} * ([^Pattern re ^String s] (seq (.split re s)))* * ([^Pattern re limit ^String s] (seq (.split re s limit* The documentation might need to be updated. Tim -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Game development in Clojure
Continuing this train of thought... 1. The declare macro may be handy for declaring multiple names at once. 2. Maybe one could use the functions in clojure.repl or clojure- contrib.ns-utils to write something that automatically forward declares everything needed? On Aug 13, 10:49 pm, Tim Daly d...@axiom-developer.org wrote: Suppose you make a file containing a (def foo) form for every defn in every file and then load that first? Does that solve the circular reference problem? Tim Daly Eric Lavigne wrote: The (def g) in your example has the same effect as the (declare foo) in my example. I discussed two problems. The first problem, which you addressed, was mostly just a warm-up for discussing a related problem that is more severe. Where can I put (def g) so that two files can require each other? This is not a rare problem for me. Like Mike Anderson, I work around it by putting extra thought into which package-level dependencies I will allow, which sometimes necessitates creating more or fewer packages than I otherwise would have created. On Sat, Aug 14, 2010 at 12:13 AM, Wilson MacGyver wmacgy...@gmail.com wrote: I rarely run into this. The few times I have, I just do (def g) ;creates a var g that is unbound (defn f [] (g)) ;ok (defn g [] ;f will call this nil) as shown by Rich at http://markmail.org/message/vuzvdr4xyxx53hwr#query:+page:1+mid:tzsd3k... On Fri, Aug 13, 2010 at 11:49 PM, Eric Lavigne lavigne.e...@gmail.com wrote: Suppose I have two functions in the same file, and one depends on the other: (defn foo [x] (+ 1 x)) (defn bar [x] (* 2 (foo x))) I can't switch their order without adding extra forward-declaration code, which is redundant: (declare foo) (defn bar [x] (* 2 (foo x))) (defn foo [x] (+ 1 x)) -- Omnem crede diem tibi diluxisse supremum. -- 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: Exception when trying to require clojure.contrib.io
The following worked for me: (ns your-namespace (:require (clojure.contrib io))) (See: http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/ns) This also works: (ns your-namespace (:require [clojure.contrib.io])) On Aug 11, 2:46 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 11 Aug., 10:19, Folcon fol...@gmail.com wrote: The stacktrace is as follows: Backtrace: 0: clojure.lang.LazySeq.sval(LazySeq.java:47) useless stuff snipped Wow. Emacs really goes out of its way to hide what's going on. If you try your code in a normal repl it should tell you the file where things go wrong. Also the caused by lines tell you the chain of causes. Not the location information (bar.clj:1) alsthough the 1 is entirely correct. user= (require 'foo.bar) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISe q from: clojure.lang.Symbol (bar.clj:1) user= (.printStackTrace *e) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol (bar.clj:1) at clojure.lang.Compiler.eval(Compiler.java:5435) snip at clojure.main.main(main.java:37) Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol at clojure.lang.LazySeq.sval(LazySeq.java:47) snip at clojure.lang.Compiler.macroexpand(Compiler.java:5336) at clojure.lang.Compiler.eval(Compiler.java:5404) ... 32 more Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.l ang.Symbol at clojure.lang.LazySeq.sval(LazySeq.java:47) snip at clojure.lang.LazySeq.sval(LazySeq.java:42) ... 45 more Caused by: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol at clojure.lang.RT.seqFrom(RT.java:471) snip at clojure.lang.LazySeq.sval(LazySeq.java:42) ... 50 more Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Exception when trying to require clojure.contrib.io
Hmmm. Actually, as Meikel noted, this should be fine, and it does indeed work for me: (ns your-namespace (:require clojure.contrib.io)) The only time I got the Don't know how to create ISeq from: clojure.lang.Symbol exception is when I erroneously copy-pasted and tried to evaluate this: (ns your-namespace (:require clojure.contrib.io)) On Aug 11, 2:46 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 11 Aug., 10:19, Folcon fol...@gmail.com wrote: The stacktrace is as follows: Backtrace: 0: clojure.lang.LazySeq.sval(LazySeq.java:47) useless stuff snipped Wow. Emacs really goes out of its way to hide what's going on. If you try your code in a normal repl it should tell you the file where things go wrong. Also the caused by lines tell you the chain of causes. Not the location information (bar.clj:1) alsthough the 1 is entirely correct. user= (require 'foo.bar) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISe q from: clojure.lang.Symbol (bar.clj:1) user= (.printStackTrace *e) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol (bar.clj:1) at clojure.lang.Compiler.eval(Compiler.java:5435) snip at clojure.main.main(main.java:37) Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol at clojure.lang.LazySeq.sval(LazySeq.java:47) snip at clojure.lang.Compiler.macroexpand(Compiler.java:5336) at clojure.lang.Compiler.eval(Compiler.java:5404) ... 32 more Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.l ang.Symbol at clojure.lang.LazySeq.sval(LazySeq.java:47) snip at clojure.lang.LazySeq.sval(LazySeq.java:42) ... 45 more Caused by: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol at clojure.lang.RT.seqFrom(RT.java:471) snip at clojure.lang.LazySeq.sval(LazySeq.java:42) ... 50 more Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure 1.2 RC1
The jar can be located in the target sub-directory. On Aug 1, 2:37 am, Mark Engelberg mark.engelb...@gmail.com wrote: Meant to say, ...zip doesn't have a compiled jar... On Sun, Aug 1, 2010 at 1:36 AM, Mark Engelberg mark.engelb...@gmail.comwrote: On Fri, Jul 30, 2010 at 8:00 AM, Stuart Halloway stuart.hallo...@gmail.com wrote: Clojure 1.2 RC 1 is now available, along with a corresponding Clojure Contrib, at: http://clojure.org/downloads Is there any particular reason the contrib release candidate zip have a compiled jar inside 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
Re: clojure.string namespace missing from API page?
Thank you Tom :) On Jul 18, 12:10 pm, Tom Faulhaber tomfaulha...@gmail.com wrote: The official doc for clojure and clojure-contrib have moved as well. They are now at: http://clojure.github.com/clojure/ and http://clojure.github.com/clojure-contrib/ I have not got them completely up-to-date with the 1.2 beta split, so for the moment just look at the master branch. I expect to have that fixed in the next few days. You are correct, clojure.string is not there. I'll get that added today. Thanks for catching it! Tom -- 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.string namespace missing from API page?
Hi Clojurians, The recent 1.2 beta release is the first time I played with 1.2. When reading the release notes, I saw a number of new namespaces. I was able to find most of them (clojure.java.io, etc.) on the API site (http://richhickey.github.com/clojure/). However, I could not find the clojure.string namespace. Did I miss something? Any help would be greatly appreciated. -Benny P.S. My apologies for the repeat question (I asked this question in the 1.2 beta release announcement thread as well), but I am leaning quite a bit on the API site as I continue to learn the functions built into Clojure, and could really use some help figuring this out. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure.string namespace missing from API page?
Thank you Adrian. I did see in the release announcement thread that that is the new source site for 1.2. However, I was unable to find an online API there. http://richhickey.github.com/clojure/ is the only online API I have seen. And again, the other new 1.2 namespaces like clojure.java.io show up just fine there, which is why I'm confounded why clojure.string is not there. On Jul 17, 8:57 am, Adrian Cuthbertson adrian.cuthbert...@gmail.com wrote: Hi Benny, The 1.2 release source site has moved tohttp://github.com/clojure/ -Regards, Adrian On Sat, Jul 17, 2010 at 8:00 AM, Btsai benny.t...@gmail.com wrote: Hi Clojurians, The recent 1.2 beta release is the first time I played with 1.2. When reading the release notes, I saw a number of new namespaces. I was able to find most of them (clojure.java.io, etc.) on the API site (http://richhickey.github.com/clojure/). However, I could not find the clojure.string namespace. Did I miss something? Any help would be greatly appreciated. -Benny P.S. My apologies for the repeat question (I asked this question in the 1.2 beta release announcement thread as well), but I am leaning quite a bit on the API site as I continue to learn the functions built into Clojure, and could really use some help figuring this out. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure 1.2 Beta 1
Congrats to Clojure on hitting this fantastic milestone :) Question: the release notes mentions a new clojure.string namespace. But I've had no luck finding it in the online API at http://richhickey.github.com/clojure/. Am I missing something? On Jul 14, 9:03 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Clojure 1.2 Beta 1 is now available, along with a corresponding Clojure Contrib, at: http://clojure.org/downloads It contains significant new features, as well as many bug fixes and small enhancements. A larger number of contributors than ever before have pitched in. You can see an overview of the changes in the changes file at: http://github.com/clojure/clojure/blob/1.2.x/changes.txt For maven/leiningen users, your settings to get the beta from build.clojure.org/releases are: :dependencies [[org.clojure/clojure 1.2.0-beta1] [org.clojure/clojure-contrib 1.2.0-beta1] To everyone who has contributed to 1.2, many thanks! Stu -- 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