Re: thinking in clojure

2010-09-17 Thread Michael Ossareh
On Fri, Sep 17, 2010 at 08:58, Michael Wood wrote: > On 17 September 2010 00:56, Michael Ossareh wrote: >> Meikel, >> >>>     (recur (cond (not (nil? (data key)))                (true? true) >>> >>> *ieeck* Please do (cond ... :else default-clause). Not true, or (true? >>> true) or othe

Re: thinking in clojure

2010-09-17 Thread Michael Wood
On 17 September 2010 00:56, Michael Ossareh wrote: > Meikel, > >> >>>     (recur (cond (not (nil? (data key))) >>>                (true? true) >> >> *ieeck* Please do (cond ... :else default-clause). Not true, or (true? >> true) or other stuff. > > Wow, I somehow missed the :else option in cond? I

Re: thinking in clojure

2010-09-17 Thread Michael Ossareh
Meikel, > >>     (recur (cond (not (nil? (data key))) >>                (true? true) > > *ieeck* Please do (cond ... :else default-clause). Not true, or (true? > true) or other stuff. Wow, I somehow missed the :else option in cond? I've got that (true? true) stuff scattered all over my code - goi

Re: thinking in clojure

2010-09-17 Thread Michael Ossareh
>> (loop [data (sorted-map) >>          collection newData >>          meeting (first collection)] >> >>   (def key ( )) > > As a general rule, def should only be used at the top level. You > probably want (let [key ...] (if ...) here. Hey, thanks for pointing this out - I was actually just t

Re: thinking in clojure

2010-09-17 Thread Michael Ossareh
On Thu, Sep 16, 2010 at 07:53, Laurent PETIT wrote: > 2010/9/16 Meikel Brandmeyer >> >> Hi Laurent, >> >> On 16 Sep., 15:54, Laurent PETIT wrote: >> >> > you don't like my one-liner ? :-) >> >> I saw your message only after I sent mine. :) >> >> > (update-in coll [k] (fnil update-in *default-val

Re: thinking in clojure

2010-09-16 Thread Btsai
That pattern will be a great addition to the toolbox, thank you :) On Sep 16, 9:58 am, Laurent PETIT wrote: > And note that the pattern works at any level, and is easily readable, since > update-in "flattens" the arguments of the modifying function : > > If you want to "touch" the path [:a :b :c

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
And note that the pattern works at any level, and is easily readable, since update-in "flattens" the arguments of the modifying function : If you want to "touch" the path [:a :b :c :d] and provide specific default values at each level if the key is not found, it's as "simple" as : (update-in coll

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
So nested calls to update-in are needed in order to be able to provide a specific default value, everytime just having an empty map created isn't sufficient. So instead of (update-in {} [:a :b] identity) which returns {:a {:b nil}} , you can break the key path at :a so that the default value if no

Re: thinking in clojure

2010-09-16 Thread Btsai
My poor brain can't handle nested calls to update-in, so this is what I came up with: (defn add-meetings [data k meetings] (cond (nil? (data k)) (assoc data k {:title "title" :meetings meetings}) :else (update-in data [k :meetings] concat meetings))) On Sep 16, 8:53 am, Laurent PETIT wro

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
2010/9/16 Meikel Brandmeyer > Hi Laurent, > > On 16 Sep., 15:54, Laurent PETIT wrote: > > > you don't like my one-liner ? :-) > > I saw your message only after I sent mine. :) > > > (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp > vec > > concat) data) > > Hmm... (comp ve

Re: thinking in clojure

2010-09-16 Thread Meikel Brandmeyer
Hi Laurent, On 16 Sep., 15:54, Laurent PETIT wrote: > you don't like my one-liner ? :-) I saw your message only after I sent mine. :) > (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp vec > concat) data) Hmm... (comp vec concat) == into? Meikel -- You received this m

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
Hi Meikel, you don't like my one-liner ? :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp vec concat) data) 2010/9/16 Meikel Brandmeyer > Hi, > > On 16 Sep., 15:36, Meikel Brandmeyer wrote: > > > > (if (not (nil? (next collection) > > > > You can save the nil?. (if

Re: thinking in clojure

2010-09-16 Thread Meikel Brandmeyer
Hi, On 16 Sep., 15:36, Meikel Brandmeyer wrote: > >   (if (not (nil? (next collection) > > You can save the nil?. (if (not (next collection))) will also work. > nil is logically false. And of course this should be (if (next collection)). The not belongs to the "You can save" part. Sincerely Me

Re: thinking in clojure

2010-09-16 Thread Meikel Brandmeyer
Hi, maybe this does what you want. I'm not sure, since you add the new meeting to *all* meetings? And where does the :title come from when you add a new meeting? I assume you have a map of a meeting title and a meeting and want to add this to the corresponding entry in the data map. If the meeting

Re: thinking in clojure

2010-09-16 Thread Laurent PETIT
Something along those lines : (def t { 0 {:title "some" :meetings [ :d1 ]} 2 {:title "some2" :meetings [ :d2 ]}}) user=> (pprint (update-in t [1] (fnil update-in {:title "title" :meetings []}) [:meetings] (comp vec concat) [:d1 :d2]int (update-in t [1] (fnil update-in {:title "title" :meetings []

Re: thinking in clojure

2010-09-16 Thread Mike Meyer
On Wed, 15 Sep 2010 11:48:09 -0700 Michael Ossareh wrote: > Hi Guys, > > One of the things that has struck me about clojure, by virtue of being > a lisp, is the concision of the code - I really find it very > attractive. However yesterday I found something that I couldn't work > out how to do in

Re: thinking in clojure

2010-09-16 Thread David Nolen
On Wed, Sep 15, 2010 at 2:48 PM, Michael Ossareh wrote: > Hi Guys, > > One of the things that has struck me about clojure, by virtue of being > a lisp, is the concision of the code - I really find it very > attractive. However yesterday I found something that I couldn't work > out how to do in a

Re: Thinking in Clojure

2010-09-03 Thread HB
I'm interested in Conjure webframework and I'm considering trying to read its source code and participate later. What do you think? Do you other projects in mind? This discussion is amazing guys :) On Sep 3, 8:25 pm, CuppoJava wrote: > I had the exact same problem transitioning from OOP to Lisp,

Re: Thinking in Clojure

2010-09-03 Thread jt
This may help! http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/ "These twenty video lectures by Hal Abelson and Gerald Jay Sussman are a complete presentation of the course, given in July 1986 for Hewlett- Packard employees, and professionally produced by Hewlett-Packard Te

Re: Thinking in Clojure

2010-09-03 Thread Raoul Duke
On Fri, Sep 3, 2010 at 8:23 AM, Michael Ossareh wrote: >> I'd go over SICP, though it not in Clojure but in Scheme - it will >> show you how to "think" functional. > +1 on this. > http://mitpress.mit.edu/sicp/ i think some folks argue that http://www.htdp.org/ is even better :-) or at least a goo

Re: Thinking in Clojure

2010-09-03 Thread CuppoJava
I had the exact same problem transitioning from OOP to Lisp, and I can only offer my own experiences. I finally "understood" lisp, by programming a new pet project FROM SCRATCH, in the most STRAIGHTFORWARD way possible. I originally started by porting over a program I had written in Java, and found

Re: Thinking in Clojure

2010-09-03 Thread HB
Really nice example Peter, Thanks, I appreciate it. On Sep 3, 6:36 am, Peter Buckley wrote: > I'm only a little ways through Joy of Clojure (my first Clojure book) > but bear with me as I'm thinking aloud on what it means for me to > "think in Clojure." I hope list members will forgive me if I ge

Re: Thinking in Clojure

2010-09-03 Thread Michael Ossareh
On Thu, Sep 2, 2010 at 21:05, Miki wrote: > I'd go over SICP, though it not in Clojure but in Scheme - it will > show you how to "think" functional. > +1 on this. http://mitpress.mit.edu/sicp/ -- !new number! 415-400-6772 -- You received this message because you are subscribed to the Googl

Re: Thinking in Clojure

2010-09-03 Thread Chouser
On Thu, Sep 2, 2010 at 11:36 PM, Peter Buckley wrote: > > One of the things that stuck out for me that I heard somewhere (can't > remember exactly) was that OOP is about framing questions in terms of > "nouns" and FP is about framing questions in terms of "verbs." Perhaps you heard it in Yegge's

Re: Thinking in Clojure

2010-09-03 Thread MarkH
Sean and Peter made comments that ring very true for me. I've always had a problem with Java/Smalltalk/C# type OO. I also thought the Common Lisp/Dylan way of generic functions and data structures made more sense. Like Peter mentioned, I tend to think in terms of verbs and transformations of dat

Re: Thinking in Clojure

2010-09-03 Thread Peter Buckley
I'm only a little ways through Joy of Clojure (my first Clojure book) but bear with me as I'm thinking aloud on what it means for me to "think in Clojure." I hope list members will forgive me if I get things wrong - and please correct my working concept(s) as well. One of the things that stuck out

Re: Thinking in Clojure

2010-09-03 Thread Sean Allen
On Thu, Sep 2, 2010 at 9:29 PM, HB wrote: > Hey, > I finished reading "Programming Clojure" and "Practical Clojure" and > I'm hooked :) > Please count me in the Clojure club. > But I failed how to think in Clojure. > My main career is around Java web applications (Hibernate, Spring, > Lucene) and

Re: Thinking in Clojure

2010-09-03 Thread Bob Hutchison
On 2010-09-02, at 10:02 PM, HB wrote: > So in idiomatic Clojure applications, maps are considered like > objects? > And to operate on them we pass them to functions? I think that considering maps as a state representation is reasonable. There are alternatives, but that's fine-tuning I think. T

Re: Thinking in Clojure

2010-09-02 Thread Sean Corfield
On Thu, Sep 2, 2010 at 6:29 PM, HB wrote: > Usually we create some domain entities, map them with Hibernate/ > iBatis. > I don't know how a Clojure application would be build without objects. I wonder if watching this talk by Rich Hickey will help? http://www.infoq.com/presentations/Are-We-There

Re: Thinking in Clojure

2010-09-02 Thread Miki
I'd go over SICP, though it not in Clojure but in Scheme - it will show you how to "think" functional. On Sep 2, 6:29 pm, HB wrote: > Hey, > I finished reading "Programming Clojure" and "Practical Clojure" and > I'm hooked :) > Please count me in the Clojure club. > But I failed how to think in C

Re: Thinking in Clojure

2010-09-02 Thread Wilson MacGyver
I highly recommend "Joy of Clojure". It's a good "2nd book on clojure". It shows you the "why things are the way they are", and how to do things the clojure way as much as possible. On Thu, Sep 2, 2010 at 9:29 PM, HB wrote: > Hey, > I finished reading "Programming Clojure" and "Practical Clojure"

Re: Thinking in Clojure

2010-09-02 Thread HB
So in idiomatic Clojure applications, maps are considered like objects? And to operate on them we pass them to functions? On Sep 3, 4:55 am, David Nolen wrote: > On Thu, Sep 2, 2010 at 9:29 PM, HB wrote: > > Hey, > > I finished reading "Programming Clojure" and "Practical Clojure" and > > I'm ho

Re: Thinking in Clojure

2010-09-02 Thread David Nolen
On Thu, Sep 2, 2010 at 9:29 PM, HB wrote: > Hey, > I finished reading "Programming Clojure" and "Practical Clojure" and > I'm hooked :) > Please count me in the Clojure club. > But I failed how to think in Clojure. > My main career is around Java web applications (Hibernate, Spring, > Lucene) and

Re: Thinking in Clojure - static fields?

2009-01-27 Thread Chouser
On Mon, Jan 26, 2009 at 11:13 PM, Whirlycott wrote: > > I'm new to Clojure and I'm wondering how I'm supposed to be thinking > about various things. I want to use the c3p0 database connection pool > in a Clojure app. In Java, I would simply create an instance of this > class and either assign i

Re: Thinking in Clojure - static fields?

2009-01-27 Thread Timothy Pratley
Here is one way: (let [dbc (make-db)] (defn get-apples [] (.query dbc "select * from apples"))) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@go