Simple - Small Syntax, no fluff

Clojure has a very small syntax, with very few fiddly bits in the language.

The syntax is so small you can read it all in about 15 minutes with lots of examples

(str "Hello" " " "World!")
(+ 3 4)
(map inc [1 2 3 4 5])
Parentheses ()

Parentheses ( ) are a list in Clojure. A left parenthesis is the start of the list and needs a matching right parenthesis or you will get an error.

It is quite common in Clojure code to have many nested parentheses

(def username "john")

(str "Welcome to our website: " (clojure.string/capitalize username))
Calling Functions

Next to the parentheses, we see the instructions to the computer. That instruction is normally what we call a function.

The functions do all the hard work in Clojure.

print-str, + and forward are all functions.

When these functions get run, they return a some type of value.

Clojure functions always return a value.

Arguments

Many functions take in arguments which are everything else inside the enclosing parentheses after the function.

print-str takes "Hello, World!" and returns a string.

+ takes 3 and 4, adds them, and returns 7.

The map function takes the inc function and a collection [1 2 3 4 5] as arguments. map takes a value in turn from the collection and applies the inc function on it, returning the result when all values have been processed.

results matching ""

    No results matching ""