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 :else branch.


On Tue, May 13, 2014 at 6:44 PM, gamma235 jesus.diama...@gmail.com wrote:

 I am reading The Joy of Clojure now and am finishing chapter 5 on sequence
 abstractions. There is an example given that demonstrates how to locate the
 index of an element in a sequence by value, but I don't understand why the
 character lookup here is returning 13. Can somebody please explain this to
 me?

 (defn index [coll]
   (cond
(map? coll) (seq coll)
(set? coll) (map vector coll coll)
:else (map vector (iterate inc 0) coll)))

 (defn pos [pred coll]
   (for [[i v] (index coll) :when (pred v)] i))



 (pos \3 :a 4 :b 1 :c 3 :d 4)



 = 13


 J

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 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 = time ?


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://pizzaforthought.blogspot.in/2014/05/and-infinity-beyond.html

 The *state* function defined towards the end is not very functional.
 Could someone guide me towards a cleaner approach?

 Also, I can't find good code-highlighting tools for blogger/clojure. Any
 suggestions?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 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 ja...@booleanknot.com wrote:

 I'd suggest generating an intermediate seq with the summed time:

 (defn state [time]
   (- (thomsons-lamp)
(reduce (fn [[_ t] [onoff dur]] [onoff (+ t dur)]))
(drop-while (fn [[_ t]] ( t time)))
first second))

 - James



 On 1 May 2014 20:06, Divyansh Prakash divyanshprakas...@gmail.com wrote:

 Hey!
 I wrote a blog post discussing Thomson's Paradox, and simulated it in
 Clojure-
 http://pizzaforthought.blogspot.in/2014/05/and-infinity-beyond.html

 The *state* function defined towards the end is not very functional.
 Could someone guide me towards a cleaner approach?

 Also, I can't find good code-highlighting tools for blogger/clojure. Any
 suggestions?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 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 jiacai2...@gmail.com 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.
 Thank again for telling me their differences.


 On Thursday, April 24, 2014 11:36:13 PM UTC+8, Gary Trakhman wrote:

 Well, maybe I shouldn't bash MIT-scheme unintentionally :-).  I bet some
 people use it for serious stuff, and I have no bad experiences with it.


 On Thu, Apr 24, 2014 at 11:33 AM, Gary Trakhman gary.t...@gmail.comwrote:

 MIT-lisp is more for teaching than industrial use..

 We also have hash-maps, vectors, sets, queues, conj works with all of
 them, leaving the details up to the collection.

 Cons always adds to the front.  Conj only adds to the back for certain
 collections (vector, queue).

 You could work around it by reversing, consing, then reversing again, or
 just use vectors and conj if you're always working on the tail.


 On Thu, Apr 24, 2014 at 11:27 AM, Jiacai Liu jiaca...@gmail.com wrote:

 Oh,Thank you for answer.
 But if I just want to insert a element to list,and meantime want to
 insert in the back.How should I do?
 Another question: why clojure need both cons and conj? In mit-lisp cons
 just do all things.


 On Thursday, April 24, 2014 11:12:49 PM UTC+8, Gary Trakhman wrote:

 Conj is polymorphic on its first argument. If you pass it a vector,
 it'll add to the back, if a list, the front.  The collection is 
 responsible
 for deciding the most efficient way to add an element.

 Cons always adds to the front, creating a linked-list node pointing to
 the rest.  Also, cons takes the sequence as the second argument.


 On Thu, Apr 24, 2014 at 11:10 AM, Jiacai Liu jiaca...@gmail.comwrote:

 hi everyone:
 I use Clojure to solve SICP 2.22 
 http://www.billthelizard.com/2011/01/sicp-221-223-mapping-over-lists.html
 .
 The problem is to rewrite a map fn in a iterative way,here it want to
 get the square of each element in a list
 Method 1:
 (defn square-list [items]
   (defn iter [things answer]
 (if (empty? things)
   answer
   (iter
 (rest things)
 (cons (square (first things)) answer
   (iter items nil))
 This method just return opposite result.
 (square-list (range 1 10))
 ;===(81 64 49 36 25 16 9 4 1)

 I think all I need is to swap the position of (square (first 
 things))andanswer,then
 I can get the right order
 I write fn below:
 Method 2
 (defn square-list [items]
   (defn iter [things answer]
 (if (empty? things)
   answer
   (iter
 (rest things)
 (conj answer (square (first things))
   (iter items nil))
 However, it still return opposite order.
 Did I misuse cons and conj or I ignore something?


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@googlegroups.com

 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it,
 send an email to clojure+u...@googlegroups.com.

 For more options, visit https://groups.google.com/d/optout.


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.



  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to 

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 question has always bothered me. I tend to think that this mix would
negate a lot of strength Clojure would give me, barring the functional
style of programming I get to use along with Java objects.

I would also love to see some good example of such a mix and if there are
any guidelines on how to use them seamlessly without doing the guess work
of dealing with a mix of immutable and mutable objects.

Thanks


On Sat, Apr 19, 2014 at 11:03 AM, Max Penet m...@qbits.cc wrote:

 Hi,

 And there's Storm that could be worth mentioning... used by some (very)
 large companies (twitter ,groupon, etc...) and a success story. Also
 prismatic is a good example, and I could mention more companies/products,
 some that were acquired by big players, others used by millions, netflix
 comes to mind.

 About data access we have clients/drivers for any datastore you can think
 of, and there are tons of excellent web related libs both on front/back-end
 sides. I am not sure a huge monolithic monster ala rails is something to
 desire really.

 Depending on what you do, clojure can be a very good choice for a
 company/product.
 We use it as our main backend techno were I work, and we dont' regret that
 choice, kind of the opposite. Having access to the immense java ecosystem
 paired with the versatility that clojure gives us (+ its ecosystem) is a
 big win.


 On Saturday, April 19, 2014 7:27:35 PM UTC+2, Andrey Antukh wrote:

 Hi Paulo.

 2014-04-19 18:15 GMT+02:00 Paulo Suzart paulo...@gmail.com:

 Hi all, (warning, this is kinda confusing email)

 Been following the list for some time and specially paying attention to
 what could be the killer clojure app as Akka is for Scala.

  I keep seeing small libs (I like libs) popping up like ants, but I
 don't believe none of them (alone at least)  can make clojure explode and
 become main technology in a old school /ordinary company.

 People say clojure is good for data. But where are the cases? And more
 specifically, where are the frameworks and libs to support it? Are they
 talking about wrappers around java for Hadoop? Sigh...

 Pulsar is quite dead, core async isn't clear regarding remoting, and
 avout? And lamina? And aleph? Where are the tools that can make clojure to
 cover from Web to big data and batch?

 Pulsar is dead? Really? https://github.com/puniverse/pulsar/commit/
 1bb398cff65017c79d04bedd26915bca03a77521 24 days ago the last commit
 preparing new release. I follow the development of pulsar and quasar and it
 not seems dead.

 distributed/remote communication is not target of CSP and core.async but
 can be implemented without much problems over any existing transport
 protocols: http://niwibe.github.io/jnanomsg/#_async_support (example
 implementing clojure channels over nanomsg)

  Luminous,  caribou, etc, are they going to become the next grails?
 Huumm.. Will take lot of time. Clojure Script alone will not go any further
 than the current server side.

 What made me give up scala was Scalaz, and I hope the create thousand
 disconnected libs and publish a post with ANN sufix approach doesn't make
 me give up clojure.

 Creating one unique library that includes and integrates everything is
 really a solution? I believe not.

  Sorry guys, I've been posting about Clojure since 2009, and still
 can't see it becoming the main technology even being the CTO of the
 company.

 What is the killer app for you? Or how do you think we can make clojure
 supporting apps like Facebook or something big like that?

 In summary: erlang/elixir has actors, scala has actors (and very slow
 compiller...), prolog has logic programming, go has csp and clojure has all
 them. Really you need a killer app?

 Sorry I don't understand the motivation of this email :(

 Andrey

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@googlegroups.com

 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.

 For more options, visit https://groups.google.com/d/optout.




 --
 Andrey Antukh - Андрей Антух - andrei@kaleidos.net / ni...@niwi.be
 
 http://www.niwi.be http://www.niwi.be/page/about/
 https://github.com/niwibe

  --
 You received this message because you are subscribed to the Google
 Groups Clojure 

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 crucial, since this will help you appreciate how
some of the solutions submitted by other members can be so small and
elegant. For me learning from the submitted code of other and comparing the
though process I went through in coming up with my solution was a big take
away.
4. It feels good to be on the first page of top users page, once you solved
the 150 odd problems.

Cons:

1. A solution to almost all 4Clojure problems is just a google search away.
So, stay away from the temptation to look for the answers. You will be
surprised with how different your solution would have looked.

For further proof, I noticed many of the problems on this site are inspired
by this list:

http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html

So good luck!

Guru






On Wed, Apr 16, 2014 at 8:19 AM, Roelof Wobben rwob...@hotmail.com wrote:



 Op woensdag 16 april 2014 16:43:09 UTC+2 schreef Charlie Griefer:


 On Apr 15, 2014, at 11:56 PM, Roelof Wobben rwo...@hotmail.com wrote:

 I like to try clojure.
 I have little or none programming background but I know I learn the best
 by reading a piece of text
 and then do exercises about it so I can check if I really understand it.

 What is then the best way to proceed ?


 I know you said that you want to do exercises, but I have to second the
 recommendations for Clojure for the Brave and True. Great introduction for
 somebody who has little to no programming background. http://www.
 braveclojure.com/

 Also as others have said, 4Clojure is exactly what you're asking for
 (exercises). But I'd start off with Clojure for the Brave and True, and as
 concepts start to click (or maybe even just before that), start working
 some of the 4Clojure exercises.

 --
 Charlie Griefer
 http://charlie.griefer.comhttp://charlie.griefer.com

 Give light, and the darkness will disappear of itself.
 -- Desiderius Erasmus



 Thanks,

 What I do now is read the braveclojure book and do the exercises from
 http://iloveponies.github.io/120-hour-epic-sax-marathon/index.html

 So I read a lot and I can see how things work.

 Roelof

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 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 s...@corfield.org wrote:

 On Jan 10, 2014, at 11:26 AM, Guru Devanla grd...@gmail.com wrote:

 Another good book I thought you could get through faster in 'Pragmatic
 Clojure'.I found this book to be the next level to Clojure Programming.


 Do you mean Programming Clojure (2nd Ed) by Stuart Halloway?

 http://pragprog.com/book/shcloj2/programming-clojure

 Sean Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)





-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


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

2014-01-11 Thread Guru Devanla
Sure that could be the case. But I found the coverage interesting and quite
different from the other books. There was also some good tips for using
Clojure in the real world. That said, may be its still worth a wait for
next version.

Thanks
Guru


On Sat, Jan 11, 2014 at 1:51 PM, Sean Corfield s...@corfield.org wrote:

 On Jan 11, 2014, at 10:05 AM, Guru Devanla grd...@gmail.com 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 work properly now).

 There's a second edition coming: http://manning.com/rathore2/

 Sean Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)





-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 colin.ya...@gmail.com wrote:

 I have a sequence of file names and I want to make them unique.  (uniquify
 [a b c a]) = [a b c a_1])

 This is what I have come up with, but surely there is a better way?

 What would you all do?  Feedback welcome (including the word 'muppet' as I
 am sure I have missed something simple) :)

 (defn uniquify
   Return a sequence, in the same order as s containing every element
   of s. If s (which is presumed to be a string) occurs more than once
   then every subsequent occurrence will be made unique.

   Items will be updated to include an incrementing numeric count using
   the specified formatter function. The formatter function will be
   given the name and the number and should return a combination of the
   two.

   The set of unique s's in the returned sequence will be the count of
   s's in s.
   ([s] (uniquify s (fn [item duplicates] (str item _ duplicates
   ([s formatter]
  (let [occurrences (atom {})
register-occurrence (fn [item]
  (if (get @occurrences item)
(swap! (get @occurrences item) inc)
(swap! occurrences assoc item (atom 1)))
  @(get @occurrences item))
process (fn [item]
  (let [duplicates (dec (register-occurrence item))]
(if ( duplicates 0)
  (formatter item duplicates)
  item)))
unique-s (map process s)]
unique-s)))

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 colin.ya...@gmail.com wrote:

 The missing context is that distinct removes duplicates, I want duplicates
 to be made unique by changing them in some way: (uniquify [a b c
 a]) = [a b c a_1]) *not* (uniquify [a b c a]) = [a
 b c])

 Not sure what else to put that isn't in the original post to be honest...

 --
 Date: Fri, 10 Jan 2014 07:10:22 -0800
 Subject: Re: How can I improve this?
 From: grd...@gmail.com
 To: clojure@googlegroups.com


 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 colin.ya...@gmail.comwrote:

 I have a sequence of file names and I want to make them unique.  (uniquify
 [a b c a]) = [a b c a_1])

 This is what I have come up with, but surely there is a better way?

 What would you all do?  Feedback welcome (including the word 'muppet' as I
 am sure I have missed something simple) :)

 (defn uniquify
   Return a sequence, in the same order as s containing every element
   of s. If s (which is presumed to be a string) occurs more than once
   then every subsequent occurrence will be made unique.

   Items will be updated to include an incrementing numeric count using
   the specified formatter function. The formatter function will be
   given the name and the number and should return a combination of the
   two.

   The set of unique s's in the returned sequence will be the count of
   s's in s.
   ([s] (uniquify s (fn [item duplicates] (str item _ duplicates
   ([s formatter]
  (let [occurrences (atom {})
register-occurrence (fn [item]
  (if (get @occurrences item)
(swap! (get @occurrences item) inc)
(swap! occurrences assoc item (atom 1)))
  @(get @occurrences item))
process (fn [item]
  (let [duplicates (dec (register-occurrence item))]
(if ( duplicates 0)
  (formatter item duplicates)
  item)))
unique-s (map process s)]
unique-s)))

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.



 --
 --
 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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/rt-l_X3gK-I/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 clojure+unsubscr...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to 

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, 2014 at 11:03 AM, Sean Corfield s...@corfield.org 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 Yates colin.ya...@gmail.com wrote:

 I have a sequence of file names and I want to make them unique.  (uniquify
 [a b c a]) = [a b c a_1])

 This is what I have come up with, but surely there is a better way?

 What would you all do?  Feedback welcome (including the word 'muppet' as I
 am sure I have missed something simple) :)




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 s...@corfield.org 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 Yates colin.ya...@gmail.com wrote:

 I have a sequence of file names and I want to make them unique.  (uniquify
 [a b c a]) = [a b c a_1])

 This is what I have come up with, but surely there is a better way?

 What would you all do?  Feedback welcome (including the word 'muppet' as I
 am sure I have missed something simple) :)




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 quickly get into building some stuff right away. Another good book I
thought you could get through faster in 'Pragmatic Clojure'.I found this
book to be the next level to Clojure Programming.

But, it will take more time and practice (along with pure joy!) to
internalize the functional way of doing things.  For the functional
exercise, even one other book I thought is useful are smaller and simpler
books like Little Schemer etc, though you will have to spend time
understand the syntax of yet another FP language. But again, you could put
your experience of F# to good use here.

Thanks


On Fri, Jan 10, 2014 at 11:25 AM, Andrey Antukh n...@niwi.be wrote:

 +1 for Clojure Programming of Oreilly


 2014/1/10 Curtis Gagliardi gagliardi.cur...@gmail.com

 I really think Clojure Programming is the best Clojure book out there.
  If you read that thing most (or all) of the way through, you'll have a
 very solid understanding of Clojure.


 On Friday, January 10, 2014 4:52:53 AM UTC-8, christian jacobsen wrote:

 I have +10 years experience of OO programming (C++, C# and a little
 Java) and a couple of years of FP programming (mainly F#, some Scala and a
 little Haskell).
 Are there any resources for learning Clojure that are particular good
 for someone with the above background?

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




 --
 Andrey Antukh - Андрей Антух - andrei.anto...@kaleidos.net / 
 n...@niwi.be
 http://www.niwi.be http://www.niwi.be/page/about/
 https://github.com/niwibe

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 reporting facility. The errors
sometimes might as well just say 'I just cannot run!'.  It would be nice if
there was some facility to approximately point to some s-exp or line
numbers.

May be I am missing some workflow used by other expert users. Can someone
throw more light on this.


Thanks
Guru


On Fri, Dec 27, 2013 at 3:44 PM, Daniel doubleagen...@gmail.com wrote:

 Best: Language  Community
 Worst: Error Reporting


 On Friday, December 27, 2013 3:17:48 PM UTC-6, Kelker Ryan wrote:

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

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 grd...@gmail.com wrote:

 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 reporting facility. The
 errors sometimes might as well just say 'I just cannot run!'.  It would be
 nice if there was some facility to approximately point to some s-exp or
 line numbers.

 May be I am missing some workflow used by other expert users. Can someone
 throw more light on this.


 Thanks
 Guru


 On Fri, Dec 27, 2013 at 3:44 PM, Daniel doubleagen...@gmail.com wrote:

 Best: Language  Community
 Worst: Error Reporting


 On Friday, December 27, 2013 3:17:48 PM UTC-6, Kelker Ryan wrote:

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

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 assuming Scala can do
similar to what we have in ML, which would look like this:

datatype rank = Jack | Queen | King | Ace | Num of int

Isn't a similar idiomatic case class sufficient to achieve the needed
simplicity in Scala?

3. Regarding walking down the path of multiple object hierarchies, I guess
that is only a choice in Scala and is not necessitated by idiomatic Scala.
So, can't one just use the functional construct to achieve what you define
in Clojure?

I believe Scala's blending of static typing with OO and FP principles is a
exciting area of research and only time will tell if we could have all the
features in one big language.  Scala's tries to be different language to
different people depending on which background one approaches from.

I also agree with one other member where it is stated that Scala is just
too complex and Clojure's wins by its simplicity and consistent
representation.

Thanks
Guru



On Mon, Dec 16, 2013 at 12:13 PM, Mark Engelberg
mark.engelb...@gmail.comwrote:

 I think you're right that all or nearly all of the functional aspects of
 Clojure have counterparts in Scala.  On top of that, Scala provides mutable
 flavors of everything, so you can pick and choose your approach.  So that
 makes Scala better, right?

 But the difference between Clojure and Scala is bigger than a
 feature-to-feature comparison -- they have very different philosophies, and
 programs developed in Clojure consequently have a very different feel to
 them than those developed in Scala.  I find Clojure programs to be
 dramatically simpler.

 Just as one example, consider modeling a deck of cards.  In Clojure, you'd
 be more likely to come up with a simple representation for a card, perhaps:
 [10 :spades].  Depending on the card game, you might choose to represent a
 face card as [:king :clubs] or [13 :clubs].  A deck would likely be modeled
 as just a sequence of cards, and all the built-in sequence functions would
 apply, for example, shuffle, take, drop, etc.  Serializing the data (for
 example, if you want to keep a database tracking all the shuffled decks
 you've ever used in a given game) comes for free.

 On the other hand, in Scala, you'd be more likely to create a card Class
 with a rank and suit field.  The Suit class would be comprised of four case
 classes, because the philosophy is to enumerate all the possible suits as
 separate entities -- there's nothing in Scala like Clojure's convenient
 keywords.  For the rank, you'd be steered towards representing all the
 ranks as integers.  The possibility of representing face cards with a name
 would likely never occur to you, because it would be too complicated to go
 through the effort of defining the type of a rank to be a integer or a
 class comprised of four case classes -- jack,queen,king,ace.  For modeling
 the deck, you probably wouldn't say a Deck is-a sequence, because
 composition is favored over inheritance.  So you'd probably have a Deck
 class which would *contain* a sequence of cards.  This means that you'd
 have to reimplement methods like shuffle, take, and drop on your Deck class
 to turn around and dispatch those methods to the underlying sequence of
 cards.  If you're not careful, years of object-oriented training might kick
 in and before you know it, you're representing the deck as a class where
 methods like shuffle, take, and drop *destructively update* the
 underlying sequence -- it feels so natural to do that once you've
 encapsulated the underlying sequence of cards in a class.  If you want to
 serialize a deck, that's more code to write (although general pickling of
 a Scala object is an *active area of research*).

 This example pretty much sums up what I prefer about Clojure.  I like to
 tell people that a big part of what makes Clojure special is its philosophy
 of *lightweight data modeling*.  It leads to delightfully simple
 systems.  Scala remains deeply rooted in the OO philosophy, which all too
 often leads to an over-engineered muddle.

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit 

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 shortlypor...@gmail.comwrote:

 Hi

 I have the following function:

 (defn group
   [ validators]
   (fn [m]
 (reduce (fn [maps f]
   (let [[m error-m] maps
 [new-map errors] (f m)]
   [new-map (vec (flatten (if errors (conj error-m errors)
 error-m)))]))

 [m []]
 validators
 )))

 The following call (def foo group) returns a function. All as I'd expect.
 I then thought I'd replace the anonymous function with a named function...

 (defn validate
   [maps f]
   (let [[m error-m] maps
 [new-map errors] (f m)]
 [new-map (vec (flatten (if errors (conj error-m errors) error-m)))]))


 (defn group2
   [ validators]
   (fn [m]
 (reduce validate
 [m []]
 validators
 )))
 The following call (def foo group2) returns an empty vector. I would have
 though it would have returned a function. Am I missing something?

 cheers

 Dave

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 shortlypor...@gmail.comwrote:

 Hi

 I'd like to be able to define a function that is passed a vector of items
 and returns a function such that each time the returned function is called
 it returns the next item in my-vector.

 For example

 (def blah (my-function [1 2 3])

 (blah) = 1
 (blah) = 2
 (blah) = 3

 Is this possible?

 cheers

 Dave

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 juan.faco...@gmail.comwrote:

 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 it:

 (defmacro migrate [ syms]
   `(migrate* ~@(map (partial list 'var) syms)))

 (macroexpand-1 '(migrate a b c))

 ;= (user/migrate* (var a) (var b) (var c))


 Hope it helps,

 Juan

 On Friday, November 29, 2013 5:26:14 AM UTC+8, Curtis Gagliardi wrote:

 I wrote a macro last night and got the feeling I did what I did in a
 suboptimal way.

 I have have a migration function that I stole from technomancy that takes
 in the vars of migration functions:
 (migrate #'create-db #'add-users-table #'etc)

 It uses the name of the var from the metadata to record which migrations
 have been run.  I wanted to try to make it so you didn't have to explicitly
 pass in the vars, and just have the migrate function call var for you.
 I've since decided this is a bad idea but I wrote the macro anyway just for
 fun.  My first question is: could this be done without a macro?  I didn't
 see how since if you write it as a function, all you recieve are the actual
 functions and not the vars, but I thought I'd ask to be sure.  Assuming you
 did have to write a macro, does this implementation seem reasonable?  I
 felt strange about using (into [] ...).

 https://www.refheap.com/21335

 Basically I'm trying to get from (migrate f g h) to (migrate* (var f)
 (var g) (var h)), I'm not sure I'm doing it right.

 Thanks,
 Curtis.

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 the value of y would be different. And, isn't this something that is
determined during execution of the function?

Example:

(def ^:dynamic y 10)

(defn testfn [x]
(+ x y))

(testfn 10)

== print 20

(binding [y 100]
 (testfn 10))

== prints 110.


So, unless you want to assume the free variables are always lexically
scoped, that value you may want to deref would vary.

Maybe you have a very specific scenario where you need to do what you want.
More details would help.

Thanks
Guru





On Tue, Nov 26, 2013 at 4:19 AM, henry w henryw...@gmail.com wrote:

 Sad not to get any replies - even to tell me if it is a bad idea or not
 possible. :-(

 Assuming it is not possible, am I right in saying that at the moment, in
 Clojure, 'code is data' really only applies until code is compiled?

 I realise compiled functions can still be passed around, assigned to vars
 and so on.


  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 ja...@scattered-thoughts.net
 wrote:

  (def f (let [y 1] (fn [x] (+ x y

 Let's have a look inside.

  (require '[no.disassemble :refer [disassemble]])
  (println (disassemble f))
 // Compiled from /home/jamie/strucjure/src/strucjure.clj (version 1.5
 : 49.0, super bit)
 public final class strucjure$fn__5589$fn__5590 extends
 clojure.lang.AFunction {

   // Field descriptor #7 Lclojure/lang/Var;
   public static final clojure.lang.Var const__0;

   // Field descriptor #25 Lclojure/lang/IPersistentMap;
   final clojure.lang.IPersistentMap __meta;

   // Field descriptor #27 J
   long y;
 

 So there is the field you want.

  (.y f)
 java.lang.IllegalArgumentException: No matching field found: y for
 class strucjure$eval5552$fn__5553 Reflector.java:271
 clojure.lang.Reflector.getInstanceField Reflector.java:300
 clojure.lang.Reflector.invokeNoArgInstanceMember
 /home/jamie/strucjure/src/strucjure.clj:21 strucjure/eval5556

 Humbug.

  (require '[clojure.reflect :refer [reflect]])
  (reflect f)
 java.lang.ClassNotFoundException: strucjure$eval5552$fn__5553

 Interesting... I would love to know why that is the case.

  (into [] (.. f getClass getDeclaredFields))

 [#Field public static final clojure.lang.Var
 strucjure$fn__5589$fn__5590.const__0 #Field final
 clojure.lang.IPersistentMap strucjure$fn__5589$fn__5590.__meta
 #Field long strucjure$fn__5589$fn__5590.y]

  (defn get-field [instance field-name]
   (let [field (first (filter #(= field-name (.getName %)) (.. instance
 getClass getDeclaredFields)))]
 (.setAccessible field true)
 (.get field instance)))
  (get-field f y)
 1

 Success! And just for fun:

  (def f2 (strucjure$fn__5589$fn__5590 7))
  (f2 1)
 8

 I hope that helps. Now the more interesting question is why you would
 want to do that...


 On 21 November 2013 18:14, henry w henryw...@gmail.com wrote:
  Say you have a function created like this:
 
  (fn [x] (+ x y))
 
  and then you have a reference to an instance of this function, is there
 some
  way to use the function reference to access the list '(fn [x] (+ x y)),
  including the symbol 'y' (such that you could dereference 'y' and get its
  value)? The source function is not the right thing and so far googling
  hasn't got me the answer.
 
  Thanks
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your
  first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google Groups
  Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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
question was regarding data that one could reason in the form on clojure
forms itself. At least, that is what I believe Henry was referring to,
isn't?

-Guru



On Tue, Nov 26, 2013 at 1:51 PM, henry w henryw...@gmail.com wrote:

 The thing is, the data contained in the source definition is all still
 there in the compiled version - but apparently it is not easily accessible.
 It feels like it must be possible to write a function that looks at a
 function object and it's class and can produce at least a decent
 approximation to the original, or at least a clojure list version of the
 compiled code. No doubt completely faithful recreation wouldn't be
 possible, not least because of macros.

 Also, sometimes, such as when developing possibly, it is not always
 necessary to have optimum performance.




 On Tuesday, November 26, 2013 8:30:38 PM UTC, Alex Miller wrote:

 Seems like you lost the clojure mailing list in this response, so I
 re-added it.

 On Tue, Nov 26, 2013 at 2:09 PM, henry w henr...@gmail.com wrote:

 Thanks to all respondents.

 This was really just something I was curious about, although I can think
 of some practical uses.

 It's just not clear to me still if there is some really good reason code
 stops being data (or at least having an accessible data representation)
 after it is compiled. Jamie has shown it is still data, although in a very
 platform-specific way. Is it just the case that there aren't compelling
 use-cases that people have come up with perhaps?


 Code stops being data so it can be a more efficient form to the host
 platform (bytecode), which is what makes Clojure perform well. If you
 always left the data in the original form, you would just need an
 interpreter (and Clojure would be much slower). Clojure is always compiled
 as performance is a key concern.


 Pratically, some examples of use might be related to the
 https://github.com/clojure/tools.trace library. Here vars are
 temporarily bound to functions that are wrapped versions of the functions
 they held previously in order to print input and output. A nice alternative
 would be to show the function form with the parameters interpolated.
 Another case might be to see not just the source of a function, but to
 'inline' the source of functions called from it. Or just generally mess
 about with functions I don't own.


 There has been a recent enhancement discussion (perhaps here, perhaps
 jira, can't find it now) to have functions retain their source definition
 at runtime. I'm not sure how that would be possible without significantly
 affecting performance and memory footprint however.





 On Tuesday, November 26, 2013 7:01:57 PM UTC, Alex Miller wrote:

 It would help to know what your real goal is, but compiled Clojure does
 not retain the original source form.

 One hook you do have though is macros which will be invoked prior to
 compilation. At macro execution time, you have access to the special form
 var which is the original form (as a Clojure data structure).

 Thus you could write a defn-like macro which when called to define a
 function definition would define the function and decorate it with meta
 that included the definition. I am a poor enough macrologist that I will
 not attempt that here but merely suggest it should be feasible. :)

 Alex

 On Thursday, November 21, 2013 12:14:39 PM UTC-6, henry w wrote:

 Say you have a function created like this:

 (fn [x] (+ x y))

 and then you have a reference to an instance of this function, is
 there some way to use the function reference to access the list '(fn [x] 
 (+
 x y)),
 including the symbol 'y' (such that you could dereference 'y' and get
 its value)? The source function is not the right thing and so far googling
 hasn't got me the answer.

 Thanks


  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
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 - 

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 the4thamig...@googlemail.comwrote:

 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 built in functions?

 Thanks

 Andy

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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 to

(addone 10)

Thanks
Guru


On Mon, Nov 25, 2013 at 6:32 AM, Andy Smith the4thamig...@googlemail.comwrote:

 It doesnt seem to expand function calls though right?


 On Monday, 25 November 2013 12:55:27 UTC, 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 built in functions?

 Thanks

 Andy

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: 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))

introduces duplicate evaluation.  I see the utility of let more in such
scenarios.  Whereas in the original PGs example that is not the case, and
debate on that stands.


On Tue, Oct 15, 2013 at 10:02 AM, Sean Corfield seancorfi...@gmail.comwrote:

 Yeah, I found when I first got started with Clojure I tended to use
 let for intermediate named results but over time I've moved to using
 small, private top-level functions instead because I want to focus on
 the names of the _functionality_ rather than the names of intermediate
 _data_. I still use let for some things but nowhere near as much as I
 used to.

 One construct using let that I see in my code quite a bit that I
 haven't figured out a cleaner way to express:

 (let [x (some-expression)]
   (if (p x)
 (f x)
 (g x)))

 I get tempted to write a utility function for it but I haven't come up
 with a good name for it :)

 Sean

 On Tue, Oct 15, 2013 at 9:00 AM, Alex Baranosky
 alexander.barano...@gmail.com wrote:
  I and some of my coworkers do tend to avoid `let` unless in this
 particular
  case you especially want to emphasize the name of something unobvious.
 OFten
  I'd prefer to pull out a new function over using let, or inline the
 binding
  for readability *improvement*.
 
 
  On Tue, Oct 15, 2013 at 8:18 AM, Raoul Duke rao...@gmail.com wrote:
 
  if a programming language doesn't have something like 'where', then i
  am sad. http://stackoverflow.com/questions/4362328/haskell-where-vs-let
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups
  Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send
 an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your
  first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google Groups
  Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.



 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.