Introduction






cycognito



clojure logo

Clojure pillars

clojure pillars

Homoiconicity

The syntax of the code is the same as the syntax of the data.
(+
   (* 3 4)
   (* 5 6))
'(a b
  c
  [d.a d.b]
  (e.a
     [e.b.a (e.b.b.a e.b.b.b)]
    e.c)

Functional programming

A function is an entity that receives multiple things and return a thing.

In functional programming the things that functions receive and return are allowed to be functions.

We say that functions are first class citizens.
first class

Function syntax

We create a function with defn

(defn bar
  "bar is a function with documentation"
  [a b c]
  b)

We call a function like this

(bar 1 2 3)

The REPL

Live demo

Data oriented

Instead of representing data with classes, we use maps.

The maps are immutable.

(def m {"a" 1})

(assoc m "b" 2)

m

Online tools and materials

  1. Klipse: Clojure REPL online

  2. ClojureDocs: Documentation with Examples

  3. ClojureScript koans

  4. Clojurians: Slack Channel

  5. Clojureverse forum

  6. Cursive: Clojure IDE based on IntelliJ

tools

Homework

  1. Register to Clojurians: Slack Channel

  2. Post at least 1 question on Clojurians

  3. 10 minutes of ClojureScript koans every day

  4. Solve this exercise

Hello World

  1. Write a function hello-world that receives a name and prints "Hello <name>!" to the console.

  2. Write a function hello-worlds that receives multiple names and prints "Hello <name>!" to the console for each name

  3. Write tests for both functions