Language choice
So many languages, so many choices.
Python
reduce( lambda sum, current: sum + current, [1, 2, 3] )
Common Lisp
(reduce #'+ '(1 2 3))
Ruby
[1, 2, 3].inject(0) { |sum, current| sum = sum + current }
Perl
map {$sum += $_;} (1,2,3);
Which one do you prefer?
Update: I changed the Common Lisp version from using lambda to using the + function instead, it’s a lot less verbose. Thanks to everyone who pointed that out. ;)
In Common Lisp, `+’ is a function.
(reduce #’+ ‘(1 2 3))