3 little clojure functions

Post on 11-Nov-2014

660 views 3 download

Tags:

description

clojure, dev, functions, functional

Transcript of 3 little clojure functions

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

@diego_pacheco

@diego_pacheco

diego-pacheco.blogspot.com

Yes, I’m a geek guy.

(And I like dinosaurs)

github.com/diegopacheco

Respect The REPL

Remember…

Remember…

(NO enterprise java Bullshit PLEASE)

assoc

subs

Dosync (macro)

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

Calc 1

Calc 2

Calc 3

Calc 4

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)

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.

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.

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

DEV

Recommended Books

(pr “Thanks All Folks”)

@diego_pacheco