I wanted to add the map/cycle sample, then thougt of clojuredocs and
here you go:

 http://clojuredocs.org/clojure_core/clojure.core/identity

On 14 Aug., 00:25, Alan Malloy <a...@malloys.org> wrote:
> On Aug 13, 12:45 pm, jaime <xiejianm...@gmail.com> wrote:
>
> > I found an interesting function "identity" which will do nothing but
> > only returns the parameter passed to it. The next minute I came up a
> > question: "then what's the purpose of this function?" -- I've tried to
> > figure out reasons of existence of "identity".
>
> > The only reason that I can imagine is this: because we often use
> > higher-order functions, these higher-order functions will accept
> > functions as its parameters, in such a situation, when we want to use
> > a higher-order function but don't want to pass any "real" functions to
> > it, then we can use function like "identity" and "identity" here is
> > just to fill the role of parameter of higher-order function.
>
> > Guys, is my guess correct or not? Are there other reasons for
> > identity's existence?? Are there other functions for the same purpose?
>
> One of my favorite uses of identity is for use with partition-by:
>
> user> (partition-by identity '(a a b a a a a c c d))
> ;; ((a a) (b) (a a a a) (c c) (d))
>
> I sometimes speculate that, while identity is plenty useful, if your
> program contains the characters "(identity", you probably don't know
> how to program.

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