(fun clojure)

43

Upload: timo-sulg

Post on 06-May-2015

934 views

Category:

Technology


1 download

DESCRIPTION

My talk at Geek2Geek, where i gave little talk about first steps into Clojure.

TRANSCRIPT

Page 1: (Fun clojure)
Page 2: (Fun clojure)

(apply fun clojure)Geek<->Geek

Page 3: (Fun clojure)

{:name “Timo Sulg” :from “VersionEye”

:at “Geek2Geek”:twitter “@timgluz”}

Page 4: (Fun clojure)

Path to Clojure

Page 5: (Fun clojure)

Formal introduction

Page 6: (Fun clojure)

Clojure

Page 7: (Fun clojure)

Clojure philosophy

source: “The Joy of Clojure”, M.Fogus

Page 8: (Fun clojure)

Language basics

Page 9: (Fun clojure)

Primitives

integers 42, -107, 0x7f, 2r01011001, 32r3V

floats 1.17, -2. , 366e7, 32e-14, 10.7e-3

rationals 22/2 , -7/22 , -103/4

symbols sym + def

keywords :2 :chumby :?

characters \a \\ \space \0042

strings “this is string”

Page 10: (Fun clojure)

Functions

+ inplace functions#(say %1)

+ anonymous functions(fn [x y] (+ x y))

+ named-functions (def add2 (fn [x y] (+ x y)))(defn add2 (+ x y))(defn addN

([] 0) ([x] x) ([x y] (+ x y)))) ;; function arity

Page 11: (Fun clojure)

Seq(uence)

“It is better to have 100 functions operate on one data structure than to have 10 function operate on 10 data structures”,

Alan J. Perlis

Page 12: (Fun clojure)

Clojure Collections

+ Lists(:yankee :hotel :foxtrot)

+ Vectors[1 :a 2 :b] (vector 1 2 4) (apply vector ‘(1 3 4))

+ Hash-maps{1 :one, 2 :two 3 :three}

+ Sets#{:first :second :third}

Page 13: (Fun clojure)

Loops

high-order functions (map sqr [1 2 3])

(reduce + [1,2,3])

list comprehensions (for [word [“the” “quick” “tutorial”]]

(format “<p>%s</p>” word))

recursion(defn print-down-from [x]

(when (?pos x)(println x)(recur (dec x))))

Page 14: (Fun clojure)

STM

“STM - what, why, how” - http://sw1nn.com/blog/2012/04/11/clojure-stm-what-why-how/

Page 15: (Fun clojure)

Mutation primitives and concurreny

“Refs and transactions, STM” http://clojure.org/refs

REF Agent Atom Var

Coordinated ✓

Asynchronous ✓

Retriable ✓ ✓

Thread-local ✓

Page 16: (Fun clojure)

Interoperability

“Programming Clojure”, C.Emerick, p.44

Page 17: (Fun clojure)

Bla-bla, it’s all here

Page 18: (Fun clojure)

Little reality check

Page 19: (Fun clojure)
Page 20: (Fun clojure)

Ugly side and why it’s okay.

- clumzy lazyness- dynamic typing- microbenchmarks

- exception vomit- young ecosystem- lack of good docs

Page 21: (Fun clojure)

Vox Populi

survey by Chas Emerick

3 most important graphs

Results: http://java.dzone.com/articles/results-2012-state-clojure

Page 22: (Fun clojure)
Page 23: (Fun clojure)
Page 24: (Fun clojure)
Page 25: (Fun clojure)
Page 26: (Fun clojure)

Quil - processing in Clojure

Page 27: (Fun clojure)

Overtone - rock on REPL

checkout: meta-ex.com

Page 28: (Fun clojure)

Incanter - hammer your statistics

Page 29: (Fun clojure)

Datomic

Page 30: (Fun clojure)

Other Rockstars

data processing (Storm, Cascalog, Incanter, Core.logic)data pipelining

(Aleph, Plumbing, Core/async)Web

(Hiccup, Ring, Dommy, Luminus, Pedestal)Graphs

(d2, quil)Music

(overtone, checkout meta-ex.com)

Page 31: (Fun clojure)

Hands on REPL

Page 32: (Fun clojure)

Installing lein

1. Download the lein script (or on Windows lein.bat)

2. Place it on your $PATH (eg. ~/bin)

3. Set it to be executable (chmod a+x ~/bin/lein)

Page 33: (Fun clojure)

Editors

Clooj / Catnipps: there’s plugins for all mainstream IDEs

Page 34: (Fun clojure)

Sample workflow

> lein new geek2geek> cd & geek2geek > ls -a> vim project.clj

> lein deps> lein repl

Page 35: (Fun clojure)

tryClojureonline REPL http://tryclj.com/

download Android App

homebrew

lein-try

Shortcuts to Clojure

Page 36: (Fun clojure)

Demos

On REPL

File IO

API access

Quil

Page 37: (Fun clojure)

Demo 1 - FoxyEye

Page 38: (Fun clojure)

Demo 1 - FoxyEye

ExperimentalFirefox OSAppClojureClojureScript

Page 39: (Fun clojure)

Sources

Page 40: (Fun clojure)

Books

1. “Clojure Programming” by Chas Emerickhttp://shop.oreilly.com/product/0636920013754.do

2. “Joy of Clojure”, by Micheal Fogus & Chris Houserhttp://shop.oreilly.com/product/0636920013754.do

3. Clojure Cookbook, by communityhttp://clojure-cookbook.com/

Page 41: (Fun clojure)

Websites

quick ref: http://clojuredocs.org/quickref/Clojure%20Core

Cheetsheet:http://clojure.org/cheatsheet

Clojure page on VersionEye: http://versioneye.com/clojure

Talks:http://www.youtube.com/user/clojuretv

Page 43: (Fun clojure)

Thank you!