3 little clojure functions

18
2 little (assoc, subs) functions 1 big macro (dosync) …and The Calc Function @diego_pacheco

Upload: diego-pacheco

Post on 11-Nov-2014

660 views

Category:

Technology


3 download

DESCRIPTION

clojure, dev, functions, functional

TRANSCRIPT

Page 1: 3 little clojure functions

2 little (assoc, subs) functions 1 big macro (dosync)…and The Calc Function

@diego_pacheco

Page 2: 3 little clojure functions

@diego_pacheco

diego-pacheco.blogspot.com

Yes, I’m a geek guy.

(And I like dinosaurs)

github.com/diegopacheco

Page 3: 3 little clojure functions

Respect The REPL

Remember…

Page 4: 3 little clojure functions

Remember…

(NO enterprise java Bullshit PLEASE)

Page 5: 3 little clojure functions

assoc

Page 6: 3 little clojure functions

subs

Page 7: 3 little clojure functions

Dosync (macro)

Page 8: 3 little clojure functions

Calc function

(calc "+" 4 5) ;; Result must be : 9(calc "-" 5 1) ;; Result must be : 4(calc "*" 2 3) ;; Result must be : 6(calc "/" 27 3) ;; Result must be : 9

Live DEMO

with REPL

Page 9: 3 little clojure functions

Calc 1

Page 10: 3 little clojure functions

Calc 2

Page 11: 3 little clojure functions

Calc 3

Page 12: 3 little clojure functions

Calc 4

Page 13: 3 little clojure functions

What's Next ?

Homework (all)• 3 new Functions from clojure.core• 4 new functions (exercises) with Unit Testing

• (car-tax [c1 c2 c3 c4])• (bank-deposit ac1 10)• (bank-withdraw ac1 5)• (bank-assessment ac1)

Page 14: 3 little clojure functions

What's Next ?car-tax [vector-of-cars]

Car must be a struct with owner-name, car-type, cur-speed and license-plate. Cars that current speed is grater than 100 pay 10 plus 20 each 1 beyond 100. This func must add the property tax with proper value to the car.

Page 15: 3 little clojure functions

What's Next ?

bank-* [account]

Bank account is a struct with name and value. All changes must be persistent(ref) and you must pass the account in all operations. You must use STM for this functions as well.

Page 16: 3 little clojure functions

What's Next ? (When I back from London…)

DEV

Page 17: 3 little clojure functions

Recommended Books

Page 18: 3 little clojure functions

(pr “Thanks All Folks”)

@diego_pacheco