A Very Simple Example:

(defn list-projects
  [request posts]
  (wrap request :project
   (text :projects)
   (map project-block posts)
   (link-to "/project/edit/" "new")))

That's a top-level view function from a (nearly) production site I'm
working at right now.

Note:

Clean readable code. This doesn't use any particular new or fancy
feature of clojure. All it is pretty much standard LISP with no side
effects. No macros or anything like that. Automatically thread safe.

Uses (map project-block posts) to translate a list of project
descriptions (a seq of nested maps) into a structured display format,
and project-block is simply a function that translates a single
project description into the required format (in this case,
compojure's generator format). Try doing that with a C-style for loop.

If you're presenting to non-functional programmers, I'd concentrate on
the basic and immediately useful stuff: map is one of the most useful
things I can think of - it pops up everywhere. reduce may be cooler,
but you're not going to use it nearly as much.

>From that project: total lines (including whitespace, comments etc):
less than 2000. Total uses of (map) - excluding macros that embed it:
78. That's a map call almost 8% of every line. If I'd had to guess,
I'd say that at least half of my "loops" are done using plain map.

Besides:

new Array arr;
(for i =0; i < list.length; i++)  {
  arr[i] = inputArr[i]+1;
]
return arr;

vs

(map inc inputArr)

And who's going to argue?

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