Re: Presentatie over Clojure

2010-02-12 Thread Joop Kiefte
Sorry for the 3rd post, but can someone provide some nice example-code for
functional structures used in real world code?

2010/2/12 Jeff Rose ros...@gmail.com

 Cool!  This is the most fun I've ever had practicing Dutch :-)

 As someone who used to be very skeptical towards functional programming and
 Lisps, I think it would be good to have some examples to show what you mean
 about things being cleaner and simpler in functional Clojure.  I think
 comparing a typical for loop that transforms an array with mapping a
 function over a seq, or something like that, would make for a nice example.
 The other big thing to talk about is immutable values.  Nobody can know what
 this code produces, whether single or multi-threaded, which seems to be the
 heart of the problem with object orientation:

 def foo(obj)
   obj.val = 2
   obj.do_stuff()
   return obj.val
 end

 -Jeff



 On Fri, Feb 12, 2010 at 4:39 PM, Joop Kiefte iko...@gmail.com wrote:

 Graag commentaar

 --
 Communication is essential. So we need decent tools when communication is
 lacking, when language capability is hard to acquire...

 - http://esperanto.net  - http://esperanto-jongeren.nl

 Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004





-- 
Communication is essential. So we need decent tools when communication is
lacking, when language capability is hard to acquire...

- http://esperanto.net  - http://esperanto-jongeren.nl

Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

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

Re: Presentatie over Clojure

2010-02-12 Thread Joost
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