CLOJURE

JAK CLOJURE CLOJURE CLOJURE
Pascal is for building pyramids – imposing, breathtaking, static structures built by armies pushing heavy blocks into place. Lisp is for building organisms – imposing, breathtaking, dynamic structures built by squads fitting fluctuating myriads of simpler organisms into place.

— Alan J. Perlis,
Structure and Interpretation of Computer Programs

Start

Cel

Jak?

Manipulacja SVG


<path style="fill: #ff0000;">
  ...
</path>
        

REPL

Read-Evaluate-Print Loop

Mapy


{klucz1 wartość1 
 klucz2 wartość2 
 ...
 kluczN wartośćN}
        

Klucze (keywords)


Wektory


Walidacja

Note that these are not hyperlinks; these URIs are used for identification. This is a machine-readable way to say "this is HTML". In particular, software does not usually need to fetch these resources, and certainly does not need to fetch the same one over and over!

— W3C Systems Team Blog

Definiowanie funkcji


(defn funkcja [arg1 ... argN]
  wyrażenie)

(defn times-42 [x]
  (* x 42))
        

Sekwencje

Funkcje wyższego rzędu


(map add-42 [1 2 3])
(42 84 126)

(filter even? (range 10))
(0 2 4 6 8)
        

Funkcje anonimowe


(map (fn [x] (+ x 42)) [1 2 3])
(42 84 126)

(map #(+ % 42) [1 2 3])
(42 84 126)
        

Let


(let [nazwa1 wartość1
      nazwa2 wartość2
      ...
      nazwaN wartośćN]
  wyrażenie)

(let [x 20] (+ x 3))
23
        

Zippery (1)

Zippery (2)


(let [z (zip/vector-zip [3 [4 5]])]
  (-> z down (insert-left 1) root))
[1 3 [4 5]]
        

Zamiast rekurencji ogonowej


(loop [x 10 y 0]
  (if (zero? x)
    y
    (recur (dec x) (+ x y))))
        

CSV

clojure-csv

HTTP: Ring

HTTP jako funkcja
żądanie → odpowiedź

Request


:server-port  :uri
:server-name  :query-string
:remote-addr  :request-method
:scheme       :content-type
:headers      :content-length
:body         :character-encoding
        

Response


:status
:headers
:body
        

Pytania?

Dziękuję za uwagę!


(doseq [you (audience)]
  (thank! you))    
        

http://plblog.danieljanus.pl
http://fablo.pl