If anything, the defprotocol and deftype stuff that's on the way is more along the lines of an abstract class because you can define a protocol, acting a sort of modularized interface, and then you can compose types by grouping together functions that implement one ore more protocols. Anyway, I don't think the idea of an abstract function from OO applies to functional programming so directly. If you think about abstraction a bit more generally, then you are basically trying to isolate common patterns in your code and then pull them out so that you can more easily create functions that use these same patterns without having to duplicate the thought, coding and debugging that went into it. Additionally, the hope is that by moving to higher levels of abstraction you can get the high level structure and form of your code to more closely mimic the way that you naturally understand what it is you are programming.
With that in mind, abstraction basically comes down to finding patterns and then finding ways to reuse them. Higher order functions, function composition, partial application, the sequence library and macros are all tools to let you suck patterns out of your code to create higher levels of abstraction. (Sean Devlin has some nice discussion of some of these ideas in Clojure in his video podcast, Full Disclojure, on vimeo.) Once you become familiar with each of the tools, then you can also start becoming familiar with the different patterns in code that they are best applied to. For example higher order functions are often used to automate the way that other functions are used without knowing what exactly the functions will do. When you see in multiple places in your code that you seem to be iterating over some data structure in the same way for multiple different reasons, then this is a good place for a higher order function. So it isn't about being concrete or abstract, but more about whether a function is implementing an abstract pattern or some application specific piece of logic. -Jeff On Feb 27, 8:10 pm, reynard <atsan...@gmail.com> wrote: > This may be more about functional programming in general, rather than > clojure specific. However, since I mainly use clojure for learning > functional programming, I would like to discuss it here. > > Basically, I can think of the following 2 ways of doing abstraction. > I would like to hear some comments or feedback from others. Which way > do you think is better? Does this issue even matter? Or there are > better alternative ways? Thanks. > > (defn abstract-function [f x y] > (body....) > (f x y) > (body....)) > > (defn concrete-function [x y] > (abstract-function a-fun x y)) > > -------------------------------------------------------------- > (defn abstract-function [f] > (fn [x y] > (body....) > (f x y) > (body....))) > > (def concrete-function (abstract-function a-fun)) -- 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