Functional Approach

Ken Pu
Thursday, Apr 5, 2018

The on-going assumption is that programming is all about data transformation. Let’s see how we achieve this with functions.


Function is a programming construct. Function is a piece of code that requires zero or more values as input, and function will generate a new data using some sort of computation.

(defn f [x y]

This is synonymous to how mathematicians express functions. $$ f(x, y) = \dots $$

(defn f ...) creates a top-level symbol f that is bound to a 2-arity function.

Using functions.

Mathematicians invoke functions all the time: $f(f(\pi, 1), 2)$. Clojure presents function invocations as a list, with the first element as function, and the rest as the arguments.

(f (f π 1) 2)
comments powered by Disqus