(fun clojure)

Post on 06-May-2015

935 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

(apply fun clojure)Geek<->Geek

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

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

Path to Clojure

Formal introduction

Clojure

Clojure philosophy

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

Language basics

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”

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

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

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}

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))))

STM

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

Mutation primitives and concurreny

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

REF Agent Atom Var

Coordinated ✓

Asynchronous ✓

Retriable ✓ ✓

Thread-local ✓

Interoperability

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

Bla-bla, it’s all here

Little reality check

Ugly side and why it’s okay.

- clumzy lazyness- dynamic typing- microbenchmarks

- exception vomit- young ecosystem- lack of good docs

Vox Populi

survey by Chas Emerick

3 most important graphs

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

Quil - processing in Clojure

Overtone - rock on REPL

checkout: meta-ex.com

Incanter - hammer your statistics

Datomic

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)

Hands on REPL

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)

Editors

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

Sample workflow

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

> lein deps> lein repl

tryClojureonline REPL http://tryclj.com/

download Android App

homebrew

lein-try

Shortcuts to Clojure

Demos

On REPL

File IO

API access

Quil

Demo 1 - FoxyEye

Demo 1 - FoxyEye

ExperimentalFirefox OSAppClojureClojureScript

Sources

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/

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

Thank you!

top related