Re: thinking in clojure
On Thu, Sep 16, 2010 at 07:53, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com 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? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) Awesome, thank you for returning concision to my code! I'd certainly missed the update-in, and related, functions. Cheers Laurent! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
(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 trying to avoid passing these values in the loop signature. Your point is very well taken and I've now replaced those (def)'s with a let inside the loop. (if (not (nil? (next collection) Minor nit: (not (nil? X)) is better spelled (seq? X)) Right! That's actually a standard idiom, except you missed the assoc-in and get-in functions: (assoc-in data key :meetings (conj (get-in data key :meetings) meeting) Thanks for the advice. I've taken Laurent's feedback and ended up with: (update-in data [week-difference] (fnil update-in (struct week title [])) [meetings] into [decorated]) Which certainly reads far better than what I had. Thanks for pointing out get-in, another *key* fn I've missed. The standard library is rather large, I guess this'll take a while. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
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 - going to change that right now. Thanks for showing me this. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
On 17 September 2010 00:56, Michael Ossareh ossa...@gmail.com 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've got that (true? true) stuff scattered all over my code - going to change that right now. Thanks for showing me this. It's not actually an :else option in cond. Anything that is not false or nil can work there, so :any-arb-keyword would work just as well as :else. But by convention, Clojure programmers tend to use :else. -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
On Fri, Sep 17, 2010 at 08:58, Michael Wood esiot...@gmail.com wrote: On 17 September 2010 00:56, Michael Ossareh ossa...@gmail.com 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've got that (true? true) stuff scattered all over my code - going to change that right now. Thanks for showing me this. It's not actually an :else option in cond. Anything that is not false or nil can work there, so :any-arb-keyword would work just as well as :else. But by convention, Clojure programmers tend to use :else. Thanks for confirming my thoughts, Michael. Indeed I immediately checked the docs and couldn't find :else referenced. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
On Wed, Sep 15, 2010 at 2:48 PM, Michael Ossareh ossa...@gmail.com 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 concise manner. Clearly commenting the code was a priority once I got it working, however I'd like to ensure I'm doing this correctly. Much of my functional experience comes from JS and dealing with the immutability of our data structures is a very interesting learning process. You should look at update-in, assoc-in. Then you could write something like this (not tested): (defn add-meeting [xs key meeting] (for [x xs] (update-in x [key :meetings] conj meeting))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
On Wed, 15 Sep 2010 11:48:09 -0700 Michael Ossareh ossa...@gmail.com 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 concise manner. Clearly commenting the code was a priority once I got it working, however I'd like to ensure I'm doing this correctly. Much of my functional experience comes from JS and dealing with the immutability of our data structures is a very interesting learning process. I have a map (a sorted map) which maps an int to a map. The inner map contains a vector of data to which I want to conj elements into. { 0 {:title some str :meetings [{ ... meeting data ... } { ... meeting data ... } { ... meeting data ...}]} 1 {:title some other str :meetings [{ ... meeting data ... } { ... meeting data ... } { ... meeting data ...}]} . n {:title some n str :meetings [{ ... meeting data ... } { ... meeting data ... } { ... meeting data ...}]}} In JS I'd have a loop which looks somewhat like this (assume the data above is called storedData and that newData has the data which I wish to insert into storedData); newData.forEach(function(data) { var key = ; if (!storedData[key]) storedData[key] = {title: title}, meetings:[]} storedData[key].meetings.push(data) ; }) In clj, I've ended up with something along the lines of the following (edited from what I have in my code base to match the JS example above): (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. (if (not (nil? (next collection) Minor nit: (not (nil? X)) is better spelled (seq? X)) And you seem to be missing a close paren or two here. (recur (cond (not (nil? (data key))) (assoc data key (assoc (data key) :meetings (conj ((data key) :meetings) meeting))) (true? true) (conj data [key {:title some str :meetings [meeting]}]))) data)) The middle section, with the assoc(es) and conj, just doesn't read as nicely as the rest of my clojure. Is this a symptom of my data structure or is there a more concise way to conj my data into these inner vectors? That's actually a standard idiom, except you missed the assoc-in and get-in functions: (assoc-in data key :meetings (conj (get-in data key :meetings) meeting) Should do what you want. Also, as a secondary concern, I read on here a while ago that when you find yourself typing (( it's a sign of an issue - how, given the data structure I've to work with, woud you access the title of a value if not using that (( syntax, i.e. ((data key) :title)? I'm not sure where that came from, bug get-in and assoc-in solve that as well. mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
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 []}) [:meetings] (comp vec concat) [:d1 :d2])) {1 {:title title, :meetings [:d1 :d2]}, 0 {:title some, :meetings [:d1]}, 2 {:title some2, :meetings [:d2]}} and in a function: (def *default-value* {:title title :meetings []}) (defn assoc-data data is considered a seq of additional meeting objects to insert at the end of the meetings of key k [coll k data] (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp vec concat) data)) Concise again, isn't it ? ;-) HTH, -- Laurent 2010/9/15 Michael Ossareh ossa...@gmail.com 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 concise manner. Clearly commenting the code was a priority once I got it working, however I'd like to ensure I'm doing this correctly. Much of my functional experience comes from JS and dealing with the immutability of our data structures is a very interesting learning process. I have a map (a sorted map) which maps an int to a map. The inner map contains a vector of data to which I want to conj elements into. { 0 {:title some str :meetings [{ ... meeting data ... } { ... meeting data ... } { ... meeting data ...}]} 1 {:title some other str :meetings [{ ... meeting data ... } { ... meeting data ... } { ... meeting data ...}]} . n {:title some n str :meetings [{ ... meeting data ... } { ... meeting data ... } { ... meeting data ...}]}} In JS I'd have a loop which looks somewhat like this (assume the data above is called storedData and that newData has the data which I wish to insert into storedData); newData.forEach(function(data) { var key = ; if (!storedData[key]) storedData[key] = {title: title}, meetings:[]} storedData[key].meetings.push(data) ; }) In clj, I've ended up with something along the lines of the following (edited from what I have in my code base to match the JS example above): (loop [data (sorted-map) collection newData meeting (first collection)] (def key ( )) (if (not (nil? (next collection) (recur (cond (not (nil? (data key))) (assoc data key (assoc (data key) :meetings (conj ((data key) :meetings) meeting))) (true? true) (conj data [key {:title some str :meetings [meeting]}]))) data)) The middle section, with the assoc(es) and conj, just doesn't read as nicely as the rest of my clojure. Is this a symptom of my data structure or is there a more concise way to conj my data into these inner vectors? Also, as a secondary concern, I read on here a while ago that when you find yourself typing (( it's a sign of an issue - how, given the data structure I've to work with, woud you access the title of a value if not using that (( syntax, i.e. ((data key) :title)? Cheers, mike -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
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 is not contained it will be added as n+1. (defn insert-meeting-data [data {:keys [title meeting]}] (if-let [k (some #(when (= title (get-in data [% :title])) %) (keys data))] (update-in data [k :meetings] conj meeting) (let [k (inc (apply max (keys data)))] (assoc data k {:title title :meetings [meeting]} To be used eg. as: (reduce insert-meeting-data data sequence-of-title-meeting-maps) Also, as a secondary concern, I read on here a while ago that when you find yourself typing (( it's a sign of an issue - how, given the data structure I've to work with, woud you access the title of a value if not using that (( syntax, i.e. ((data key) :title)? (( is not necessarily a sign of an issue, but for your example you can do (:title (data key)) or (get-in data [key :title]). (loop [data (sorted-map) collection newData meeting (first collection)] (def key ( )) Almost surely not what you want. You want a let, not a def. def is always global and in 95% of the cases should only be used in global context. Exceptions are for example closures. (let [hidden-atom (atom nil)] (defn can-access-hidden-atom [..] )) (if (not (nil? (next collection) You can save the nil?. (if (not (next collection))) will also work. nil is logically false. (recur (cond (not (nil? (data key))) (true? true) *ieeck* Please do (cond ... :else default-clause). Not true, or (true? true) or other stuff. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
Hi, On 16 Sep., 15:36, Meikel Brandmeyer m...@kotka.de 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 Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com 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? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
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 laurent.pe...@gmail.com wrote: 2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com 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? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
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 :a is specified by (fnil XXX default-value). And by specifying that XXX is update-in, you can continue your key path where you stopped (after :a), either using the found value at :a, either the provided default value : (update-in {} [:a] (fnil update-in {:label great label}) [:b] identity) = {:a {:b nil, :label great label}} or you can also decide that it's not a map which should be the default value, imagine you want to modify a path [:a 2] : (update-in {} [:a] (fnil update-in [:foo :bar :baz]) [2] str) = {:a [:foo :bar :baz]} 2010/9/16 Btsai benny.t...@gmail.com 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 laurent.pe...@gmail.com wrote: 2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com 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? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
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 [:a] (fnil update-in default-for-first-level) [:b] (fnil update-in default-for-second-level) [:c] (fnil update-in default-for-third-level) [:d] (fnil update-in default-for-fourth-level) the-function-you-wanted-to-use-in-the-first-place arg2-for-the-function arg3-for-the-function ...) 2010/9/16 Laurent PETIT laurent.pe...@gmail.com 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 :a is specified by (fnil XXX default-value). And by specifying that XXX is update-in, you can continue your key path where you stopped (after :a), either using the found value at :a, either the provided default value : (update-in {} [:a] (fnil update-in {:label great label}) [:b] identity) = {:a {:b nil, :label great label}} or you can also decide that it's not a map which should be the default value, imagine you want to modify a path [:a 2] : (update-in {} [:a] (fnil update-in [:foo :bar :baz]) [2] str) = {:a [:foo :bar :baz]} 2010/9/16 Btsai benny.t...@gmail.com 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 laurent.pe...@gmail.com wrote: 2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com 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? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thinking in clojure
That pattern will be a great addition to the toolbox, thank you :) On Sep 16, 9:58 am, Laurent PETIT laurent.pe...@gmail.com 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 :d] and provide specific default values at each level if the key is not found, it's as simple as : (update-in coll [:a] (fnil update-in default-for-first-level) [:b] (fnil update-in default-for-second-level) [:c] (fnil update-in default-for-third-level) [:d] (fnil update-in default-for-fourth-level) the-function-you-wanted-to-use-in-the-first-place arg2-for-the-function arg3-for-the-function ...) 2010/9/16 Laurent PETIT laurent.pe...@gmail.com 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 :a is specified by (fnil XXX default-value). And by specifying that XXX is update-in, you can continue your key path where you stopped (after :a), either using the found value at :a, either the provided default value : (update-in {} [:a] (fnil update-in {:label great label}) [:b] identity) = {:a {:b nil, :label great label}} or you can also decide that it's not a map which should be the default value, imagine you want to modify a path [:a 2] : (update-in {} [:a] (fnil update-in [:foo :bar :baz]) [2] str) = {:a [:foo :bar :baz]} 2010/9/16 Btsai benny.t...@gmail.com 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 laurent.pe...@gmail.com wrote: 2010/9/16 Meikel Brandmeyer m...@kotka.de Hi Laurent, On 16 Sep., 15:54, Laurent PETIT laurent.pe...@gmail.com 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? Yep. so this is the killer one : :-) (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data) -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
On Thu, Sep 2, 2010 at 6:29 PM, HB hubaghd...@gmail.com 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-Yet-Rich-Hickey It focuses on issues with mutability in the context of OO. -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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. There's a lot you're going to have to take in, but I suspect the biggest sticking point will be around values/immutable-state, references to that state, and when/how the reference changes. When you get this, you'll be able to see how state/reference/time relate to the OO concepts you already know. At which point you'll be laughing. I don't remember anybody I've worked with that has had any difficulty with picking up functional programming (aside from the immutability thing). It's one of those things that changes how you work forever -- you are going to feel pain when working with Java :-) I strongly second the recommendation of the book Joy Of Clojure as a next thing to read (it's from Manning and you can get from their MEAP in pdf/epub formats) Cheers, Bob On Sep 3, 4:55 am, David Nolen dnolen.li...@gmail.com wrote: On Thu, Sep 2, 2010 at 9:29 PM, HB hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? It does require a significant shift in thinking. I think you'll be surprised how far maps and functions will take you if you're used to thinking in OOP. And contrary to popular belief Clojure is also a hybrid OOP/FP approach: multimethods, protocols, deftype, defrecord, definterface, etc. will let you utilize the better aspects of OOP design. However you should be cautious to reach for these. They are easily misapplied. Stick with the core datastructures (maps, vectors, sets, lists) and fns and you'll do just fine. David -- 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 Bob Hutchison Recursive Design Inc. http://www.recursive.ca/ weblog: http://xampl.com/so -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
On Thu, Sep 2, 2010 at 9:29 PM, HB hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? Reading a bit about OOP in either Common Lisp or Dylan might help ease you into 'thinking clojure'. It can provide a bridge between then Java OOP way and other ways of doing OOP. I had the opposite problem from you. When I started programming, Dylan and Common Lisp style OOP made far more sense to me then the C++/Java way ( and the Smalltalk way but I didn't want to group it with C++/Java ). There is a fundamental difference in OOP in Lisp style languages from the Algol ones and knowing more about those other forms of OOP might make the path easier to see. There is an older Guy Steele essay that talks in part about Scheme and OOP ( something that most people consider anti-ethical ) http://dreamsongs.com/ObjectsHaveNotFailedNarr.html Basic message, some form of OOP is possible in any language, it is just how easy it is made. As David said, I would be careful about reaching for the methods in Clojure that makes OOP easier and work more with maps, vectors, fns etc and then look at the others. - for more info on OOP in dylan see: http://www.opendylan.org/books/drm/ for more info about OOP in Common Lisp, I would recommened: http://www.amazon.com/Object-Oriented-Programming-Common-Lisp-Programmers/dp/0201175894/ref=sr_1_9?ie=UTF8s=booksqid=1283484149sr=8-9 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 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. Partly for my own benefit (and the list's critique and refinement) I want to talk about this as it relates to an example. The first task I'm working on in Clojure is taking a text file which is sortof a template, and then removing/adding/changing certain lines/strings in it based on an xml kindof config file, in the end spitting out an improved text file. If I was in the OOP frame of mind, I would have a class to represent my text file, and a class to represent my xml file. There would possibly be a shared base class to let me share the common slurping (reading of lines) from the files. As verb-y as that is (I hope Clojure is polluting my thought process already!) the base class would probably be called File or something super noun-y. In any case, the classes, the files, these are all nouns. But in the FP frame of mind, I just have data or information, and the focus is on the transformations that I do with the data. The transformations are things like zip-my-xml-into-a-struct-map or read-my-lines-into-a-seq and replace-text-values-with-xml-values. The focus is on the actions (verbs being action words), and the functions are essentially the verbs. I feel like I'm starting to get the concept of thinking in a function-al way, although I have a lot of work to do yet on learning Clojure the language. HTH, Peter On Thu, Sep 2, 2010 at 10:02 PM, Wilson MacGyver wmacgy...@gmail.com wrote: 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 hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? -- Omnem crede diem tibi diluxisse supremum. -- 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 -- The king’s heart is like a stream of water directed by the Lord; He guides it wherever He pleases. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 data. It just makes a lot more sense to me. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
On Thu, Sep 2, 2010 at 11:36 PM, Peter Buckley buckmeist...@gmail.com 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 enjoyable essay: http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html --Chouser -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
On Thu, Sep 2, 2010 at 21:05, Miki miki.teb...@gmail.com 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 Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
Really nice example Peter, Thanks, I appreciate it. On Sep 3, 6:36 am, Peter Buckley buckmeist...@gmail.com 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 get things wrong - and please correct my working concept(s) as well. 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. Partly for my own benefit (and the list's critique and refinement) I want to talk about this as it relates to an example. The first task I'm working on in Clojure is taking a text file which is sortof a template, and then removing/adding/changing certain lines/strings in it based on an xml kindof config file, in the end spitting out an improved text file. If I was in the OOP frame of mind, I would have a class to represent my text file, and a class to represent my xml file. There would possibly be a shared base class to let me share the common slurping (reading of lines) from the files. As verb-y as that is (I hope Clojure is polluting my thought process already!) the base class would probably be called File or something super noun-y. In any case, the classes, the files, these are all nouns. But in the FP frame of mind, I just have data or information, and the focus is on the transformations that I do with the data. The transformations are things like zip-my-xml-into-a-struct-map or read-my-lines-into-a-seq and replace-text-values-with-xml-values. The focus is on the actions (verbs being action words), and the functions are essentially the verbs. I feel like I'm starting to get the concept of thinking in a function-al way, although I have a lot of work to do yet on learning Clojure the language. HTH, Peter On Thu, Sep 2, 2010 at 10:02 PM, Wilson MacGyver wmacgy...@gmail.com wrote: 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 hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? -- Omnem crede diem tibi diluxisse supremum. -- 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 -- The king’s heart is like a stream of water directed by the Lord; He guides it wherever He pleases. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 that that did not help my understanding at all. -Patrick On Sep 3, 12:12 pm, HB hubaghd...@gmail.com wrote: Really nice example Peter, Thanks, I appreciate it. On Sep 3, 6:36 am, Peter Buckley buckmeist...@gmail.com 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 get things wrong - and please correct my working concept(s) as well. 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. Partly for my own benefit (and the list's critique and refinement) I want to talk about this as it relates to an example. The first task I'm working on in Clojure is taking a text file which is sortof a template, and then removing/adding/changing certain lines/strings in it based on an xml kindof config file, in the end spitting out an improved text file. If I was in the OOP frame of mind, I would have a class to represent my text file, and a class to represent my xml file. There would possibly be a shared base class to let me share the common slurping (reading of lines) from the files. As verb-y as that is (I hope Clojure is polluting my thought process already!) the base class would probably be called File or something super noun-y. In any case, the classes, the files, these are all nouns. But in the FP frame of mind, I just have data or information, and the focus is on the transformations that I do with the data. The transformations are things like zip-my-xml-into-a-struct-map or read-my-lines-into-a-seq and replace-text-values-with-xml-values. The focus is on the actions (verbs being action words), and the functions are essentially the verbs. I feel like I'm starting to get the concept of thinking in a function-al way, although I have a lot of work to do yet on learning Clojure the language. HTH, Peter On Thu, Sep 2, 2010 at 10:02 PM, Wilson MacGyver wmacgy...@gmail.com wrote: 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 hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? -- Omnem crede diem tibi diluxisse supremum. -- 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 -- The king’s heart is like a stream of water directed by the Lord; He guides it wherever He pleases. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
On Fri, Sep 3, 2010 at 8:23 AM, Michael Ossareh ossa...@gmail.com 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 good 'nother one to skim. sincerely. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 Television. The videos have been used extensively in corporate training at Hewlett-Packard and other companies, as well as at several universities and in MIT short courses for industry. On Sep 3, 10:23 am, Michael Ossareh ossa...@gmail.com wrote: On Thu, Sep 2, 2010 at 21:05, Miki miki.teb...@gmail.com 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 Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 patrickli_2...@hotmail.com wrote: 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 that that did not help my understanding at all. -Patrick On Sep 3, 12:12 pm, HB hubaghd...@gmail.com wrote: Really nice example Peter, Thanks, I appreciate it. On Sep 3, 6:36 am, Peter Buckley buckmeist...@gmail.com 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 get things wrong - and please correct my working concept(s) as well. 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. Partly for my own benefit (and the list's critique and refinement) I want to talk about this as it relates to an example. The first task I'm working on in Clojure is taking a text file which is sortof a template, and then removing/adding/changing certain lines/strings in it based on an xml kindof config file, in the end spitting out an improved text file. If I was in the OOP frame of mind, I would have a class to represent my text file, and a class to represent my xml file. There would possibly be a shared base class to let me share the common slurping (reading of lines) from the files. As verb-y as that is (I hope Clojure is polluting my thought process already!) the base class would probably be called File or something super noun-y. In any case, the classes, the files, these are all nouns. But in the FP frame of mind, I just have data or information, and the focus is on the transformations that I do with the data. The transformations are things like zip-my-xml-into-a-struct-map or read-my-lines-into-a-seq and replace-text-values-with-xml-values. The focus is on the actions (verbs being action words), and the functions are essentially the verbs. I feel like I'm starting to get the concept of thinking in a function-al way, although I have a lot of work to do yet on learning Clojure the language. HTH, Peter On Thu, Sep 2, 2010 at 10:02 PM, Wilson MacGyver wmacgy...@gmail.com wrote: 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 hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? -- Omnem crede diem tibi diluxisse supremum. -- 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 -- The king’s heart is like a stream of water directed by the Lord; He guides it wherever He pleases. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
On Thu, Sep 2, 2010 at 9:29 PM, HB hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? It does require a significant shift in thinking. I think you'll be surprised how far maps and functions will take you if you're used to thinking in OOP. And contrary to popular belief Clojure is also a hybrid OOP/FP approach: multimethods, protocols, deftype, defrecord, definterface, etc. will let you utilize the better aspects of OOP design. However you should be cautious to reach for these. They are easily misapplied. Stick with the core datastructures (maps, vectors, sets, lists) and fns and you'll do just fine. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 dnolen.li...@gmail.com wrote: On Thu, Sep 2, 2010 at 9:29 PM, HB hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? It does require a significant shift in thinking. I think you'll be surprised how far maps and functions will take you if you're used to thinking in OOP. And contrary to popular belief Clojure is also a hybrid OOP/FP approach: multimethods, protocols, deftype, defrecord, definterface, etc. will let you utilize the better aspects of OOP design. However you should be cautious to reach for these. They are easily misapplied. Stick with the core datastructures (maps, vectors, sets, lists) and fns and you'll do just fine. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure
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 hubaghd...@gmail.com 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 Web services. Lets not talk about Java web frameworks neither Clojure ones, I want to talk in general. 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 think Scala really shines here, this OOP/FP is really powerful approach (please note I'm not saying Clojure isn't good, I don't seel flame war) How to think in Clojure? how to achieve this shift? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Thinking in Clojure - static fields?
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@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Thinking in Clojure - static fields?
On Mon, Jan 26, 2009 at 11:13 PM, Whirlycott p...@whirlycott.com 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 it to a static field or perhaps make it available in a singleton and use it from there. In Clojure, am I supposed to use a var or a ref for this? Or something else entirely? Refs are only useful if you plan to change the value of the ref to point to a new object. It sounds to me like you don't plan to do this. On the other hand, Vars are created most often via 'defn', and generally their values never change and they are globally accessible. I think a Var would do very nicely in this case. (def connection-pool (new DatabasePool ...)) --Chouser --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---