On Jan 7, 7:01 am, "Mark Volkmann" <r.mark.volkm...@gmail.com> wrote: > On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst <tom.aye...@gmail.com> wrote: > > Hi Mark, > > > I'm afraid I don't like the "big let" style and I found it hard to follow > > some of your code, that may just be a personal thing but a lot of the vars > > defined in let are only used once and could be inlined. > > I agree they could be inlined, but I find that style easier to read. > For example, these are equivalent. > > (defn make-cookies-1 [flower baking-soda salt button sugar eggs] > ; let describes the step-by-step process for making cookies. > (let [bowl (find-bowl :small) > bowl (add-ingredients bowl flower baking-soda salt) > batter (mix bowl) > batter (add-and-beat batter eggs flour) > baking-sheet (find-baking-sheet) > baking-sheet (make-dough-balls baking-sheet batter)] > (bake baking-sheet))) > > (def make-cookies-2 [flower baking-soda salt button sugar eggs] > (bake (make-dough-balls > (find-baking-sheet) > (add-and-beat (mix (add-ingredients (find-bowl) flower aking-soda > salt) eggs flour)))) > > Which of these is easier to understand?
You can avoid the big let while still keeping the order of operations clear by using the -> macro: (defn make-cookies [flour baking-soda salt butter sugar eggs] (let [batter (-> (find-bowl :small) (add ingredients flour baking-soda salt) (mix) (add-and-beat eggs flour))] (-> (find-baking-sheet) (make-dough-balls batter) (bake)))) In my opinion, this little macro is a brilliant idea. -- Nathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---