Repeating a vector n times
I have to write a function that will take a vector as input, repeat the elements multiple times and return back a single vector of the repeated items. I came up with the following but am wondering if there is a better or simpler way to write this: (def xs [a b c]) (defn repeat-vec-n [xs n] (vec (reduce concat [] (take n (repeat xs) OUTPUT: user= xs [a b c] user= (repeat-vec-n xs 3) [a b c a b c a b c] -- Shoeb -- You 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: Repeating a vector n times
Thanks Tamreen. Your solution will have to be wrapped in another vec call. I will use Miekel's: (reduce into [] (repeat n xs)). From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Tamreen Khan Sent: Wednesday, July 13, 2011 11:02 AM To: clojure@googlegroups.com Subject: Re: Repeating a vector n times Damn, Meikel's solution is better, I was thinking: (apply concat (repeat n xs)) On Wed, Jul 13, 2011 at 10:54 AM, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: I have to write a function that will take a vector as input, repeat the elements multiple times and return back a single vector of the repeated items. I came up with the following but am wondering if there is a better or simpler way to write this: (def xs [a b c]) (defn repeat-vec-n [xs n] (vec (reduce concat [] (take n (repeat xs) OUTPUT: user= xs [a b c] user= (repeat-vec-n xs 3) [a b c a b c a b c] -- Shoeb -- You 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 mailto:clojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You 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
Data filtering function
I need help to write a small filtering function. Given the following definitions: (def m1 {[45] {:a 45 :b day1} [55] {:a 55 :b day1} [25] {:a 25 :b day1} [15] {:a 15 :b day1} [10] {:a 10 :b day1}}) (def m2 {[45] {:a 45 :b day2} [55] {:a 55 :b day2} [25] {:a 25 :b day2} [15] {:a 15 :b day2} [10] {:a 10 :b day2}}) (def m3 {[45] {:a 45 :b day3} [55] {:a 55 :b day3} [25] {:a 25 :b day3} [15] {:a 15 :b day3} [10] {:a 10 :b day3}}) (def d (list m1 m2 m3)) I need to write a function that returns the filtered results as follows: (my-filter d [45]) = ({:a 45 :b day1} {:a 45 :b day2} {:a 45 :b day3}) Thanks for your help. -- Shoeb -- You 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: Data filtering function
Thanks. That was simple. I got hung up on trying to use the filter function and didn't realize it could be done in simpler ways without it. -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Base Sent: Tuesday, July 05, 2011 3:37 PM To: Clojure Subject: Re: Data filtering function (map #(get % [45]) d) On Jul 5, 12:49 pm, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: I need help to write a small filtering function. Given the following definitions: (def m1 {[45] {:a 45 :b day1} [55] {:a 55 :b day1} [25] {:a 25 :b day1} [15] {:a 15 :b day1} [10] {:a 10 :b day1}}) (def m2 {[45] {:a 45 :b day2} [55] {:a 55 :b day2} [25] {:a 25 :b day2} [15] {:a 15 :b day2} [10] {:a 10 :b day2}}) (def m3 {[45] {:a 45 :b day3} [55] {:a 55 :b day3} [25] {:a 25 :b day3} [15] {:a 15 :b day3} [10] {:a 10 :b day3}}) (def d (list m1 m2 m3)) I need to write a function that returns the filtered results as follows: (my-filter d [45]) = ({:a 45 :b day1} {:a 45 :b day2} {:a 45 :b day3}) Thanks for your help. -- Shoeb -- You 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: Most concise way to determine that a sequence is consecutive integers starting with one?
Here is another way: (defn f [xs] (and (= 1 (first xs)) (apply = (map - (rest xs) xs From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of David Nolen Sent: Friday, July 01, 2011 3:51 PM To: clojure@googlegroups.com Subject: Re: Most concise way to determine that a sequence is consecutive integers starting with one? On Fri, Jul 1, 2011 at 3:28 PM, .Bill Smith william.m.sm...@gmail.com wrote: I want a concise function that, given an arbitrary length sequence, determines whether the sequence is of consecutive integers starting with one. So: (f [1 2 3]) returns true (f [1 2 4]) returns false (f [0 1 2]) returns false My first try, which I am not proud of, follows: (defn f [numbers] (every? (fn [[x y]] (= x y)) (partition 2 (interleave (iterate inc 1) numbers Can someone suggest something better? (defn f [xs] (every? #(apply = %) (map vector xs (iterate inc 1 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
RE: Translating Java code with nested for loops
Thanks to all for the excellent and quick responses. David - you are right the variable should be called product not sum. This is just some poorly written Java code that I am translating to Clojure. Justin - thanks for the idea on how to visualize such algorithms and the picture you shared. -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Alan Malloy Sent: Wednesday, June 29, 2011 4:50 AM To: Clojure Subject: Re: Translating Java code with nested for loops On Jun 29, 12:55 am, Ken Wesson kwess...@gmail.com wrote: On Wed, Jun 29, 2011 at 3:53 AM, Alan Malloy a...@malloys.org wrote: This layout makes it fairly clear that the first element of total- values is never being used, but it would be nice if we could say so explicitly. So finally, we can wrap the whole thing in a let: (defn calc [total-values daily-values] (let [interesting-values (next total-values)] (map-indexed (fn [i daily] (- total-values (drop i) (map #(inc (/ % 100.0))) (reduce * daily))) daily-values))) Oops. Not sure if this is what you're pointing out (a single word is tricky to decipher), but I did forget to *use* interesting-values after defining it: it should be the first form in 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 -- You 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: Translating Java code with nested for loops
Hi Alan I really liked the way you kept refactoring the original solution by Huahai to make it more and more logical and elegant. I verified that each refactored function produced the correct results. Thanks for sharing your valuable thoughts and techniques. Shoeb -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Huahai Yang Sent: Thursday, June 30, 2011 12:33 AM To: Clojure Subject: Re: Translating Java code with nested for loops Missed that one. Yeah, that's much nicer. -huahai On Jun 29, 6:39 pm, Alan Malloy a...@malloys.org wrote: (* daily (reduce * 1 coll)) ;; is exactly equal to (reduce * daily coll) My point is you can start with daily instead of with 1, and thus not have to special-case it in at the end. On Jun 29, 8:22 am, Huahai Yang huahai.y...@gmail.com wrote: The multiplication outside the reduce is required because it is part of the original logic: contrib[i] = sum * dailyValues[i];. Using the drop function is a very good call though. -huahai On Jun 29, 12:53 am, Alan Malloy a...@malloys.org wrote: If you're already doing a bunch of multiplication in the reduce, you don't need to do it outside as well, do you? And because reduce doesn't care about laziness, you can use drop instead of nthnext (which I think is clearer in almost all cases). (defn calc [total-values daily-values] (map-indexed (fn [i daily] (reduce #(* %1 (inc (/ %2 100.0))) daily (drop (inc i) total-values))) daily-values)) int n = dailyValues.length; for (int i = 0; i n; i++) { sum = 1.0; for (int j = i + 1; j n; j++) { sum *= (1.0 + (totalValues[j] / 100.0)); } contrib[i] = sum * dailyValues[i]; } -- You 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
Translating Java code with nested for loops
Hi I have been learning clojure for some time but am a bit stumped when translating code with nested for loops. Can someone help me to translate the following java code to clojure elegantly: The inputs are two arrays of type double of the same length - dailyValues and totalValues. The output is the array contrib of the same length. int n = dailyValues.length; for (int i = 0; i n; i++) { sum = 1.0; for (int j = i + 1; j n; j++) { sum *= (1.0 + (totalValues[j] / 100.0)); } contrib[i] = sum * dailyValues[i]; } Many thanks for your help. -- Shoeb -- You 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
BigDecimal Division - Arithmetic Exception
What is the workaround in Clojure for: (/ 1M 3M) I am reading data from the database which by default comes in as BigDecimal (through the JDBC driver and Clojure SQL). When I perform calculations on them including division with the '/' operator I get frequent ArithmeticExceptions based on my data. How should I deal with this? Also does it mean that performing division is not safe on data read from the database due to this problem? -- Shoeb -- You 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: BigDecimal Division - Arithmetic Exception
Thanks Ken. That did the trick. -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Ken Wesson Sent: Friday, June 17, 2011 3:17 PM To: clojure@googlegroups.com Subject: Re: BigDecimal Division - Arithmetic Exception On Fri, Jun 17, 2011 at 2:51 PM, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: What is the workaround in Clojure for: (/ 1M 3M) I am reading data from the database which by default comes in as BigDecimal (through the JDBC driver and Clojure SQL). When I perform calculations on them including division with the '/' operator I get frequent ArithmeticExceptions based on my data. How should I deal with this? Also does it mean that performing division is not safe on data read from the database due to this problem? Pick a finite precision sufficient for your needs and wrap in (with-precision ...). Take care about returning lazy sequences containing bignum division results though; you may need to use the odd (doall ...) to force sequences before they leave the scope of the with-precision. -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You 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: Vim Nailgun setup - access to REPL from outside Vim
Thanks Meikel. This did exactly what I wanted. Thanks for your efforts. From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Meikel Brandmeyer Sent: Tuesday, June 14, 2011 7:25 AM To: clojure@googlegroups.com Subject: Aw: Vim Nailgun setup - access to REPL from outside Vim Hi, do it the other way around. First start the repl. Then do a (require 'vimclojure.nails) (vimclojure.nails/start-server-thread). This will setup the vim backend in the background while you can still work with the repl. Hope that helps. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You 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: Recursive var definition
Thanks Baishmpayan. The link to the discussion thread you sent is very enlightening for a new comer to Clojure. -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Baishampayan Ghose Sent: Monday, June 13, 2011 2:41 AM To: clojure@googlegroups.com Subject: Re: Recursive var definition On Sat, Jun 11, 2011 at 6:48 PM, Shoeb Bhinderwala shoeb.bhinderw...@gmail.com wrote: I have never seen a recursive var definition such as fibs above and fail to understand how it works. When I read the fibs definition above, it looks like to define fibs it already should know about fibs since it is used in the map function. How does this work? And is this a good/idiomatic practice? The example was discussed in this group some time back. This is the discussion thread - http://groups.google.com/group/clojure/browse_thread/thread/95e40809e03d c3fa Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To 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: Radically simplified Emacs and SLIME setup
Thanks Phil for the good work. Emacs v23 didn't work for me in either Windows XP or Windows 7. So, I searched and found Emacs 24 at: http://code.google.com/p/emacs-for-windows/updates/list clojure-jack-in with Emacs 24 worked seamlessly with Windows 7 (64 bit). With Windows XP, clojure-jack-in fails with the following error: cd c:/projects/pasclj lein jack-in 11991: exited abnormally with code 1. So, on XP I start lein swank manually in another window and use slime-connect. Shoeb -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Mark Engelberg Sent: Thursday, June 09, 2011 4:22 AM To: clojure@googlegroups.com Subject: Re: Radically simplified Emacs and SLIME setup Andreas, can you clarify exactly where you got emacs from? I got it from here: http://ftp.gnu.org/gnu/emacs/windows/ Is there another/better source? On Thu, Jun 9, 2011 at 1:18 AM, Andreas Liljeqvist bon...@gmail.com wrote: One week ago on windows. install latest stable Emacs. install Emacs starter kit. M-x package-install clojure-mode lein plugin install swank-clojure 1.3.1 Be sure to remove any old swank-clojure from your plugin dir. invoke M-x clojure-jack-in from a project Works for me atleast. Phil - Thanks for all the great work. 2011/6/9 Mark Engelberg mark.engelb...@gmail.com It's been a couple of weeks, so I thought I'd check in and see whether anyone has yet been successful at using the new clojure-jack-in process on Windows. Did the 1.9.2 release successfully resolve the cannot find the path specified error for anyone else? Thanks, Mark On Mon, May 30, 2011 at 3:10 PM, Mark Engelberg mark.engelb...@gmail.com wrote: The package installer saw the 1.9.2 release, which I installed. I'm still getting the cannot find the path specified error though. Thanks for all the help you all have provided so far; let me know if you have any other ideas for me to try. Thanks, Mark -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
RE: New to Clojure
To start thinking functionally, I would also highly recommend reading the book Structure and Interpretation of Computer Programs: http://mitpress.mit.edu/sicp/ http://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs This book is available freely at the above sites. A better typeset format in PDF is available at (docs.google.com): https://docs.google.com/viewer?a=vpid=explorerchrome=truesrcid=0BxVCLS4f8Sg5OGUwMmZlZjYtZWQ4Zi00ZThmLWFkMjYtNTIxZmY4ODhjNDdlhl=enauthkey=CLnyyF4 Thanks Shoeb -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of hci Sent: Wednesday, June 08, 2011 3:33 PM To: Clojure Subject: Re: New to Clojure I was in the same boat last year. My experience with Clojure started with Java interop, by writing Clojure code to solve some small problems using existing Java libraries. For example, I used Clojure to fetch and process application logs in a MySQL database and visualize the results with a Java graph library. These experience got me into productive mode quickly and became familiar with the syntax of the language. However, I was not transformed into a Clojure programmer by just doing Java-interop because I was still thinking in Java way. It should be noted that the Clojure way is very different from the Java way. A transformation in thinking is necessary. I did the transformation by studying the Joy of Clojure book and did programming exercise on 4clojure.com. The former showed me the Clojure way and I practiced walking the way with the later. A good thing about 4clojure.com is that there is an immediate feedback on how well one does. The code either pass the unit tests or not. If it passes, one can see how short their own code compared with others. In searching a shorter solution, one often learns some functional tricks. Also, the site forces one to work with core Clojure functions only, and the use of def is not allowed. On Jun 7, 12:30 pm, Santosh M santoshvmadhyas...@gmail.com wrote: I want to learn clojure. I already know Java. Please tell me how to proceed. Regards Santosh -- You 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
Emacs - marmalade package install and .emacs file entries
I am new to emacs and not sure how to automatically get the right entries created in .emacs file after I install packages from marmalade. Once I install a package using marmalade (e.g. clojure-mode-1.9.2) I have to manually edit my .emacs file to add a load-path and require entry: Example entry in .emacs file: (add-to-list 'load-path ~/.emacs.d/elpa/clojure-mode-1.9.2/) (require 'clojure-mode) If I don't add the above entry clojure mode does not work. Similarly, after I install the packages slime and slime-repl, I have to manually add entries otherwise emacs doesn't recognize my command slime-connect. I am not even sure what the right entries are and how many require statements I have to add. So am a bit lost. Is there any way to have emacs/marmalade automatically add the right entries into the .emacs configuration file? -- Shoeb -- You 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: swank-clojure/lein/emacs
I figured out the cause of my problem. It is the presence of incanter! Having it in leiningen project.clj file as a dependency causes lein swank to throw the following error: C:\projects\pascljlein swank Exception in thread main java.lang.IllegalArgumentException: No value supplied for key: 4005 (NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:5440) at clojure.lang.Compiler.eval(Compiler.java:5414) at clojure.lang.Compiler.eval(Compiler.java:5415) at clojure.lang.Compiler.eval(Compiler.java:5391) at clojure.core$eval.invoke(core.clj:2382) When I remove [incanter 1.2.3] from my project.clj file the problem goes away. Obviously there is some incompatibility between incanter and swank-clojure. Anybody else face this issue or know of how to make incanter work with swank-clojure? Thanks Shoeb -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Phil Hagelberg Sent: Monday, June 06, 2011 12:16 AM To: Clojure Subject: Re: swank-clojure/lein/emacs On Jun 5, 9:09 am, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: I installed clojure-mode from marmalade. I added the following to my .emacs file: (add-to-list 'load-path ~/.emacs.d/elpa/clojure-mode/) (require 'clojure-mode) This is not necessary; if you install via marmalade then the autoloads will handle this for you. And also added the following to my lein project.clj file: :dev-dependencies [[swank-clojure 1.2.1]] This is a rather old version of swank. You should stick with 1.3.1 at least. When I perform step 3 from within EMACS, and specify the path to my lein project.clj file, I get the following error: Starting swank server... cd c:/projects/pasclj lein jack-in 1187: exited abnormally with code 1. This is probably due to the old swank version. Also when I execute the following command lein swank from the command line, I get the following error: C:\projects\pascljlein swank Exception in thread main java.lang.IllegalArgumentException: No value supplied for key: 4005 (NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:5440) at clojure.lang.Compiler.eval(Compiler.java:5414) at clojure.lang.Compiler.eval(Compiler.java:5415) at clojure.lang.Compiler.eval(Compiler.java:5391) at clojure.core$eval.invoke(core.clj:2382) There's also a bug when mismatched versions are in lib/dev vs ~/.lein/ plugins that can cause behaviour like this. It's best not to put swank in dev-deps at all but just stick with lein plugin install. Just inspect ~/.lein/plugins to make sure only 1.3.1 is in there. I'll update the readme to explain this issue. -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 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: Emacs - marmalade package install and .emacs file entries
Hi Phil - I am on Windows XP with Emacs version 23.3 Don't know what is meant by install of package.el. I simply followed instructions at: http://marmalade-repo.org/ and copied package.el to my ~/.emacs.d directory and added the following to my .emacs file: (add-to-list 'package-archives '(marmalade . http://marmalade-repo.org/packages/;)) If emacs version 23 is not supported, where can I get version 24? The gnu website does not list version 24 in the downloads: http://ftp.gnu.org/gnu/emacs/windows/ Thanks Shoeb -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Phil Hagelberg Sent: Monday, June 06, 2011 4:40 PM To: Clojure Subject: Re: Emacs - marmalade package install and .emacs file entries On Jun 6, 8:39 am, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: (add-to-list 'load-path ~/.emacs.d/elpa/clojure-mode-1.9.2/) (require 'clojure-mode) If I don't add the above entry clojure mode does not work. It sounds like this is a bug in package.el; this should all be handled for you. If you are using Emacs 24 then maybe you could try M-x report- emacs-bug since package.el is part of Emacs now. Otherwise it would take some further debugging; package.el works in Emacs 23 but is not officially supported. What's your OS and version of Emacs? How did you install package.el? -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 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: Emacs - marmalade package install and .emacs file entries
Hi Phil A lot of my problems went away when I downloaded Emacs version 24. Also I am able to successfully use swank-clojure from emacs now using clojure-jack-in. Thanks Shoeb -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Bhinderwala, Shoeb Sent: Monday, June 06, 2011 5:42 PM To: clojure@googlegroups.com Subject: RE: Emacs - marmalade package install and .emacs file entries Hi Phil - I am on Windows XP with Emacs version 23.3 Don't know what is meant by install of package.el. I simply followed instructions at: http://marmalade-repo.org/ and copied package.el to my ~/.emacs.d directory and added the following to my .emacs file: (add-to-list 'package-archives '(marmalade . http://marmalade-repo.org/packages/;)) If emacs version 23 is not supported, where can I get version 24? The gnu website does not list version 24 in the downloads: http://ftp.gnu.org/gnu/emacs/windows/ Thanks Shoeb -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Phil Hagelberg Sent: Monday, June 06, 2011 4:40 PM To: Clojure Subject: Re: Emacs - marmalade package install and .emacs file entries On Jun 6, 8:39 am, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: (add-to-list 'load-path ~/.emacs.d/elpa/clojure-mode-1.9.2/) (require 'clojure-mode) If I don't add the above entry clojure mode does not work. It sounds like this is a bug in package.el; this should all be handled for you. If you are using Emacs 24 then maybe you could try M-x report- emacs-bug since package.el is part of Emacs now. Otherwise it would take some further debugging; package.el works in Emacs 23 but is not officially supported. What's your OS and version of Emacs? How did you install package.el? -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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
swank-clojure/lein/emacs
I am struggling to setup swank-clojure and connect emacs with a lein swank session. I am on Windows XP. I followed the instructions at: http://clojure02.managed.contegix.com/display/doc/Getting+Started+with+E macs I installed clojure-mode from marmalade. I added the following to my .emacs file: (add-to-list 'load-path ~/.emacs.d/elpa/clojure-mode/) (require 'clojure-mode) And also added the following to my lein project.clj file: :dev-dependencies [[swank-clojure 1.2.1]] I did a lein deps to get everything updated. However my problem starts when I try to install swank-clojure from: https://github.com/technomancy/swank-clojure Again I am following the instructions: 1. Install clojure-mode either from Marmalade or from git. == DONE 2. lein plugin install swank-clojure 1.3.1 == DONE 3. From inside a project, invoke M-x clojure-jack-in == ERROR When I perform step 3 from within EMACS, and specify the path to my lein project.clj file, I get the following error: Starting swank server... cd c:/projects/pasclj lein jack-in 1187: exited abnormally with code 1. Also when I execute the following command lein swank from the command line, I get the following error: C:\projects\pascljlein swank Exception in thread main java.lang.IllegalArgumentException: No value supplied for key: 4005 (NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:5440) at clojure.lang.Compiler.eval(Compiler.java:5414) at clojure.lang.Compiler.eval(Compiler.java:5415) at clojure.lang.Compiler.eval(Compiler.java:5391) at clojure.core$eval.invoke(core.clj:2382) On my other machine which runs Windows 7, I see the same error above from within Emacs when I invoke M-x clojure-jack-in and specify the path to my lein project.clj file. Anybody else experienced similar issues. Any help guidance greatly appreciated. -- Shoeb -- You 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: swank-clojure/lein/emacs
I tried removing the :dev-dependencies but I am still having the same problem. I gave up on running clojure-jack-in. However, I am still facing issues running lein swank. Can someone please help me with lein swank? Here is my project.clj file: (defproject expclj 1.0.0-SNAPSHOT :description my description :dependencies [[org.clojure/clojure 1.2.1] [clojure-contrib 1.2.0] [incanter 1.2.3]]) I am using clojure 1.2.1 and clojure-contrib 1.2.0. I tried removing incanter but the problem does not go away. I installed the lein swank plugin by running the following command: lein plugin install swank-clojure 1.3.1 My leinengen version is: Leiningen 1.5.2 on Java 1.6.0_25 Java HotSpot(TM) 64-Bit Server VM I am running all this on Windows 7 - 64bit. When I run lein swank, I get the following error and then my console hangs: Exception in thread main java.lang.IllegalArgumentException: No value supplied for key: 4005 (NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:5440) at clojure.lang.Compiler.eval(Compiler.java:5414) at clojure.lang.Compiler.eval(Compiler.java:5415) at clojure.lang.Compiler.eval(Compiler.java:5391) at clojure.core$eval.invoke(core.clj:2382) at clojure.main$eval_opt.invoke(main.clj:235) at clojure.main$initialize.invoke(main.clj:254) at clojure.main$null_opt.invoke(main.clj:279) at clojure.main$main.doInvoke(main.clj:354) at clojure.lang.RestFn.invoke(RestFn.java:421) at clojure.lang.Var.invoke(Var.java:369) at clojure.lang.AFn.applyToHelper(AFn.java:163) at clojure.lang.Var.applyTo(Var.java:482) at clojure.main.main(main.java:37) Please can someone from the group help me with this problem. Is there anything wrong with my configuration? I simply can't get lein swank to work. I haven't even tried the emacs integration yet. Shoeb -Original Message- From: clojure@googlegroups.com on behalf of Vijay Kiran Sent: Sun 6/5/2011 12:42 PM To: clojure@googlegroups.com Subject: Re: swank-clojure/lein/emacs I don't think you need to add the :dev-dependency, can you try again by removing the line ? ./vijay On Jun 5, 2011, at 6:09 PM, Bhinderwala, Shoeb wrote: I am struggling to setup swank-clojure and connect emacs with a lein swank session. I am on Windows XP. I followed the instructions at: http://clojure02.managed.contegix.com/display/doc/Getting+Started+with+Emacs I installed clojure-mode from marmalade. I added the following to my .emacs file: (add-to-list 'load-path ~/.emacs.d/elpa/clojure-mode/) (require 'clojure-mode) And also added the following to my lein project.clj file: :dev-dependencies [[swank-clojure 1.2.1]] I did a lein deps to get everything updated. However my problem starts when I try to install swank-clojure from: https://github.com/technomancy/swank-clojure Again I am following the instructions: 1. Install clojure-mode either from Marmalade or from git. == DONE 2. lein plugin install swank-clojure 1.3.1 == DONE 3. From inside a project, invoke M-x clojure-jack-in == ERROR When I perform step 3 from within EMACS, and specify the path to my lein project.clj file, I get the following error: Starting swank server... cd c:/projects/pasclj lein jack-in 1187: exited abnormally with code 1. Also when I execute the following command lein swank from the command line, I get the following error: C:\projects\pascljlein swank Exception in thread main java.lang.IllegalArgumentException: No value supplied for key: 4005 (NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:5440) at clojure.lang.Compiler.eval(Compiler.java:5414) at clojure.lang.Compiler.eval(Compiler.java:5415) at clojure.lang.Compiler.eval(Compiler.java:5391) at clojure.core$eval.invoke(core.clj:2382) .. On my other machine which runs Windows 7, I see the same error above from within Emacs when I invoke M-x clojure-jack-in and specify the path to my lein project.clj file. Anybody else experienced similar issues. Any help guidance greatly appreciated. -- Shoeb -- You 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
RE: swank-clojure/lein/emacs
Yes it is 4005. But I am just using the defaults. Does the problem have anything to do with the number 4005? Again, I am just following simple instructions outlined to get swank running using lein, so that I can connect to it using emacs. I am not doing anything special or different. As a newcomer to clojure I am just struggling with getting a basic setup so I can use a repl in emacs and connect to swank launched by lein. Did anybody face similar problem/error? Are there any more detailed clearer instructions anywhere else? Thanks Shoeb -Original Message- From: clojure@googlegroups.com on behalf of Ambrose Bonnaire-Sergeant Sent: Sun 6/5/2011 3:56 PM To: clojure@googlegroups.com Subject: Re: swank-clojure/lein/emacs On Mon, Jun 6, 2011 at 3:46 AM, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: Exception in thread main java.lang.IllegalArgumentException: No value supplied for key: 4005 (NO_SOURCE_FILE:1) Might be a coincidence, isn't the swank port 4005? Ambrose -- You 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
Clojurebox/emacs setup
I am extremely new to Emacs. Been a long time Vim user. I have installed Clojurebox and am able to get it running easily. Can someone help me with the following: 1. I have a leningen project that I am working with. I usually do a lein repl in the project directory and all the jars in the lib path are automatically added to the classpath of the REPL. How can I do the same with clojurebox? Everytime I load a clojure file, I get exceptions saying classes not found on classpath. Basically, I want the REPL in clojurebox have the exact load behaviour of the lein repl. 2. How do I load a clojure file, compile it and then launch a REPL that has the file loaded? So that I can exercise my functions in the REPL? 3. How do I change color scheme to a dark color scheme? I googled and found the website ColorTheme (http://www.nongnu.org/color-theme/) but the download link is broken: http://download.savannah.nongnu.org/releases/color-theme/ In short I am looking for very straightforward clear instructions for someone who is brand new to emacs with clojurebox running swank-clojure/slime/paredit. -- Shoeb -- You 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: Clojurebox/emacs setup
No I am using Windows. I guess the most pressing problem for me is how to synchronize clojurebox with an existing leiningen project. I want the clojurebox REPL to behave just like the lein REPL in terms of classpath and jars loaded, etc. How do I configure the clojrurebox REPL for this? Thanks Shoeb From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Vijay Kiran Sent: Friday, June 03, 2011 4:43 PM To: clojure@googlegroups.com Subject: Re: Clojurebox/emacs setup Hi Shoeb, I'm not sure if you use mac, but here's the setup I've been using successfully: 1. Installed emacs 2. Installed the emacs-starter-kit (https://github.com/technomancy/emacs-starter-kit) 3. And then followed the http://technomancy.us/149 The clojure-jack-in mode does all the necessary actions and even starts the repl in another window of Emacs. For color modes I use a Mac, so on the Terminal I use the Solarized Dark theme, so it is used for Emacs as well. Make sure that you either change to the directory in which you have the lein project before you call clojure-jack-in. ./Vijay On Jun 3, 2011, at 9:26 PM, Bhinderwala, Shoeb wrote: I am extremely new to Emacs. Been a long time Vim user. I have installed Clojurebox and am able to get it running easily. Can someone help me with the following: 1. I have a leningen project that I am working with. I usually do a lein repl in the project directory and all the jars in the lib path are automatically added to the classpath of the REPL. How can I do the same with clojurebox? Everytime I load a clojure file, I get exceptions saying classes not found on classpath. Basically, I want the REPL in clojurebox have the exact load behaviour of the lein repl. 2. How do I load a clojure file, compile it and then launch a REPL that has the file loaded? So that I can exercise my functions in the REPL? 3. How do I change color scheme to a dark color scheme? I googled and found the website ColorTheme (http://www.nongnu.org/color-theme/ http://www.nongnu.org/color-theme/ ) but the download link is broken: http://download.savannah.nongnu.org/releases/color-theme/ http://download.savannah.nongnu.org/releases/color-theme/ In short I am looking for very straightforward clear instructions for someone who is brand new to emacs with clojurebox running swank-clojure/slime/paredit. -- Shoeb -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
RE: Jark 0.3 (using the nrepl protocol)
I am trying to install jark on a Linux server and running into issues. I am trying to follow the exact instructions as mentioned on the website: http://icylisper.in/jark/start.html I added the following bin directory to my PATH variable: /home/BhindSA/bin I downloaded jark-0.3 and copied it to file name jark: cp jark-0.3 /home/BhindSA/bin/jark When I run: jark self install, I get the following error: /home/BhindSA/bin/jark: line 296: /home/BhindSA/.config/jark/bin/jark-client: No such file or directory I tried creating the directories in .config, but still get the same error. What am I doing wrong? Can the instructions on the website be made clearer? -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of isaac praveen Sent: Thursday, May 05, 2011 1:18 PM To: clojure@googlegroups.com Cc: clojure-j...@googlegroups.com; clojure-jark-...@googlegroups.com Subject: ANN: Jark 0.3 (using the nrepl protocol) Hi, It is a pleasure to announce the release of Jark 0.3, today. Why Jark? Startup time of the Java Virtual Machine(JVM) is too slow and thereby command-line applications on the JVM are sluggish and very painful to use. Jark is an attempt to run a persistent JVM daemon and provide a set of utilities to control and operate on it. It should help in deploying clojure applications on the JVM, running command-line applications written in clojure and remote-debugging. The motivation is also to provide a very thin nrepl-client that can run on any given OS platform. Maybe one on the Android. The client host need not even have the JRE installed. The current implementation is in python(2.6 or 2.7) as a proof-of-concept and runs only on GNU/Linux and Mac OSX. Get started: http://icylisper.in/jark/start.html Jark has utilites for: a. Operating and tuning the JVM b. Managing classpaths c. Managing packages and repositories that are not project-specific (uses cljr) d. Scripting (#!/usr/bin/env jark) and namespaces. All of which can be done remotely. This is a sample usage: server jark vm start [--port] client jark vm connect [--host] [--port] client jark repl --- client jark vm stat client jark cp list server jark cp add jar client jark package install -p PACKAGE -v VERSION client jark ns load /path/to.clj and so on .. The earlier version (0.2) of jark used nailgun as a proof-of-concept server and client. The current release (0.3) of jark uses Chas Emerick's nrepl protocol for communication. I hope to rewrite the client in haskell, so native binaries can be generated, sometime soon. Have a look at the roadmap: Roadmap: http://icylisper.in/jark/roadmap.html Mailing list: https://groups.google.com/group/clojure-jark code: https://github.com/icylisper/jark.git Special thanks to: * Ambrose Bonnaire-Sergeant (for collaborating and providing very interesting ideas) * Bangalore-clojure group members for continuous feedback: Shantanu Kumar Abhijith Gopal Martin Demello Abhijit Hoskeri * other early jark users for valuable ideas and fixes Thats all folks! Hope you find it useful. Screencasts and demos are on the way ... -- isaac http://icylisper.in -- You 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: RE: Multi-level bucketing problem
Whoa! Thanks Juan. I will start to understand/analyze this... From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of JuanManuel Gimeno Illa Sent: Tuesday, May 03, 2011 11:40 AM To: clojure@googlegroups.com Subject: Re: RE: Multi-level bucketing problem I'm sure this can be simplyfied: (defn mlg [attrs data] (if (empty? attrs) [ (reduce + (map :mv data)) {:children data}] (let [parts (group-by (first attrs) data) subtrees (map (fn [[value data]] [value (mlg (rest attrs) (map #(dissoc % (first attrs)) data))]) parts)] (reduce (fn [[sum tree] [value [sumsubtree subtree]]] [(+ sum sumsubtree) (update-in tree [:children] conj (assoc subtree :path [(first attrs) value] :mv sumsubtree))] ) [ 0.0 { :children [] }] subtrees Returns a pair with the sum for all items and a tree. Each tree is represented as a dictionary, and inner nodes of the tree have three keys: - :mv the sum of :mv's of its children - :path a pair of attr-value that represents all the leaves in the subtree - :children the subtrees of this level Leaves are represented as dictionaries with only the keys :sec_id and :mv. I've forked your gist, so you can grab the code directly from github https://gist.github.com/952861 Best regards, Juan Manuel -- You 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
Optimizing my function for performance
This is related to my multi-level bucketing problem which I am starting new thread. The code is at: https://gist.github.com/952861 I am referring to the sum-by function which was provided by fellow clojurer in this group. It choked when I passed in data of size one million - meaning I didn't run out of memory but it took a very long time. Quoting below are two functions from my code: (def data (take 100 (repeatedly get-rec))) ;get aggregate values for list of attributes (defn sum-by [data attrs] (let [aggregated (group-by (apply juxt attrs) data)] (zipmap (keys aggregated) (map #(reduce + (map :mv %)) (vals aggregated) ;invoke sum-by (sum-by data [:attr1 :attr2]) Are there any obvious performance optimizations (e.g. transient, etc) that can be performed so that the function can perform better and consume less memory? In general what are the things to watch out for when writing functions such as these so as not to get poor performance with very large data sets. Thanks for your help. -- Shoeb -- You 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: Multi-level bucketing problem
Hi Miki What you provided is an amazing piece of code. I need a lot more time to understand how it works since it uses so many higher order functions. I have uploaded my original problem code base and your solution at: https://gist.github.com/952382 This is just a simplified version of my problem. What we are trying to do is group data in hierarchies and then performs all sorts of calculations on each grouping at each level. The calculations at the lower grouping levels also roll up and feed calculations at the higher levels. Your idea of not creating a tree and simply using functions to compute the values for the groups (nodes) is certainly very thought provoking. Thanks Shoeb From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Miki Sent: Monday, May 02, 2011 11:33 AM To: clojure@googlegroups.com Subject: Re: Multi-level bucketing problem One way is not to use a tree structure but to aggregate by composed keys, starting with [:attr1] then [:attr1 :attr2] ... (defn sum-by [data attrs] (let [aggregated (group-by (apply juxt attrs) data)] (zipmap (keys aggregated) (map #(reduce + (map :mv %)) (vals aggregated) (println (sum-by data [:attr1 :attr2])) -- You 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: Merging two maps based on ids
Thanks Ted. Using your approach I could write the following function which will allow me to merge any number of data sets very easily: (defn merge-by-ids [ args] (reduce #(merge %1 %2) (map #(index % [:id]) args))) Example: (def data1 ; lowest priority '({:id 2 :a2 34 :a3 76 :a4 87}, ;-- {:id 3 :a2 30 :a3 38 :a4 39}, {:id 4 :a2 10 :a3 73 :a4 38}, {:id 5 :a2 67 :a3 32 :a4 38}, {:id 7 :a2 84 :a3 86 :a4 63})) ;-- (def data2 '({:id 3 :a2 5534 :a3 5576 :a4 5587}, ;-- {:id 4 :a2 5584 :a3 5586 :a4 5563}, ;-- {:id 12 :a2 5593 :a3 5512 :a4 5539}, {:id 13 :a2 5509 :a3 5539 :a4 5592})) ;-- (def data3 ; highest priority '({:id 5 :a2 7734 :a3 7776 :a4 7787}, ;-- {:id 12 :a2 7793 :a3 7712 :a4 5539}, ;-- {:id 15 :a2 7709 :a3 7739 :a4 7792})) ;-- (merge-by-ids data1 data2 data3) Result: { {:id 2} #{{:id 2, :a2 34, :a3 76, :a4 87}}, {:id 3} #{{:id 3, :a2 5534, :a3 5576, :a4 5587}}, {:id 4} #{{:id 4, :a2 5584, :a3 5586, :a4 5563}}, {:id 5} #{{:id 5, :a2 7734, :a3 7776, :a4 7787}}, {:id 7} #{{:id 7, :a2 84, :a3 86, :a4 63}}, {:id 12} #{{:id 12, :a2 7793, :a3 7712, :a4 5539}}, {:id 13} #{{:id 13, :a2 5509, :a3 5539, :a4 5592}}, {:id 15} #{{:id 15, :a2 7709, :a3 7739, :a4 7792}}, } -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of GrumpyLittleTed Sent: Thursday, April 28, 2011 6:56 PM To: Clojure Subject: Re: Merging two maps based on ids Sometimes it helps to change the structure of the data you are using to fit the job and simplify matters. In this case it appears that you are trying to represent a relation. However the tuples are being represented in a non-associative structure (a list). If you represent the relation using an outer map of inner maps then the job becomes as simple as (merge data-orig data-override) The simplest way to do this is to use the value of the key (in this case :id) as the key for the outer map. You also ensure the uniqueness of the key in the resulting outer map. If you need to keep the data in the list structure you can do the transform to a relation using (use 'clojure.set) (index data-orig [:id]) though this solution will give you keys in the form {:id 2} and each value as a set (for one to many relations whereas in this case you only need one-one). Using a proper relational approach the full solution is simply (def data-orig {2 {:id 2 :a2 34 :a3 76 :a4 87} 3 {:id 3 :a2 30 :a3 38 :a4 39} 5 {:id 5 :a2 67 :a3 32 :a4 38} 4 {:id 4 :a2 10 :a3 73 :a4 38} 7 {:id 7 :a2 84 :a3 86 :a4 63}}) (def data-override {2 {:id 2 :a2 5534 :a3 5576 :a4 5587} 3 {:id 3 :a2 5584 :a3 5586 :a4 5563} 12 {:id 12 :a2 5593 :a3 5512 :a4 5539} 13 {:id 13 :a2 5509 :a3 5539 :a4 5592}}) (merge data-orig data-override) On Apr 26, 5:23 am, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: Can someone help me write a merge function between two maps? My problem is as follows: I have original data in a map: (def data-orig '({:id 2 :a2 34 :a3 76 :a4 87}, {:id 3 :a2 30 :a3 38 :a4 39}, {:id 5 :a2 67 :a3 32 :a4 38}, {:id 4 :a2 10 :a3 73 :a4 38}, {:id 7 :a2 84 :a3 86 :a4 63})) Then I have override data: (def data-override '({:id 2 :a2 5534 :a3 5576 :a4 5587}, {:id 3 :a2 5584 :a3 5586 :a4 5563}, {:id 12 :a2 5593 :a3 5512 :a4 5539}, {:id 13 :a2 5509 :a3 5539 :a4 5592})) The result should be a merge of the two with the following conditions: If the id is the same, should override the original data. If id is not present in original then it should be added. The result should be: '({:id 2 :a2 5534 :a3 5576 :a4 5587}, ;overriden {:id 3 :a2 5584 :a3 5586 :a4 5563}, ;overriden {:id 5 :a2 67 :a3 32 :a4 38}, {:id 4 :a2 10 :a3 73 :a4 38}, {:id 7 :a2 84 :a3 86 :a4 63}, {:id 12 :a2 5593 :a3 5512 :a4 5539}, ;added {:id 13 :a2 5509 :a3 5539 :a4 5592}) ;added Thanks for your help. -- Shoeb -- You 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
Multi-level bucketing problem
Hi fellow clojurers: I need help to group my data at multiple levels (currently 4) using a tree structure and perform aggregate calculations at each level. I have the below clojure code to generate a list of test records for me (using the get-rec function). (def reg-cntry-list {America [USA Canada Mexico Venezuala Brazil Argentina Cuba] Asia [India Pakistan Singapore China Japan Sri Lanka Malaysia] Europe [UK Germany France Italy Belgium Turkey Finland] Middle East [Saudi Arabia Bahrain UAE Kuwait Yemen Qatar Iraq] Africa [Libya Tanzania South Africa Kenya Ethiopia Morocco Zimbabwe]}) (def sec-ind-list {Basic Materials [Apparel Auto Part Building Packaged] Consumer Goods [Beveragess Cigarettes Drugs Newspapers] Financial [Life Insurance Banking Investment Funds] Healthcare [Home care Hospitals Plans Medical] Industrial [Chemicals Cleaning Machine Lumber] Services [Advertising Broadcasting Education Publishing] Technology [Biotechnology Computers Data Storage Electronics] Utilities [Farm Products Electric Gas Oil]}) (defn get-rec [] (let [r (rand-nth (keys reg-cntry-list)) s (rand-nth (keys sec-ind-list))] {:sec_id (rand-int 1000) :attr1 r :attr2 (rand-nth (reg-cntry-list r)) :attr3 s :attr4 (rand-nth (sec-ind-list s)) :mv (rand 100) })) ;generate 50 random records (def data (take 50 (repeatedly get-rec))) Each record (map) has the following keys: :sec_id - security id :attr1 - attribute 1 of the security :attr2 - attribute 2 of the security :attr3 - attribute 3 of the security :attr4 - attribute 4 of the security :mv - market value of the security What I need is a tree like data structure that can group my data in four levels (based on attr1, attr2, attr3 and attr4) as follows and also store total market value (total mv) for each level: root (total mv of all recs) |America (total mv for America) | |USA (total mv for America/USA) | |Financial (total mv for America/USA/Financial) | |___Banking (total mv for America/USA/Financial/Banking) | | :sec_id 1 :mv 889 | :sec_id 2 :mv 393 |___Funds (total mv for America/USA/Financial/Funds) | | :sec_id 3 :mv 33 | :sec_id 4 :mv 393 |Technology | |___Electronics | | sec_id 5 :mv 93 | sec_id 6 :mv 29 |___Data Storage | | sec_id 7 :mv 389 | sec_id 8 :mv 93 |Canada | |Industrial | |___Machine | | sec_id 10 :mv 34 | sec_id 11 :mv 93 |___Lumber | | sec_id 12 :mv 93 | sec_id 13 :mv 93 |___Europe (total mv for Europe) | |Germany | |Financial | |___Banking | | sec_id 1 :mv 93 | sec_id 2 :mv 93 |Technology | |___Electronics | | sec_id 5 :mv 93 | sec_id 6 :mv 93 |France | |Industrial | |___Lumber | | sec_id 12 :mv 93 | sec_id 13 :mv 93 I tried the group-by function but can't write it to get the nested data I want and to perform the aggregate computations at each level. I am learning Clojure using this exercise which is part of a bigger project that I am interested in re-writing using Clojure. Any help greatly appreciated. Thanks Shoeb -- You 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
RE: Merging two maps based on ids
Thanks Baishampayan, Meikel, pepijn, and Jonathan. The use of partition-by function does solve this very elegantly. Below is the list of solutions I have received: (defn merge-data [data1 data2] (map first (partition-by :id (sort-by :id (concat data2 data1) (defn merge-data2 [data1 data2] (let [override-ids (set (map :id data2))] (concat data2 (remove (comp override-ids :id) data1 (defn merge-override [merge-key data2 data1] (let [keyset (into #{} (map #(% merge-key) data2))] (apply merge data2 (remove #(keyset (% merge-key)) data1 From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Jonathan Fischer Friberg Sent: Tuesday, April 26, 2011 12:58 PM To: clojure@googlegroups.com Subject: Re: Merging two maps based on ids Correction: (concat data1 data2) should be (concat data2 data1) On Tue, Apr 26, 2011 at 6:37 PM, Jonathan Fischer Friberg odysso...@gmail.com wrote: (defn merge-data [data1 data2] (map first (partition-by :id (sort-by :id (concat data1 data2) Since the sorting is stable (relative order is kept), we know that the first occurrence of each id is either the existing map from data1, or the new map from data2. On Tue, Apr 26, 2011 at 5:34 PM, pepijn (aka fliebel) pepijnde...@gmail.com wrote: Another option is using clojure.set, as is shown here: https://github.com/pepijndevos/Begame/blob/master/src/begame/util.clj#L9 9 On Apr 26, 10:10 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, you can construct the output sequence from your input sequences. (defn merge-data [data-orig data-override] (let [override-ids (set (map :id data-override))] (concat data-override (remove (comp override-ids :id) data-orig If you need your output sorted you can also add a (sord-by :id ...) around the concat. 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 mailto:clojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You 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
Merging two maps based on ids
Can someone help me write a merge function between two maps? My problem is as follows: I have original data in a map: (def data-orig '({:id 2 :a2 34 :a3 76 :a4 87}, {:id 3 :a2 30 :a3 38 :a4 39}, {:id 5 :a2 67 :a3 32 :a4 38}, {:id 4 :a2 10 :a3 73 :a4 38}, {:id 7 :a2 84 :a3 86 :a4 63})) Then I have override data: (def data-override '({:id 2 :a2 5534 :a3 5576 :a4 5587}, {:id 3 :a2 5584 :a3 5586 :a4 5563}, {:id 12 :a2 5593 :a3 5512 :a4 5539}, {:id 13 :a2 5509 :a3 5539 :a4 5592})) The result should be a merge of the two with the following conditions: If the id is the same, should override the original data. If id is not present in original then it should be added. The result should be: '({:id 2 :a2 5534 :a3 5576 :a4 5587}, ;overriden {:id 3 :a2 5584 :a3 5586 :a4 5563}, ;overriden {:id 5 :a2 67 :a3 32 :a4 38}, {:id 4 :a2 10 :a3 73 :a4 38}, {:id 7 :a2 84 :a3 86 :a4 63}, {:id 12 :a2 5593 :a3 5512 :a4 5539}, ;added {:id 13 :a2 5509 :a3 5539 :a4 5592}) ;added Thanks for your help. -- Shoeb -- You 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: Why I'm getting an empty result?
Your function objects-at is correct but you have mixed up keywords and strings in the definitions. Try the following: (def *objects* '(:bottle :bucket :frog :chain)) (def *object-locations* {:bottle 'living-room, :bucket 'living-room, :chain 'garden, :frog 'garden}) (defn objects-at [loc objs obj-locs] (letfn [(is-obj-at? [obj] (= (obj obj-locs) loc))] (filter is-obj-at? objs))) (println (objects-at 'garden *objects* *object-locations*) -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of HB Sent: Sunday, March 27, 2011 10:03 PM To: Clojure Subject: Why I'm getting an empty result? Hi, Would you please have a look at this code: (def *objects* '(bottle bucket frog chain)) (def *object-locations* {:bottle 'living-room, :bucket 'living- room, :chain 'garden, :frog 'garden}) (defn objects-at [loc objs obj-locs] (letfn [(is-obj-at? [obj] (= (obj obj-locs) loc))] (filter is-obj-at? objs))) (println (objects-at :garden *objects* *object-locations*)) Why the result is empty? Shouldn't it be (bottle bucket)? Thanks for help and time. -- You 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: Help with function to partition my data
(Sent the below email earlier but for some reason didn't make it to the list) I wasn't aware of the group-by function. Being new to clojure, I spent a lot of time coming up with my complex function. Seeing the one line solution really blew me away. Thanks!! Follow up questions on my problem (my code again first): ;data is a list of records (maps) (def data '({:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 2 :a2 67 :a3 32 :a4 38}, {:a1 4 :a2 47 :a3 73 :a4 38}, {:a1 3 :a2 84 :a3 86 :a4 63})) ;result is a map, key = value of :a1, val = all records for that value of a1 ;as pointed out, result can be obtained by (group-by :a1 data) (def result '{2 [{:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 2 :a2 67 :a3 32 :a4 39}], ;grouped a1 = 2 3 [{:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 3 :a2 84 :a3 86 :a4 63}], ;grouped a1 = 3 4 [{:a1 4 :a2 47 :a3 73 :a4 38}] ;grouped :a1 = 4 }) ;groups the data by :a1 (see result above) (def data-g (group-by :a1 data) ;for a key value in data-g returns the total of all :a4 values (defn calc-tot-a4 [data-g k] (reduce + (map :a4 (get data-g k ;adjust a4 values for a given key (defn adj-a4 [data k] (assoc data k (map #(assoc % :a4 (+ (:a3 %) (:a4 %))) (get data k ;adjust data (defn adj-data [data f] (reduce f data (keys data))) ;make adjustments to the grouped data (def data-adj (adj-data data-g adj-a4)) I am expressing my domain specific problem in a very abstract way above. In reality the data I am manipulating comes from a database. This is financial performance data for an entire month. The data set is large - about 50,000 records. I need to group it by day and then perform manipulations on it. For example, I need to make adjustments to the values loaded from the database based on certain conditions. I need to aggregate values for a certain day etc. My question is - am I on the right track with the adj-data/adj-a4 functions. Secondly since I am constantly modifying the in-memory data (loaded using contrib.sql functions which loads it into plain maps), is this inefficient since the data structures are immutable. So every time I change a value, clojure functions will return me a new data structure. Will this be inefficient when I am dealing with a large data set and making constant modifications/adjustments to the values? Thanks for your great help. -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Alan Sent: Sunday, April 17, 2011 5:18 PM To: Clojure Subject: Re: Help with function to partition my data Simpler still: group-by? (group-by :a1 data) produces the result that Shoeb was looking for. PS The original message isn't in Google's archives either. On Apr 17, 7:54 am, Nate Austin navis...@gmail.com wrote: I didn't see this original email for some reason, but here's a simplified version: (reduce (fn [coll {a1 :a1 :as value}] (update-in coll [a1] conj value)) {} data) This takes advantage of update-in passing nil if it doesn't have the key and conj with nil returning a seq of one value. On Sun, Apr 17, 2011 at 12:30 AM, Shoeb Bhinderwala shua...@gmail.com wrote: Wrote the following function which did the trick: (defn partn [data] (let [add-mapping (fn [m v] (assoc m v (filter #(= v (:a1 %)) data)))] (reduce add-mapping {} (set (map #(:a1 %) data On Sat, Apr 16, 2011 at 8:15 PM, shuaybi shua...@gmail.com wrote: I am trying to write a function but can't get it right. I need to loop through my data records and for each unique value of :a1 I need to partition the data and create a resulting map so that the key is value of :a1 and the associated value of this key is all records with that value of :a1. Better explained with code, where given the definition of data below, I need to write a function that will return the definition of result below. ;data is a list of records (maps) (def data '({:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 2 :a2 67 :a3 32 :a4 38}, {:a1 4 :a2 47 :a3 73 :a4 38}, {:a1 3 :a2 84 :a3 86 :a4 63})) ;result should be a map, keyed by unique values of :a1 and containing all records for that value of :a1 (def result '{2 ({:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 2 :a2 67 :a3 32 :a4 39}), ;list of records where :a1 = 2 3 ({:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 3 :a2 84 :a3 86 :a4 63}), ;list of records where :a1 = 3 4 ({:a1 4 :a2 47 :a3 73 :a4 38}) ;list of records where :a1 = 4 }) (defn get-val-a1 Return all records in data where :a1 is specified val [data val] (filter #(= val (:a1 %)) ;filter function data)) (defn unique-a1 Get set of all unique :a1 values [m] (set (map #(:a1 %) m))) ;This is the function I am trying to write but can't get it right. (defn partn
RE: Help with function to partition my data
I wasn't aware of the group-by function. Being new to clojure, I spent hours coming up with my complex function. Seeing the one line solution really blew me away. Thanks!! Follow up questions on my problem (my code again first): ;data is a list of records (maps) (def data '({:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 2 :a2 67 :a3 32 :a4 38}, {:a1 4 :a2 47 :a3 73 :a4 38}, {:a1 3 :a2 84 :a3 86 :a4 63})) ;result is a map, key = value of :a1, val = all records for that value of a1 ;as pointed out, result can be obtained by (group-by :a1 data) (def result '{2 [{:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 2 :a2 67 :a3 32 :a4 39}], ;grouped a1 = 2 3 [{:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 3 :a2 84 :a3 86 :a4 63}], ;grouped a1 = 3 4 [{:a1 4 :a2 47 :a3 73 :a4 38}] ;grouped :a1 = 4 }) ;groups the data by :a1 (see result above) (def data-g (group-by :a1 data) ;for a key value in data-g returns the total of all :a4 values (defn calc-tot-a4 [data-g k] (reduce + (map :a4 (get data-g k (defn adj-a4 [data k] (assoc data k (map #(assoc % :a4 (+ (:a3 %) (:a4 %))) (get data k (defn adj-data [data f] (reduce f data (keys data))) (def data-adj (adj-data data-g adj-a4)) I am expressing my domain specific problem in a very abstract way above. In reality the data I am manipulating comes from a database. This is financial performance data for an entire month. The data set is large - about 50,000 records. I need to group it by day and then perform manipulations on it. For example, I need to make adjustments to the values loaded from the database based on certain conditions. I need to aggregate values for a certain day etc. My question is - am I on the right track with the adj-data/adj-a4 functions. Secondly since I am constantly modifying the in-memory data (loaded using contrib.sql functions which loads it into plain maps), is this inefficient since the data structures are immutable. So every time I change a value clojure functions return me a new data structure. Will this be inefficient when I am dealing with a large data set and making constant modifications/adjustments to the values? Thanks for your great help. -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Alan Sent: Sunday, April 17, 2011 5:18 PM To: Clojure Subject: Re: Help with function to partition my data Simpler still: group-by? (group-by :a1 data) produces the result that Shoeb was looking for. PS The original message isn't in Google's archives either. On Apr 17, 7:54 am, Nate Austin navis...@gmail.com wrote: I didn't see this original email for some reason, but here's a simplified version: (reduce (fn [coll {a1 :a1 :as value}] (update-in coll [a1] conj value)) {} data) This takes advantage of update-in passing nil if it doesn't have the key and conj with nil returning a seq of one value. On Sun, Apr 17, 2011 at 12:30 AM, Shoeb Bhinderwala shua...@gmail.com wrote: Wrote the following function which did the trick: (defn partn [data] (let [add-mapping (fn [m v] (assoc m v (filter #(= v (:a1 %)) data)))] (reduce add-mapping {} (set (map #(:a1 %) data On Sat, Apr 16, 2011 at 8:15 PM, shuaybi shua...@gmail.com wrote: I am trying to write a function but can't get it right. I need to loop through my data records and for each unique value of :a1 I need to partition the data and create a resulting map so that the key is value of :a1 and the associated value of this key is all records with that value of :a1. Better explained with code, where given the definition of data below, I need to write a function that will return the definition of result below. ;data is a list of records (maps) (def data '({:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 2 :a2 67 :a3 32 :a4 38}, {:a1 4 :a2 47 :a3 73 :a4 38}, {:a1 3 :a2 84 :a3 86 :a4 63})) ;result should be a map, keyed by unique values of :a1 and containing all records for that value of :a1 (def result '{2 ({:a1 2 :a2 34 :a3 76 :a4 87}, {:a1 2 :a2 67 :a3 32 :a4 39}), ;list of records where :a1 = 2 3 ({:a1 3 :a2 30 :a3 38 :a4 39}, {:a1 3 :a2 84 :a3 86 :a4 63}), ;list of records where :a1 = 3 4 ({:a1 4 :a2 47 :a3 73 :a4 38}) ;list of records where :a1 = 4 }) (defn get-val-a1 Return all records in data where :a1 is specified val [data val] (filter #(= val (:a1 %)) ;filter function data)) (defn unique-a1 Get set of all unique :a1 values [m] (set (map #(:a1 %) m))) ;This is the function I am trying to write but can't get it right. (defn partn [data] (let [val-set (unique-a1 data)) ;get unique :a1 values ret-val {}] (loop [v val-set] ;loop through the unique values (assoc ret-val v (get-val-a1 data v))) ;build
Adding key values in a list of maps
I am a beginner in Clojure. I have a list of maps: (def p '({:a 1 :b 2 :c 4}, {:a 2 :b 3 :c 5}, {:a 3 :b 4 :c 6})) How do I add up all the :b values in the map? Result should be 9 (=2+3+4) I know I should be using one of the higher level functions like apply, reduce and combine it with a custom filter function. But not sure how to write it. -- Shoeb -- You 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
Creating defrecords from results of a sql query
I am considering moving the results of with-query-results into defrecords. What is the best way to achieve this? I wrote the following but it hits the limitation of 20 parameters and I get an exception: (defrecord PerfRecord [perf-dt grp-id sec-id asset-class beg-mv-base end-mv-base beg_mv_locl end_mv_locl net_out_flows_base net_in_flows_base net_inc_flows_base accr_fx_base net_out_flows_locl net_in_flows_locl net_inc_flows_locl beg_accrued_base end_accrued_base beg_accrued_locl shares base_curcy_cd end_accrued_locl sec_typ1 sec_typ2 perf_curcy_cd price_curcy_cd]) (defn to-records [res] (apply #(PerfRecord. %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16 %17 %18 %19 %20 %21) res)) (defn get-data [] (sql/with-connection dbconn (sql/with-query-results res [query-str] (to-records res Is there a better way to write the to-records method? -- Shoeb -- You 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
strint and macro expansion
I have the following definitions and am trying to use the strint macro () to perform string substitutions. test1=(use 'clojure.contrib.strint) test1= (def m {:XYZ 1, :ABC 2}) test1= (def q select ~(:XYZ m) from ~(:ABC m)) The following works when I specify my string directly: test1= ( select ~(:XYZ m) from ~(:ABC m)) select 1 from 2 But doesn't work when I pass the string through a variable: test1= ( (str q)) select ~(:XYZ m) from ~(:ABC m) Thanks for your help. -- Shoeb -- You 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: strint and macro expansion
Is clojureql powerful and flexible enough to support custom dynamic SQL with tons of joins, database function invocations in the SELECT clause, sub-selects, unions, etc.? Most of our applications are written in Java and we have been doing parameter substitution sometimes using string variables in the query and other times using prepared statements (using open source or home grown database access frameworks). Parameter bindings are retrieved from hash maps or object properties and SQL is generated on the fly. I don't see how else to do this. Also our SQLs are complex and often need tuning and optimization. Can clojureql help with this? -Original Message- From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of Alan Sent: Thursday, March 17, 2011 1:12 PM To: Clojure Subject: Re: strint and macro expansion On Mar 17, 8:34 am, Bhinderwala, Shoeb sabhinderw...@wellington.com wrote: ...use the strint *MACRO*... ...works when I specify my string [as a literal]... ...but doesn't work when I pass the string through a variable. Macros are not functions. is receiving as arguments a list with the two elements 'str and 'q. It must operate on them at compile time, before q has been given a run-time value: it cannot know what the value of q is. From my uninformed position, strint looks like it should have been written as a function, not a macro, but probably there are reasons it was not. As an aside: it is sheer folly to interpolate strings for use in SQL queries. Do not do it; it will end in tears. PHP makes it easy, which is why there are so many SQL injection issues in PHP-powered sites. Be happy that this did not work: it has provided the mailing list with an opportunity to steer you towards clojureql. -- You 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