Friday: beer+code
On tap: Leinenkugels Summer Shandy
On the tube: Star Trek and X-Men: First Class
Time for some clojure again. I am getting impatient to finish this book because I want to get cracking on a few projects and working on clojure-clr
Grasping some fundamentals. Let's talk about reduce.
(doc reduce)
says:
([f coll] [f val coll]) f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as well, and reduce returns the result of calling f with no arguments. If coll has only 1 item, it is returned and f is not called. If val is supplied, returns the result of applying f to val and the first item in coll, then applying f to that result and the 2nd item, etc. If coll contains no items, returns val and f is not called.
So... (reduce + [1 2])
will give us 3 and (reduce + 5 [1 2])
will give us 8 because we apply the plus to 5, then to 1 which gives us 6 then to 2 which gives us 8
We can use fn
to define an anonymous function, so...
will be the same as above and give us 3.
I think the thing that worries me most about clojure is that it is awesome, but it requires such a tremendous amout of brain power/study before you can understand the concepts that it will never catch on because most will deem it as not worth it.