Re: Joy of Clojure question

2014-05-13 Thread Guru Devanla
The call to (index) returns this vector ([0 \:] [1 \a] [2 \space] [3 \4] [4 \space] [5 \:] [6 \b] [7 \space] [8 \1] [9 \space] [10 \:] [11 \c] [12 \space] [13 \3] [14 \space] [15 \:] [16 \d] [17 \space] [18 \4]) And, 3 here is in the 13th position. Your (cond) in index function is picking up the

Re: Cleaner solution, anyone?

2014-05-01 Thread Guru Devanla
Reduce is not lazy, correct? Will it ever return for drop-while to execute. The problem here is not knowing how many iterations make up the sum, isnt? On Thu, May 1, 2014 at 1:13 PM, James Reeves wrote: > I'd suggest generating an intermediate seq with the summed time: > > (defn state [time] >

Re: Cleaner solution, anyone?

2014-05-01 Thread Guru Devanla
Neat, so in your last solution are you trying to get rid of recur and solve 1 - (1/2)^x = ? On Thu, May 1, 2014 at 12:06 PM, Divyansh Prakash < divyanshprakas...@gmail.com> wrote: > Hey! > I wrote a blog post discussing Thomson's Paradox, and simulated it in > Clojure- > http://pizzaforthou

Re: Clojure cons vs. conj

2014-04-24 Thread Guru Devanla
Another option is to explore "concat" On Thu, Apr 24, 2014 at 8:46 AM, Jiacai Liu wrote: > Well,I understand you. > list only support front insert since it only takes O(1). > If insert in the back,it would require O(n) time. > Maybe clojure has its own reasons for having both cons and conj. > T

Re: What's clojure killer app? I don't see any.

2014-04-19 Thread Guru Devanla
One point that makes me wonder is this: One of the points touted a lot is the availability of immense ecosystem of Java. How does one balance switching between immutable and mutable objects once Java objects are brought into the mix. I have never used Java and Clojure together yet since this questi

Re: is there a way I can learn clojure with a lot of exercises

2014-04-16 Thread Guru Devanla
I would suggest 4clojure.com for the following reasons: 1. Problems are tuned towards learning idioms of Clojure 2. In many cases problems are tuned towards making you thinking functionally. 3. Once you solve the problem, you get to compare it with some of the other submitters. This point is cruci

Re: Good learning resources for Clojure novice but with a long background i programming, both OO and some Fp?

2014-01-11 Thread Guru Devanla
wrote: > On Jan 11, 2014, at 10:05 AM, Guru Devanla wrote: > > Sorry, I mixed up. I meant the second book to be 'Clojure in Action' : > http://manning.com/rathore/ > > > That book was already outdated when it was released (and many of the > examples won't w

Re: Good learning resources for Clojure novice but with a long background i programming, both OO and some Fp?

2014-01-11 Thread Guru Devanla
Sorry, I mixed up. I meant the second book to be 'Clojure in Action' : http://manning.com/rathore/ On Fri, Jan 10, 2014 at 4:26 PM, Sean Corfield wrote: > On Jan 10, 2014, at 11:26 AM, Guru Devanla wrote: > > Another good book I thought you could get through faster in 

Re: Good learning resources for Clojure novice but with a long background i programming, both OO and some Fp?

2014-01-10 Thread Guru Devanla
IMO there are 2 aspects of learning Clojure coming from an imperative and/or OO background. One s the functional aspect of it and other the idioms and the language itself. To learn the language a book like 'Clojure Programming' would be a good start as others have suggested. It will help you quick

Re: How can I improve this?

2014-01-10 Thread Guru Devanla
Actually, you might have meant line 267? On Fri, Jan 10, 2014 at 11:03 AM, Sean Corfield wrote: > java.jdbc does this for column names (in joins): > > > https://github.com/clojure/java.jdbc/blob/master/src/main/clojure/clojure/java/jdbc.clj#L257 > > Sean > > On Jan 10, 2014, at 6:59 AM, Colin Y

Re: How can I improve this?

2014-01-10 Thread Guru Devanla
But, for the given problem this may not be directly helpful. This method only returns the next unique name for the given list. The logic would have to traverse the list n times for n elements (and some factor of no of duplicates) to get the desired result, correct? Thanks Guru On Fri, Jan 10, 20

Re: How can I improve this?

2014-01-10 Thread Guru Devanla
Ok. My bad. Should not be reading and responding to such posts from the phone. Somehow, I overlooked that part of the mail. I think as Alex stated, a simple way of holding on to seen objects in the set and reducing the list should be good. On Fri, Jan 10, 2014 at 7:14 AM, Colin Yates wrote: > T

