On Feb 27, 9: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))


I don't think the labels "concrete" or "abstract" apply to functions
very well. In both cases, abstract-function is a higher order
function, but that makes it no less concrete. :)

That said, both are valid approaches. The first one is a simple higher-
order function, like for example map or filter in clojure.core. The
second approach is is commonly used when the function returned is a
"one-shot" function, that gets passed to another. That is, instead of
def'ing concrete-function, you would use it like (map (abstract-
function a-fn) some-seq). Examples from c.core include partial,
constantly and comp.

-- 
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

Reply via email to