I don't have my own examples, anyway being a daily object-oriented programmer I'm feeling compelled to say that where "function-generating functions" prove their main practical power is in what I'd label "man in the middle functions".
Whenever I need to add behaviour to an existing OO method I have to subclass or introduce an indirection by interface, applying a decorator pattern et similia, or to apply some aspect oriented programming. Instead in Clojure you can more easily "replace" that function by an hooked-one ( https://github.com/technomancy/robert-hooke/) or by hand-written wrapping functions (http://vimeo.com/channels/fulldisclojure/38507385). If a Java programmer find a little weird the typical decorator usage of the java.io.InputStream hierarchy (based on class inheritance) to the point it's been proposed a different hierarchy designed on interfaces (see the PragPub "Interface Oriented Design" book), I guess that the possibility of writing compoundable chains of functions can further improve the general design of what we write day-by-day. So if you are searching for practical examples I'd suggest to look for such use cases, although their best application IMHO has to be found not in business code but in utility libraries/frameworks, such as ring handlers. On Wed, Aug 8, 2012 at 6: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