May 2018
Beginner to intermediate
290 pages
6h 43m
English
There’s something else you can do with functional values: you can manufacture new ones, on the fly. In much the same way you can make a new number with (+ 2 3) or (* 5 x), you can use fn to create new functions. Here, for example, we manufacture a new function with fn, one that doubles its argument:
| | (fn [n] (* 2 n)) |
As you can see from the example, using fn is a lot like using defn, except that you leave out the name. Like defn, fn creates a new function, essentially a packaged bit of code. The difference between fn and defn is that fn doesn’t bind its newborn bundle of code to a name; you just get the function value. So what can you do with a function value? Anything you can do with any other value. You can, for example, ...
Read now
Unlock full access