A ClojureScript One Question: Why is so much html created on the client side.
Hello, I am just trying to understand the best practices in ClojureScript One. One thing that strikes me is that most html gets put (with the help of macros using enlive) in the actual cljs page. As someone who hasn't done web-applications for years I myself would have created as much dynamic html content as possible on the server. But yet ClojureScript One seems to prefer to have all html in maps and render it on the client? I also looked at Chris Granger's crate library and it seems to also follow this principle. Since I consider Chris Granger and Brento Ashworth to be web experts I would just like to know the disadvantages of having most html rendered on the server? Many Greetings John -- 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: Attractive examples of function-generating functions
How about the new reducers library: http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html Jonas On Wednesday, August 8, 2012 7:48:23 PM UTC+3, Brian Marick wrote: I'm looking for medium-scale examples of using function-generating functions. I'm doing it because examples like this: (def make-incrementer (fn [increment] (fn [x] (+ increment x ... or this: (def incish (partial map + [100 200 300])) ... show the mechanics, but I'm looking for examples that would resonate more with an object-oriented programmer. Such examples might be ones that close over a number of values (which looks more like an object), or generate multiple functions that all close over a shared value (which looks more like an object), or use closures to avoid the need to have some particular argument passed from function to function (which looks like the `this` in an instance method). Note: please put the flamethrower down. I'm not saying that looking like objects is the point of higher-order functions. I'll give full credit. - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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: reduce-kv doesn't reduce a sorted-map in order
Sounds like a bug to me, in that it doesn't behave as I would expect. On Thu, Aug 9, 2012 at 7:29 PM, Baishampayan Ghose b.gh...@gmail.comwrote: Hi, It seems reduce-kv doesn't reduce a sorted-map in the correct order. Example - user (def *sm (into (sorted-map) {:aa 1 :zz 2 :bb 3 :yy 4 :cc 5 :xx 6})) ;= #'user/*sm user *sm ;= {:aa 1, :bb 3, :cc 5, :xx 6, :yy 4, :zz 2} ;; plain reduce user (reduce (fn [ret e] (conj ret e)) [] *sm) ;= [[:aa 1] [:bb 3] [:cc 5] [:xx 6] [:yy 4] [:zz 2]] ; correct ;; reduce-kv user (reduce-kv (fn [ret k v] (conj ret [k v])) [] *sm) ;= [[:cc 5] [:bb 3] [:aa 1] [:yy 4] [:xx 6] [:zz 2]] ; incorrect Is this a bug? Regards, BG -- Baishampayan Ghose b.ghose at 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 -- 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: Attractive examples of function-generating functions
While admittedly neat, and educational, this kind of code is fancy for production use in my opinion: (defn make-point [x y] (fn [member] (cond (= member :x) x (= member :y) y))) On Fri, Aug 10, 2012 at 6:06 PM, Jonas jonas.enl...@gmail.com wrote: How about the new reducers library: http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html Jonas On Wednesday, August 8, 2012 7:48:23 PM UTC+3, Brian Marick wrote: I'm looking for medium-scale examples of using function-generating functions. I'm doing it because examples like this: (def make-incrementer (fn [increment] (fn [x] (+ increment x ... or this: (def incish (partial map + [100 200 300])) ... show the mechanics, but I'm looking for examples that would resonate more with an object-oriented programmer. Such examples might be ones that close over a number of values (which looks more like an object), or generate multiple functions that all close over a shared value (which looks more like an object), or use closures to avoid the need to have some particular argument passed from function to function (which looks like the `this` in an instance method). Note: please put the flamethrower down. I'm not saying that looking like objects is the point of higher-order functions. I'll give full credit. - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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 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: reduce-kv doesn't reduce a sorted-map in order
Confirmed -- thanks for the report. Stu Hi, It seems reduce-kv doesn't reduce a sorted-map in the correct order. Example - user (def *sm (into (sorted-map) {:aa 1 :zz 2 :bb 3 :yy 4 :cc 5 :xx 6})) ;= #'user/*sm user *sm ;= {:aa 1, :bb 3, :cc 5, :xx 6, :yy 4, :zz 2} ;; plain reduce user (reduce (fn [ret e] (conj ret e)) [] *sm) ;= [[:aa 1] [:bb 3] [:cc 5] [:xx 6] [:yy 4] [:zz 2]] ; correct ;; reduce-kv user (reduce-kv (fn [ret k v] (conj ret [k v])) [] *sm) ;= [[:cc 5] [:bb 3] [:aa 1] [:yy 4] [:xx 6] [:zz 2]] ; incorrect Is this a bug? Regards, BG -- 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: A ClojureScript One Question: Why is so much html created on the client side.
Enlive is abstractement conceive : if you put a remote on client you could cache it... To do that with the same abstract language , you have the awesome enfocus [0] lib with a sample app here [1], and for those clojururians interested in MVC [2] Any way, there will be some *remote *to get that functionality on Enlive, it would be great ! [0] https://github.com/ckirkendall/enfocus [1] todomvc.herokuapp.com [2] http://github.com/phperret/peer-one/ Le vendredi 10 août 2012 12:21:00 UTC+2, john a écrit : Hello, I am just trying to understand the best practices in ClojureScript One. One thing that strikes me is that most html gets put (with the help of macros using enlive) in the actual cljs page. As someone who hasn't done web-applications for years I myself would have created as much dynamic html content as possible on the server. But yet ClojureScript One seems to prefer to have all html in maps and render it on the client? I also looked at Chris Granger's crate library and it seems to also follow this principle. Since I consider Chris Granger and Brento Ashworth to be web experts I would just like to know the disadvantages of having most html rendered on the server? Many Greetings John -- 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
currying and partial evaluation
After discovering a need for currying functions with partial evaluation (and having to do it by hand) in a clojurescript project, and deciding that a macro version might be feasible, I decided to give it a try. The result is here https://github.com/fredericksgary/currj, and seems to work at least on basic tests. Still unsupported are fn* and loop* sub-expressions, and there may be a few other relevant special forms. I also haven't yet looked into what it takes to support clojurescript. Comments and patches welcome. -- 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
Immutability rules when it comes to Ref type
Hi, I have a ref type that wraps a map, this map is going to embed many nested other maps. According to immutability rules, what happens when: A new nested map is updated (entry is removed or update) or even a new nested map is added to the master map that is wrapped by ref type? Thanks for help and time. -- 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: Attractive examples of function-generating functions
I think enlives transformersare a very good example of functions returning functions. Maybe you should have a look at the getting started guide and the tutorials Send from Android Am 09.08.2012 23:13 schrieb Jonah Benton jo...@jonah.com: You've probably seen these, but if not, Doug Crockford's video series on javascript walks through a number of interesting information sharing examples like the ones you're looking for using fn-generating-fns- http://yuiblog.com/crockford/ They're all great but act 3 - function the ultimate is especially juicy. The motivation for his examples is a little different than it would be for clojure, because that pattern is basically javascript's only abstraction trick. And certainly the semantics are different too. But if for whatever reason you haven't seen these videos, they're terrific and will probably spur some ideas. On Wed, Aug 8, 2012 at 12:48 PM, Brian Marick mar...@exampler.com wrote: I'm looking for medium-scale examples of using function-generating functions. I'm doing it because examples like this: (def make-incrementer (fn [increment] (fn [x] (+ increment x ... or this: (def incish (partial map + [100 200 300])) ... show the mechanics, but I'm looking for examples that would resonate more with an object-oriented programmer. Such examples might be ones that close over a number of values (which looks more like an object), or generate multiple functions that all close over a shared value (which looks more like an object), or use closures to avoid the need to have some particular argument passed from function to function (which looks like the `this` in an instance method). Note: please put the flamethrower down. I'm not saying that looking like objects is the point of higher-order functions. I'll give full credit. - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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 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 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: Immutability rules when it comes to Ref type
Would answer, if you want to be atomic, means transactional memory, that is a feature of Clore . Le vendredi 10 août 2012 18:21:12 UTC+2, Hussein B. a écrit : Hi, I have a ref type that wraps a map, this map is going to embed many nested other maps. According to immutability rules, what happens when: A new nested map is updated (entry is removed or update) or even a new nested map is added to the master map that is wrapped by ref type? Thanks for help and time. -- 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: Immutability rules when it comes to Ref type
If you want to stay with atomic transactions this is a Clojure feature , STM, if my souvenirs sont bons Le vendredi 10 août 2012 18:21:12 UTC+2, Hussein B. a écrit : Hi, I have a ref type that wraps a map, this map is going to embed many nested other maps. According to immutability rules, what happens when: A new nested map is updated (entry is removed or update) or even a new nested map is added to the master map that is wrapped by ref type? Thanks for help and time. -- 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: Clojure group in DFW area
@(:dfw clojure-user-groups) I'll claim that promise. :) --Proctor On Thursday, August 9, 2012 8:42:07 AM UTC-5, Alex Robbins wrote: The group hasn't met in a long time, but we were actually talking about some kind of a relaunch last week. We were hoping some Clojure interest had increased in the DFW area since we tried last time. Anyone else in the DFW area interested in getting together? Alex On Tue, Aug 7, 2012 at 11:09 AM, VishK svk...@gmail.com javascript: wrote: Hello, Is this group still meeting? (When?) Would be interested in attending the next one if possible to meet like-minded folks. Regards Vish (https://github.com/vishk) On Wednesday, June 15, 2011 11:02:10 AM UTC-5, ch...@rubedoinc.comwrote: Everyone, sorry for late notice but are meeting tonight is cancelled due to some scheduling conflicts. We have another meeting set for Tuesday June 28th 630PM - 900PM @ Rubedo, inc. 14580 Beltwood Pkwy E Suite 103 Farmers Branch, TX 75244 See you then ! On Jun 3, 9:46 am, ch...@rubedoinc.com ch...@rubedoinc.com wrote: Meeting is growing strong! We will be looking at some group projects to take on that we can use to stretch our clojure skills. Make the next meeting to be a part of it! Wednesday June 15th 630PM - 900PM @ Rubedo, inc. 14580 Beltwood Pkwy E Suite 103 Farmers Branch, TX 75244 (wifi available) On May 20, 11:08 am, ch...@rubedoinc.com ch...@rubedoinc.com wrote: Thanks everyone for attending. Our next meeting is scheduled for Our next meeting is scheduled for May 31th 630PM - 900PM @ Rubedo, inc. 14580 Beltwood Pkwy E Suite 103 Farmers Branch, TX 75244 (wifi available) there will be pizza and sodas, so bring yourclojurequestions and your appetite. Reply in this thread if you will be attending so that I can get a head count for pizza. On May 16, 12:41 pm, ch...@rubedoinc.com ch...@rubedoinc.com wrote: Meeting tonight, see you there ! Our next meeting is scheduled for May 16th 630PM - 900PM @ Rubedo, inc. 14580 Beltwood Pkwy E Suite 103 Farmers Branch, TX 75244 (wifi available) On May 4, 11:20 am, ch...@rubedoinc.com ch...@rubedoinc.com wrote: Thanks everyone for attending the first meeting. It was great to talk clojurewith some like minded people who are excited by the possibilities ! Our next meeting is scheduled for May 16th 630PM - 900PM @ Rubedo, inc. 14580 Beltwood Pkwy E Suite 103 Farmers Branch, TX 75244 (wifi available) Right now, we will try for two meetings each month. In the beginning, these will be mostly hack nights. As the group matures, we will look at doing presentations / talks onClojure. As most of the group is relatively new toClojure, we decided to start with thehttp://projecteuler.net/problemsasaway to get familiar with the language and have some common solutions to discuss. At our next meeting, we will bring our solutions for problems 1-10 and discuss how we went about solving them. All are welcome ! On Apr 25, 9:08 pm, Christopher Redinger ch...@clojure.com wrote: ch...@rubedoinc.com wrote: Rubedo, inc. 14580 Beltwood Pkwy E Suite 103 Farmers Branch, TX 75244 When: 630PM Monday May 2nd What:ClojureInterest Group Topic: 1st meeting, what our goals are, and how to take over the world withClojure Hi Chris! Thanks for offering to host the group. I've added a link to this thread on theClojureUser Groups page: http://dev.clojure.org/display/community/Clojure+User+Groups. Hopefully to help people who might be looking. We can update the link to something with a little more information if you get a page set up somewhere. Also, if you choose to go through Meetup, they have provided us with a code that gives a discount toClojuregroups. See the above page for more information. Thanks again, and let me know if there's anythingClojure/core can help you out with! Thanks, Chris -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: 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 javascript: For more options, visit this group at
Issue of protocol methods with names starting with -
The following code fails with a strange exception No matching field found: _GT_foobar for class user.MyFoobar: (defprotocol Foobar (-foobar [this])) (defrecord MyFoobar [value] Foobar (-foobar [this] (str Foobar: value))) (extend-protocol Foobar String (-foobar [this] (str Foobar: this))) (println (map -foobar [1 a])) (println (map #(-foobar %) [(MyFoobar. 1) (MyFoobar. a)])) ; the following call crashes. (println (map -foobar [(MyFoobar. 1) (MyFoobar. a)])) The result: [~]$ clojure foobar.clj (Foobar:1 Foobar:a) (Foobar:1 Foobar:a) (Exception in thread main java.lang.IllegalArgumentException: No matching field found: _GT_foobar for class user.MyFoobar at clojure.lang.Reflector.getInstanceField(Reflector.java:271) at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:300) at user$eval10$fn__11$G__2__13.invoke(foobar.clj:1) at user$eval10$fn__11$G__1__16.invoke(foobar.clj:1) at clojure.core$map$fn__4087.invoke(core.clj:2432) at clojure.lang.LazySeq.sval(LazySeq.java:42) at clojure.lang.LazySeq.seq(LazySeq.java:60) at clojure.lang.RT.seq(RT.java:473) at clojure.core$seq.invoke(core.clj:133) at clojure.core$print_sequential.invoke(core_print.clj:46) at clojure.core$fn__5270.invoke(core_print.clj:140) at clojure.lang.MultiFn.invoke(MultiFn.java:167) at clojure.core$pr_on.invoke(core.clj:3266) at clojure.core$pr.invoke(core.clj:3278) at clojure.lang.AFn.applyToHelper(AFn.java:161) ... It only fails with records that implement the protocol inline. It's also OK if the - part is in the middle of the method name, like aaa-foobar. I'm wondering if this is a issue or there is something I don't know about these special function names. P.S. My clojure version is 1.4.0. -- 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: A ClojureScript One Question: Why is so much html created on the client side.
I think it depends on the style of web site you are making. On the more GMail style 'web app' end of the spectrum, rendering/templating on the client side means you don't have to inundate the server with AJAX requests (for example, if different items are cached upon the initial connection). This will also result in less latency, and a more responsive user experience. I have no ClojureScript One specific experience, but this should give you some idea of why it would be preferred over the traditional model. Nick On Fri, Aug 10, 2012 at 11:21 AM, john john.vie...@gmail.com wrote: Hello, I am just trying to understand the best practices in ClojureScript One. One thing that strikes me is that most html gets put (with the help of macros using enlive) in the actual cljs page. As someone who hasn't done web-applications for years I myself would have created as much dynamic html content as possible on the server. But yet ClojureScript One seems to prefer to have all html in maps and render it on the client? I also looked at Chris Granger's crate library and it seems to also follow this principle. Since I consider Chris Granger and Brento Ashworth to be web experts I would just like to know the disadvantages of having most html rendered on the server? Many Greetings John -- 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 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: A ClojureScript One Question: Why is so much html created on the client side.
On 8/10/12 5:21 AM, john wrote: Hello, I am just trying to understand the best practices in ClojureScript One. One thing that strikes me is that most html gets put (with the help of macros using enlive) in the actual cljs page. As someone who hasn't done web-applications for years I myself would have created as much dynamic html content as possible on the server. But yet ClojureScript One seems to prefer to have all html in maps and render it on the client? I also looked at Chris Granger's crate library and it seems to also follow this principle. Since I consider Chris Granger and Brento Ashworth to be web experts I would just like to know the disadvantages of having most html rendered on the server? Many Greetings John John: Many believe in letting the client do the work saving 'horsepower' on the server side. With Moore's Law (http://en.wikipedia.org/wiki/Moore%27s_law) for hardware and similar increases in network bandwidth, I sometimes feel like a dinosaur when speaking of these things. Maybe we are at the point shifting this work to the client is no longer necessary. Probably the decision lies in the circumstances of the deployment considering all the factors involved (e.g., CPU counts and calibers, memory, network and etc). Rick -- 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: Immutability rules when it comes to Ref type
Hussein: If you ignore the ref for the moment, making any change to a map, or a map nested inside a map however many levels deep you wish, does not mutate the original map. Instead it creates a brand new map with the new set of keys and values. It is as if the original was copied, and the copy was modified, but it is implemented much more efficiently than that. For efficiency, this new map will usually share a lot of memory with the original one, but the original one and the new one are both in memory and accessible simultaneously, until and unless one is garbage collected, which would only happen after no other data structure references it any longer. A ref effectively contains a pointer to one object at a time, and this pointer can change over time. If you want to be safe about concurrency, the ref should only ever point at an immutable data structure. Modifying the map pointed to by the ref merely means that the pointer is changed from pointing to one immutable map, to pointing at a different immutable map. Neither of the two maps becomes mutable as a result of this. Andy On Aug 10, 2012, at 9:21 AM, Hussein B. wrote: Hi, I have a ref type that wraps a map, this map is going to embed many nested other maps. According to immutability rules, what happens when: A new nested map is updated (entry is removed or update) or even a new nested map is added to the master map that is wrapped by ref type? Thanks for help and time. -- 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: Immutability rules when it comes to Ref type
Crystal clear, thanks. On Friday, August 10, 2012 10:16:19 PM UTC+3, Andy Fingerhut wrote: Hussein: If you ignore the ref for the moment, making any change to a map, or a map nested inside a map however many levels deep you wish, does not mutate the original map. Instead it creates a brand new map with the new set of keys and values. It is as if the original was copied, and the copy was modified, but it is implemented much more efficiently than that. For efficiency, this new map will usually share a lot of memory with the original one, but the original one and the new one are both in memory and accessible simultaneously, until and unless one is garbage collected, which would only happen after no other data structure references it any longer. A ref effectively contains a pointer to one object at a time, and this pointer can change over time. If you want to be safe about concurrency, the ref should only ever point at an immutable data structure. Modifying the map pointed to by the ref merely means that the pointer is changed from pointing to one immutable map, to pointing at a different immutable map. Neither of the two maps becomes mutable as a result of this. Andy On Aug 10, 2012, at 9:21 AM, Hussein B. wrote: Hi, I have a ref type that wraps a map, this map is going to embed many nested other maps. According to immutability rules, what happens when: A new nested map is updated (entry is removed or update) or even a new nested map is added to the master map that is wrapped by ref type? Thanks for help and time. -- 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
Better ideas how to collect analytics data
Hi, I'm collecting analytics data. I used a master map that holds many other nested maps. Considering maps are immutable, many new maps are going to be allocated. (Yes, that is efficient in Clojure). Basic operation that I'm using is update-in , very convenient. Do you have a better idea how to collect these data more efficiently in Clojure? Thanks for help and time. -- 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
Why Clojure map literal creates an instance of array map?
Hi, Why Clojure map literal creates an instance of array map but not hash map? What are the advantages of array map over hash map? 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
Re: Why Clojure map literal creates an instance of array map?
It's not dependent on whether it's a literal but on the size of the map, 8 key-value pairs is the threshold. This results in a PersistentHashMap (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) = clojure.lang.PersistentHashMap This gets you a PersistentArrayMap (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}) = clojure.lang.PersistentHashMap You can see where this happens in the source here: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L115 HASHTABLE_THRESHOLD is a constant set to 16, 8 keys and 8 values. So when you assoc onto an arraymap with 8 key-value pairs it returns a hashmap. The reason for this, as far as I understand it, is that with small hashmaps it's more efficient to do simple copy-on-write. In other words when you assoc onto it, it copies the entire map, adds the new key-value pair to the copy, and then returns the copy. With larger hashmaps, it becomes more useful to do use a more complicated tree structure which uses structural sharing so that assoc doesn't copy the entire map. Copying a small 5 element map isn't a big deal, but copying one with several thousand elements is. On Fri, Aug 10, 2012 at 5:43 PM, Hussein B. hubaghd...@gmail.com wrote: Hi, Why Clojure map literal creates an instance of array map but not hash map? What are the advantages of array map over hash map? 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 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
How to measure pieces of Clojure code?
Hi, I want to measure how much space an algorithm is taking and then trying to change some aspects to see how things are going to differ. I also want to measure how much time it takes to complete an operation. What tools can I use? 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
Re: Why Clojure map literal creates an instance of array map?
Thanks, never knew about this hashtable threshold factor. On Saturday, August 11, 2012 1:01:02 AM UTC+3, Tamreen Khan (Scriptor) wrote: It's not dependent on whether it's a literal but on the size of the map, 8 key-value pairs is the threshold. This results in a PersistentHashMap (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) = clojure.lang.PersistentHashMap This gets you a PersistentArrayMap (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}) = clojure.lang.PersistentHashMap You can see where this happens in the source here: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L115 HASHTABLE_THRESHOLD is a constant set to 16, 8 keys and 8 values. So when you assoc onto an arraymap with 8 key-value pairs it returns a hashmap. The reason for this, as far as I understand it, is that with small hashmaps it's more efficient to do simple copy-on-write. In other words when you assoc onto it, it copies the entire map, adds the new key-value pair to the copy, and then returns the copy. With larger hashmaps, it becomes more useful to do use a more complicated tree structure which uses structural sharing so that assoc doesn't copy the entire map. Copying a small 5 element map isn't a big deal, but copying one with several thousand elements is. On Fri, Aug 10, 2012 at 5:43 PM, Hussein B. hubag...@gmail.comjavascript: wrote: Hi, Why Clojure map literal creates an instance of array map but not hash map? What are the advantages of array map over hash map? Thanks. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: 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 javascript: 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: A ClojureScript One Question: Why is so much html created on the client side.
Hello John, ClojureScript One is an example of a single-page application. This means that you get one page load from the server and everything else happens in the browser without any further page loads. The initial page that is loaded is dynamically generated on the server. Any other updates to the page are performed from JavaScript by manipulating the DOM. If you are making requests to the server for every new page then it makes sense to dynamically generate HTML there. The whole point of a single-page application is to make the application more responsive by reducing both the number of requests and the amount of data that is transferred over a network. Imbedding HTML templates in JavaScript means that those templates are only transferred over the network once. I hope this helps, Brenton On Friday, August 10, 2012 6:21:00 AM UTC-4, john wrote: Hello, I am just trying to understand the best practices in ClojureScript One. One thing that strikes me is that most html gets put (with the help of macros using enlive) in the actual cljs page. As someone who hasn't done web-applications for years I myself would have created as much dynamic html content as possible on the server. But yet ClojureScript One seems to prefer to have all html in maps and render it on the client? I also looked at Chris Granger's crate library and it seems to also follow this principle. Since I consider Chris Granger and Brento Ashworth to be web experts I would just like to know the disadvantages of having most html rendered on the server? Many Greetings John -- 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: How to measure pieces of Clojure code?
Hmm if by space you mean memory then I think that only a profiler can help with that, regarding time using https://github.com/hugoduncan/criterium for benchmarking is the path I would take Ronen On Saturday, August 11, 2012 1:21:05 AM UTC+3, Hussein B. wrote: Hi, I want to measure how much space an algorithm is taking and then trying to change some aspects to see how things are going to differ. I also want to measure how much time it takes to complete an operation. What tools can I use? 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
Re: Attractive examples of function-generating functions
That's a good call. +1 On Friday, August 10, 2012 8:36:25 AM UTC-4, Jonas wrote: How about the new reducers library: http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html Jonas On Wednesday, August 8, 2012 7:48:23 PM UTC+3, Brian Marick wrote: I'm looking for medium-scale examples of using function-generating functions. I'm doing it because examples like this: (def make-incrementer (fn [increment] (fn [x] (+ increment x ... or this: (def incish (partial map + [100 200 300])) ... show the mechanics, but I'm looking for examples that would resonate more with an object-oriented programmer. Such examples might be ones that close over a number of values (which looks more like an object), or generate multiple functions that all close over a shared value (which looks more like an object), or use closures to avoid the need to have some particular argument passed from function to function (which looks like the `this` in an instance method). Note: please put the flamethrower down. I'm not saying that looking like objects is the point of higher-order functions. I'll give full credit. - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile -- 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