Re: How can I improve this?

2014-01-10 Thread Guru Devanla
Hi Colin, Clojure has a distinct function that does this. I may be missing some context on what you what out of your new method that 'distinct' does not provide. The distinct functions source code is a good reference. Thanks On Fri, Jan 10, 2014 at 6:59 AM, Colin Yates wrote: > I have a seque

Re: In your opinion, what's the best, and what's the worst aspects of using Clojure?

2013-12-27 Thread Guru Devanla
Ok, wanted to be clear that I do support the Best part of language so far has been the Language itself and community! On Fri, Dec 27, 2013 at 5:48 PM, Guru Devanla wrote: > Seconded on Error reporting. > > I have been playing around with Clojure for sometime now and also > complete

Re: In your opinion, what's the best, and what's the worst aspects of using Clojure?

2013-12-27 Thread Guru Devanla
Seconded on Error reporting. I have been playing around with Clojure for sometime now and also completed almost 150 of the 4clojure problems. What still scars me in terms of incorporating Clojure as a language of choice in more complicated projects I work on in my other life, is the error reportin

Re: Is Clojure more functional then Scala?

2013-12-16 Thread Guru Devanla
Hi Mark, A few questions: 1. The point you raise regarding declaring case classes is inherent to the typed nature of Scala, correct? Can that be pointed to as valid strength of Clojure. Since, we are comparing static vs dynamic typing here. 2. I am not super familiar with Scale, but I am assumin

Re: Help with Reduce

2013-12-09 Thread Guru Devanla
Hi Dave, I tried running your code. I did see a function being returned in both cases. Am I doing something different? Thanks Guru On Mon, Dec 9, 2013 at 12:09 PM, David Simmons wrote: > Hi > > I have the following function: > > (defn group > [& validators] > (fn [m] > (reduce (fn [map

Re: How would I do this in Clojure?

2013-12-05 Thread Guru Devanla
Would this work? (defn blah [coll] (lazy-seq (when-let [s (seq coll)] (cons (first s) (blah (rest s )) You can look up: http://clojure.org/lazy Thanks Guru On Thu, Dec 5, 2013 at 10:46 AM, David Simmons wrote: > Hi > > I'd like to be able to define a function that is

Re: quick macro review

2013-11-29 Thread Guru Devanla
I like the way you use (partial list 'var). On Thu, Nov 28, 2013 at 5:22 PM, juan.facorro wrote: > Hi Curtis, > > The *apply* is unnecessary if you use *unquote-splice* (*~@*), also > instead of the *into* and *for* usage you could just *map* over the list > of symbols. > > Here's how I would do

Re: Access the datastructure used to create a function?

2013-11-26 Thread Guru Devanla
The important caveat here is "what do we label as data?". If we are okay with just 'streams of bytes' that will make us understand and reason some information about the function, then may be the bytecode itself could be sufficient and could be considered to be data. But, I guess the original quest

Re: Access the datastructure used to create a function?

2013-11-26 Thread Guru Devanla
Hi Jamie, Thats interesting. How do I not let the compiler not optimize away the fact that y refers to the constant. When I run your program I have two constant fields defined rather than 'y. Am I missing something. Thanks Guru On Tue, Nov 26, 2013 at 6:16 AM, Jamie Brandon wrote: > > (def f

Re: Access the datastructure used to create a function?

2013-11-26 Thread Guru Devanla
Hi, This may not be the answer you are looking for. But, kooking at the example you gave, you will need to execution environment of the function to determine the binding of y. It could vary based on where it is invoked. That is because, if the function call was wrapped inside a 'binding form then

Re: expand a form

2013-11-25 Thread Guru Devanla
Hi Andy, Not sure what you need in terms of function calls being expanded. Can you provide an example. Here is an silly example, even though this kind of macro is not needed: (def addone [v] (+ v 1) (defmacro testmacro [init] (list 'addone init)) (macroexpand '(testmacro 10)) expands t

Re: expand a form

2013-11-25 Thread Guru Devanla
Hi Andy, Doesn't macroexpand do what you are looking for? Thx On Mon, Nov 25, 2013 at 4:55 AM, Andy Smith wrote: > Hi, > > I am new to clojure and I was wondering if there is a macro I can use to > fully expand all symbols and macros in a form, without performing the final > evaluation of the

Re: is PG's "imperative outside-in" advice any good?

2013-10-15 Thread Guru Devanla
Sean, The case you listed is where let binding becomes important so as to not perform duplicate evaluation. That is one place the utility of let stands out along with its scope. For example Without let bindings: (if (p (some-expression)) (f (some-expression)) (g (some-expression)) in