Tutorial by Examples

Functions are defined with five components: The header, which includes the defn keyword, the name of the function. (defn welcome ....) An optional Docstring that explains and document what the function does. (defn welcome "Return a welcome message to the world" ...) Pa...
Clojure functions can be defined with zero or more parameters. (defn welcome "Without parameters" [] "Hello!") (defn square "Take one parameter" [x] (* x x)) (defn multiplier "Two parameters" [x y] (* x y)) ...
A Clojure function can be defined to take an arbitrary number of arguments, using the symbol & in its argument list. All remaining arguments are collected as a sequence. (defn sum [& args] (apply + args)) (defn sum-and-multiply [x & args] (* x (apply + args))) Calling: =&gt...
There are two ways to define an anonymous function: the full syntax and a shorthand. Full Anonymous Function Syntax (fn [x y] (+ x y)) This expression evaluates to a function. Any syntax you can use with a function defined with defn (&, argument destructuring, etc.), you can also do with wi...

Page 1 of 1