Base Concepts of Functions
Learn to define and run functions as well as check the core available functions of Clojure.
Syntax and semantics
Clojure uses the Lisp dialect, as mentioned in previous lessons, and one of its main characteristics is the different style of its syntax and semantics, which is full of parentheses.
Just to remember the base idea of how we read and plan it, let's look at the image below (also seen previously).
So, the whole code will look just like this: a parenthesis being the invoker, a function-name
, which is the action being invoked, and its parameters.
With this explanation, we know exactly how to invoke and call functions, right? However, how do we create functions of our own?
Declaring variables and functions
In Clojure, as in any other programming language, we have a reserved word to define that we are creating a function of our own—defn
—and a reserved word to define a global variable—def
.
Note: Both
def
anddefn
are actually functions. ... ...