Very interesting ideas, everyone... thanks a lot for the input. Yeah, I recognize that each case is going to be different - I guess I was just looking for suggestions on how to manage it. Which I found... Comp and partial look particularly interesting. Thanks!
-Luke On Feb 25, 5:09 pm, Kevin Downey <redc...@gmail.com> wrote: > You should look at "->" > it lest you take (op3 (op2 (op1 input))) and write it as (-> input op1 op2 > op3) > there is also "comp" which composes functions, and partial for partial > application. > > some example comp > usage:http://github.com/hiredman/clojurebot/blob/297e266b0badf0f301a556e957... > > > > > > On Wed, Feb 25, 2009 at 12:57 PM, levand <luke.vanderh...@gmail.com> wrote: > > > Recently, in my code, I have been struggling with which of the two > > equivalent forms is, in a general sense, "better". > > > (defn my-fn1 [input] > > (let [value1 (op1 input) > > value2 (op2 input) > > value3 (op4 value1 value2)] > > (op5 value3))) > > > (defn my-fn2 [input] > > (op5 (op4 (op1 input) (op2 input)))) > > > Now, the second is definitely cleaner and more elegant, besides being > > smaller, which is a non-trivial benefit when I have a fair amount of > > code to page through. > > > However, if I've been away from the code awhile, it's much easier to > > come back determine what the code is doing when its written the first > > way, especially when it uses descriptive names. An operation that is > > impenetrable when written in nested form can become quite simple when > > each step is broken down and labeled. > > > Clojure is my first Lisp - should I just stick with the second form > > until I learn to "see through" the nested s-expressions? > > > It's not that I'm trying to make my code more imperative - Although I > > come from a Java background, I love functional programming, and it is > > a delight to see how much I can do without side-effects. But I do miss > > the self-documentation that well-named variables can provide. > > > Any thoughts? Also, is there any performance degradation from the > > first way, or can the compiler optimize it away? > > -- > And what is good, Phaedrus, > And what is not good— > Need we ask anyone to tell us these things? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---