RE: Repeating a vector n times

2011-07-13 Thread Bhinderwala, Shoeb
11 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 wrote: I have to write a function that will take a vector as input,

Repeating a vector n times

2011-07-13 Thread Bhinderwala, Shoeb
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

RE: Data filtering function

2011-07-05 Thread Bhinderwala, Shoeb
PM To: Clojure Subject: Re: Data filtering function (map #(get % ["45"]) d) On Jul 5, 12:49 pm, "Bhinderwala, Shoeb" wrote: > I need help to write a small filtering function. Given the following > definitions: > > (def m1 >        {["45"] {:a 45 :b "d

Data filtering function

2011-07-05 Thread Bhinderwala, Shoeb
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

RE: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Bhinderwala, Shoeb
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.

RE: Translating Java code with nested for loops

2011-06-29 Thread Bhinderwala, Shoeb
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- F

RE: Translating Java code with nested for loops

2011-06-29 Thread Bhinderwala, Shoeb
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. -

Translating Java code with nested for loops

2011-06-28 Thread Bhinderwala, Shoeb
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 i

RE: BigDecimal Division - Arithmetic Exception

2011-06-17 Thread Bhinderwala, Shoeb
:51 PM, Bhinderwala, Shoeb 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 t

BigDecimal Division - Arithmetic Exception

2011-06-17 Thread Bhinderwala, Shoeb
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 da

RE: Vim Nailgun setup - access to REPL from outside Vim

2011-06-14 Thread Bhinderwala, Shoeb
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 se

RE: Recursive var definition

2011-06-13 Thread Bhinderwala, Shoeb
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.c

RE: New to Clojure

2011-06-09 Thread Bhinderwala, Shoeb
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 b

RE: Radically simplified Emacs and SLIME setup

2011-06-09 Thread Bhinderwala, Shoeb
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-jac

RE: Emacs - marmalade package install and .emacs file entries

2011-06-06 Thread Bhinderwala, Shoeb
ject: Re: Emacs - marmalade package install and .emacs file entries On Jun 6, 8:39 am, "Bhinderwala, Shoeb" 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 m

RE: Emacs - marmalade package install and .emacs file entries

2011-06-06 Thread Bhinderwala, 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" wrote: >   (add-to-lis

RE: swank-clojure/lein/emacs

2011-06-06 Thread Bhinderwala, Shoeb
ure? 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" wrote: > I inst

Emacs - marmalade package install and .emacs file entries

2011-06-06 Thread Bhinderwala, Shoeb
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 ent

RE: swank-clojure/lein/emacs

2011-06-05 Thread Bhinderwala, Shoeb
@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

RE: swank-clojure/lein/emacs

2011-06-05 Thread Bhinderwala, Shoeb
l 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,

swank-clojure/lein/emacs

2011-06-05 Thread Bhinderwala, Shoeb
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 fil

RE: Clojurebox/emacs setup

2011-06-03 Thread Bhinderwala, Shoeb
uot;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,

Clojurebox/emacs setup

2011-06-03 Thread Bhinderwala, Shoeb
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 pat

RE: Jark 0.3 (using the nrepl protocol)

2011-05-06 Thread Bhinderwala, Shoeb
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

Optimizing my function for performance

2011-05-03 Thread Bhinderwala, Shoeb
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

RE: RE: Multi-level bucketing problem

2011-05-03 Thread Bhinderwala, Shoeb
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 buc

RE: Multi-level bucketing problem

2011-05-02 Thread Bhinderwala, Shoeb
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 vers

Multi-level bucketing problem

2011-05-01 Thread Bhinderwala, Shoeb
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" ["US

RE: Merging two maps based on ids

2011-05-01 Thread Bhinderwala, Shoeb
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" w

RE: Merging two maps based on ids

2011-04-26 Thread Bhinderwala, Shoeb
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

Merging two maps based on ids

2011-04-25 Thread Bhinderwala, Shoeb
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

RE: Why I'm getting an empty result?

2011-04-21 Thread Bhinderwala, Shoeb
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 ob

RE: Help with function to partition my data

2011-04-18 Thread Bhinderwala, Shoeb
(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

RE: Help with function to partition my data

2011-04-17 Thread Bhinderwala, Shoeb
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 :

Adding key values in a list of maps

2011-04-14 Thread Bhinderwala, Shoeb
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

RE: Creating defrecords from results of a sql query

2011-04-13 Thread Bhinderwala, Shoeb
[mailto:clojure@googlegroups.com] On Behalf Of David Nolen Sent: Wednesday, April 13, 2011 4:01 PM To: clojure@googlegroups.com Subject: Re: Creating defrecords from results of a sql query On Wed, Apr 13, 2011 at 3:43 PM, Bhinderwala, Shoeb wrote: I am considering moving the results of with

Creating defrecords from results of a sql query

2011-04-13 Thread Bhinderwala, Shoeb
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

RE: strint and macro expansion

2011-03-17 Thread Bhinderwala, Shoeb
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, "Bhinderw

strint and macro expansion

2011-03-17 Thread Bhinderwala, Shoeb
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=> (<<