On Fri, Jan 1, 2016 at 9:53 PM, William la Forge <laforg...@gmail.com> wrote:
> Andrey, > > This is where I have a problem. Ii could have implemented dewdrop lenses > as functions that could be composed. But the code would be harder to > understand and possibly be slower. I just do not see the point. > I agree with your main argument, but I don't know how using records makes thinks more easy understandable in this concrete case and how using functions over records will make code slower. Transducers has a performance improvements over classical transformation compositions, and in this case, the cats lenses leverage the same technique. > > Implementing dewdrop lenses as records makes it dirt simple for anyone to > create more kinds of lenses. And the ladd function to create a new record > with the composed getter and setter functions is pretty clean as well. > Yes but it implies more api to know, that is not bad but if you limit the set of new api that one should learn/use, will contribute to more familiar and easy api. Adding new api also implies more time to understand it and remember when it should be used. > > Isn't it more important to have code you can analyze easily, and which > even a novice clojurist like myself can embrace and enhance a whole lot > more important than being able to say that we can use comp to compose these > lenses??? > Yes, I agree with you, the code readability is very very important. But this concrete case I don't found big differences in code readability: ;; dewdrop (defn key-lens [k] (lens. (fn [d] (get d k)) (fn [d v] (assoc d k v)))) ;; cats (defn key [k] (lens (fn [s] (get s k)) (fn [s f] (update s k f)))) The code is mostly the same... > I see good engineering as leveraging computer science so the programming > grunts can make effective use of it. Programming is real grunt work, after > all. No matter how much you dress it up, we all needs must get our hands > dirty and put our backs into it. > My two cents. Andrey > > Bill > > On Friday, January 1, 2016 at 9:09:08 AM UTC-5, Andrey Antukh wrote: >> >> Hi! >> >> I have read the readme and I don't found a big evidence of something >> wrong so, nice work! >> Furthermore, do you know about https://github.com/funcool/cats ? It has >> a lens and traversable implementation for clj/cljs. You can read the >> related documentation here: http://funcool.github.io/cats/latest/#lens . >> >> You can found that lenses, using cats approach, are working just like >> transducers (function composition), you do not need any special function >> for combine lenses, just use comp. One of the readme examples (from your >> repository) that combines two lenses, in cats can be written in this way: >> >> (require '[cats.labs.lens :as l]) >> (def xy-lens (comp (l/key :x) (l/key :y)) >> ;; Or just use (l/in [:x :y]) >> >> (l/focus xy-lens {:x {:y 1}}) >> ;; => 1 >> (l/over xy-lens inc {:x {:y 1}}) >> ;; => {:x {:y 2}} >> >> Happy new year! >> Andrey >> >> On Fri, Jan 1, 2016 at 2:54 PM, William la Forge <lafo...@gmail.com> >> wrote: >> >>> I've been looking at lenses and while it looks pretty simple and very >>> useful, I had a hard time getting it. So I came up with my own take on >>> lenses. https://github.com/laforge49/dewdrop#readme >>> >>> So perhaps I still do not understand lenses and what I've done is wrong. >>> Or perhaps having been through the exercise I'm now getting it and what >>> I've done is no simpler than what everyone else has done. Or perhaps I've >>> just described things with fewer technical terms. >>> >>> So I'd appreciate it if you would review this very short document and >>> tell me what I don't understand. Or that I've actually done something >>> worthwhile with lenses??? >>> >>> Thanks! >>> Bill >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To post to this group, send email to clo...@googlegroups.com >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> To unsubscribe from this group, send email to >>> clojure+u...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/clojure?hl=en >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to clojure+u...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Andrey Antukh - Андрей Антух - <ni...@niwi.nz> >> http://www.niwi.nz >> https://github.com/niwinz >> > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Andrey Antukh - Андрей Антух - <n...@niwi.nz> http://www.niwi.nz https://github.com/niwinz -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.