SlideShare a Scribd company logo
1 of 11
Download to read offline
Clojure Example Functions

                        ilegra - LDC
By Jackson dos Santos
odd
user =>(odd? 1)
true
odd

The same thing in java
(2 % 1) ? true : false
even
user => (even? 2)
true
even
The same thing in java
(2 % 2) ? true : false
dotimes
user => (dotimes [i 2] (println i))
0
1
2
dotimes
The same thing in java
Vector v = new Vector();
v.add(0);
v.add(1);
v.add(2);
for (int i = 0; i < v.size(); i++) {
System.out.println(v.get(i));
}
Car tax function
(defn verify_car_speed [car]
    (if (> 100 (get car :cur-speed)) true
        (do
            (def extraTax (* (- (get car :cur-speed) 100) 20))
            (assoc car :tax (+ extraTax 10))
        )
    )
)
Car tax tests
(deftest test-car-speed-with-less-than-100
  (def carToTest (struct car "FUCA" "PASSANGER" 99 1))
  (def carReturned (verify_car_speed carToTest))
  (is (= nil (get carReturned :tax)))
)

(deftest test-car-speed-with-more-than-100
  (def carToTest (struct car "FUCA" "PASSANGER" 101 1))
  (def carReturned (verify_car_speed carToTest))
  (is (= 30 (get carReturned :tax)))
)
Bank functions
(defn bank-deposit [bank-account value-to-deposit]
  (def value-to-credit (+ (get @bank-account :value) value-to-deposit))
  (dosync
    (ref-set bank-account (assoc @bank-account :value value-to-credit))
  )
)

(defn bank-withdraw[bank-account value-to-withdraw]
  (def value-to-dec (- (get @bank-account :value) value-to-withdraw))
  (dosync
    (ref-set bank-account (assoc @bank-account :value value-to-dec))
  )
)

(defn bank-assesment[bank-account]
  (str "Client " (get @bank-account :name)" has " (get @bank-account :value) " in his account")
)
Bank tests
(deftest test-deposit-100
  (def client-rich (ref (struct bank-account "Eike Batista" 100.02M)))
  (bank-deposit client-rich 100)
  (is (= 200.02 (get @client-rich :value)))
)

(deftest test-withdraw-99.03
  (def client-poor (ref (struct bank-account "Jackson" 224.07M)))
  (bank-withdraw client-poor 99.03M)
  (is (= 125.04 (get @client-poor :value)))
)

(deftest test-assesment
  (def rich-client (ref (struct bank-account "Silvio Santos" 1000)))
  (bank-deposit rich-client 100)
  (is (= "Client Silvio Santos has 1100 in his account" (bank-assesment rich-client)))
)

More Related Content

What's hot

Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventas
DAYANA RETO
ย 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
Kris Kowal
ย 

What's hot (19)

Detect Negative and Positive sentiment in user reviews using python word2vec ...
Detect Negative and Positive sentiment in user reviews using python word2vec ...Detect Negative and Positive sentiment in user reviews using python word2vec ...
Detect Negative and Positive sentiment in user reviews using python word2vec ...
ย 
The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181
ย 
Empolyee deatils in java
Empolyee deatils in javaEmpolyee deatils in java
Empolyee deatils in java
ย 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
ย 
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVERINSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
ย 
Informatics Practices/ Information Practices Project (IP Project Class 12)
Informatics Practices/ Information Practices Project (IP Project Class 12)Informatics Practices/ Information Practices Project (IP Project Class 12)
Informatics Practices/ Information Practices Project (IP Project Class 12)
ย 
LINQ Internals - STLDODN
LINQ Internals - STLDODNLINQ Internals - STLDODN
LINQ Internals - STLDODN
ย 
Clojure functions 3
Clojure functions 3Clojure functions 3
Clojure functions 3
ย 
Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventas
ย 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
ย 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragment
ย 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
ย 
Using Redux-Saga for Handling Side Effects
Using Redux-Saga for Handling Side EffectsUsing Redux-Saga for Handling Side Effects
Using Redux-Saga for Handling Side Effects
ย 
The redux saga begins
The redux saga beginsThe redux saga begins
The redux saga begins
ย 
Higher-Order Components โ€” Ilya Gelman
Higher-Order Components โ€” Ilya GelmanHigher-Order Components โ€” Ilya Gelman
Higher-Order Components โ€” Ilya Gelman
ย 
04 2 ์˜ค๋ฒ„ํ”Œ๋กœ ์ƒ์ˆ˜ ๋งคํฌ๋กœ
04 2 ์˜ค๋ฒ„ํ”Œ๋กœ ์ƒ์ˆ˜ ๋งคํฌ๋กœ04 2 ์˜ค๋ฒ„ํ”Œ๋กœ ์ƒ์ˆ˜ ๋งคํฌ๋กœ
04 2 ์˜ค๋ฒ„ํ”Œ๋กœ ์ƒ์ˆ˜ ๋งคํฌ๋กœ
ย 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
ย 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order function
ย 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
ย 

Similar to Clojure functions examples

Unit test candidate solutions
Unit test candidate solutionsUnit test candidate solutions
Unit test candidate solutions
benewu
ย 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
ย 
Phoenix for laravel developers
Phoenix for laravel developersPhoenix for laravel developers
Phoenix for laravel developers
Luiz Messias
ย 
Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...
Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...
Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...
Databricks
ย 
Clojure in the Wild
Clojure in the WildClojure in the Wild
Clojure in the Wild
suitzero
ย 

Similar to Clojure functions examples (20)

Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
ย 
Scala meetup
Scala meetupScala meetup
Scala meetup
ย 
Clojure functions midje
Clojure functions midjeClojure functions midje
Clojure functions midje
ย 
Unit test candidate solutions
Unit test candidate solutionsUnit test candidate solutions
Unit test candidate solutions
ย 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
ย 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
ย 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
ย 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84
ย 
Django - sql alchemy - jquery
Django - sql alchemy - jqueryDjango - sql alchemy - jquery
Django - sql alchemy - jquery
ย 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
ย 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212
ย 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }
ย 
Phoenix for laravel developers
Phoenix for laravel developersPhoenix for laravel developers
Phoenix for laravel developers
ย 
Testing in those hard to reach places
Testing in those hard to reach placesTesting in those hard to reach places
Testing in those hard to reach places
ย 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
ย 
Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...
Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...
Scaling Up: How Switching to Apache Spark Improved Performance, Realizability...
ย 
Scaling up data science applications
Scaling up data science applicationsScaling up data science applications
Scaling up data science applications
ย 
Scott Anderson [InfluxData] | InfluxDB Tasks โ€“ Beyond Downsampling | InfluxDa...
Scott Anderson [InfluxData] | InfluxDB Tasks โ€“ Beyond Downsampling | InfluxDa...Scott Anderson [InfluxData] | InfluxDB Tasks โ€“ Beyond Downsampling | InfluxDa...
Scott Anderson [InfluxData] | InfluxDB Tasks โ€“ Beyond Downsampling | InfluxDa...
ย 
Clojure in the Wild
Clojure in the WildClojure in the Wild
Clojure in the Wild
ย 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
ย 

More from Jackson dos Santos Olveira

More from Jackson dos Santos Olveira (20)

AWS Control Tower
AWS Control TowerAWS Control Tower
AWS Control Tower
ย 
Netty training
Netty trainingNetty training
Netty training
ย 
An introduction to predictionIO
An introduction to predictionIOAn introduction to predictionIO
An introduction to predictionIO
ย 
Introduction to HashiCorp Consul
Introduction to HashiCorp ConsulIntroduction to HashiCorp Consul
Introduction to HashiCorp Consul
ย 
Apache mahout - introduction
Apache mahout - introductionApache mahout - introduction
Apache mahout - introduction
ย 
Managing computational resources with Apache Mesos
Managing computational resources with Apache MesosManaging computational resources with Apache Mesos
Managing computational resources with Apache Mesos
ย 
Introduction to CFEngine
Introduction to CFEngineIntroduction to CFEngine
Introduction to CFEngine
ย 
DBC Principles
DBC PrinciplesDBC Principles
DBC Principles
ย 
Racket
RacketRacket
Racket
ย 
Jboss Teiid - The data you have on the place you need
Jboss Teiid - The data you have on the place you needJboss Teiid - The data you have on the place you need
Jboss Teiid - The data you have on the place you need
ย 
Apache PIG introduction
Apache PIG introductionApache PIG introduction
Apache PIG introduction
ย 
Jboss AS7 New Main Features
Jboss AS7 New Main FeaturesJboss AS7 New Main Features
Jboss AS7 New Main Features
ย 
Celery Introduction
Celery IntroductionCelery Introduction
Celery Introduction
ย 
Solid
SolidSolid
Solid
ย 
Aurinko
AurinkoAurinko
Aurinko
ย 
Gcontract
GcontractGcontract
Gcontract
ย 
Ocaml
OcamlOcaml
Ocaml
ย 
Ocaml
OcamlOcaml
Ocaml
ย 
Haskell
HaskellHaskell
Haskell
ย 
Elastic search introduction
Elastic search introductionElastic search introduction
Elastic search introduction
ย 

Recently uploaded

VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...
dipikadinghjn ( Why You Choose Us? ) Escorts
ย 
VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...
dipikadinghjn ( Why You Choose Us? ) Escorts
ย 
VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
dipikadinghjn ( Why You Choose Us? ) Escorts
ย 
( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...
dipikadinghjn ( Why You Choose Us? ) Escorts
ย 
Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7
Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7
Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 

Recently uploaded (20)

VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday ...
ย 
The Economic History of the U.S. Lecture 21.pdf
The Economic History of the U.S. Lecture 21.pdfThe Economic History of the U.S. Lecture 21.pdf
The Economic History of the U.S. Lecture 21.pdf
ย 
The Economic History of the U.S. Lecture 18.pdf
The Economic History of the U.S. Lecture 18.pdfThe Economic History of the U.S. Lecture 18.pdf
The Economic History of the U.S. Lecture 18.pdf
ย 
The Economic History of the U.S. Lecture 20.pdf
The Economic History of the U.S. Lecture 20.pdfThe Economic History of the U.S. Lecture 20.pdf
The Economic History of the U.S. Lecture 20.pdf
ย 
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Koregaon Park Call Me 7737669865 Budget Friendly No Advance Booking
ย 
VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West ๐ŸŒน 9920725232 ( Call Me ) Mumbai Esc...
ย 
Booking open Available Pune Call Girls Shivane 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Shivane  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Shivane  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Shivane 6297143586 Call Hot Indian Gi...
ย 
The Economic History of the U.S. Lecture 19.pdf
The Economic History of the U.S. Lecture 19.pdfThe Economic History of the U.S. Lecture 19.pdf
The Economic History of the U.S. Lecture 19.pdf
ย 
VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai ๐Ÿ’ง 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
ย 
Booking open Available Pune Call Girls Wadgaon Sheri 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Wadgaon Sheri  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Wadgaon Sheri  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Wadgaon Sheri 6297143586 Call Hot Ind...
ย 
Gurley shaw Theory of Monetary Economics.
Gurley shaw Theory of Monetary Economics.Gurley shaw Theory of Monetary Economics.
Gurley shaw Theory of Monetary Economics.
ย 
Top Rated Pune Call Girls Dighi โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Dighi โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Dighi โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Dighi โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...
ย 
03_Emmanuel Ndiaye_Degroof Petercam.pptx
03_Emmanuel Ndiaye_Degroof Petercam.pptx03_Emmanuel Ndiaye_Degroof Petercam.pptx
03_Emmanuel Ndiaye_Degroof Petercam.pptx
ย 
02_Fabio Colombo_Accenture_MeetupDora&Cybersecurity.pptx
02_Fabio Colombo_Accenture_MeetupDora&Cybersecurity.pptx02_Fabio Colombo_Accenture_MeetupDora&Cybersecurity.pptx
02_Fabio Colombo_Accenture_MeetupDora&Cybersecurity.pptx
ย 
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
ย 
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
ย 
The Economic History of the U.S. Lecture 23.pdf
The Economic History of the U.S. Lecture 23.pdfThe Economic History of the U.S. Lecture 23.pdf
The Economic History of the U.S. Lecture 23.pdf
ย 
( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...
( Jasmin ) Top VIP Escorts Service Dindigul ๐Ÿ’ง 7737669865 ๐Ÿ’ง by Dindigul Call G...
ย 
Vip Call US ๐Ÿ“ž 7738631006 โœ…Call Girls In Sakinaka ( Mumbai )
Vip Call US ๐Ÿ“ž 7738631006 โœ…Call Girls In Sakinaka ( Mumbai )Vip Call US ๐Ÿ“ž 7738631006 โœ…Call Girls In Sakinaka ( Mumbai )
Vip Call US ๐Ÿ“ž 7738631006 โœ…Call Girls In Sakinaka ( Mumbai )
ย 
Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7
Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7
Call Girls in New Ashok Nagar, (delhi) call me [9953056974] escort service 24X7
ย 

Clojure functions examples

  • 1. Clojure Example Functions ilegra - LDC By Jackson dos Santos
  • 3. odd The same thing in java (2 % 1) ? true : false
  • 5. even The same thing in java (2 % 2) ? true : false
  • 6. dotimes user => (dotimes [i 2] (println i)) 0 1 2
  • 7. dotimes The same thing in java Vector v = new Vector(); v.add(0); v.add(1); v.add(2); for (int i = 0; i < v.size(); i++) { System.out.println(v.get(i)); }
  • 8. Car tax function (defn verify_car_speed [car] (if (> 100 (get car :cur-speed)) true (do (def extraTax (* (- (get car :cur-speed) 100) 20)) (assoc car :tax (+ extraTax 10)) ) ) )
  • 9. Car tax tests (deftest test-car-speed-with-less-than-100 (def carToTest (struct car "FUCA" "PASSANGER" 99 1)) (def carReturned (verify_car_speed carToTest)) (is (= nil (get carReturned :tax))) ) (deftest test-car-speed-with-more-than-100 (def carToTest (struct car "FUCA" "PASSANGER" 101 1)) (def carReturned (verify_car_speed carToTest)) (is (= 30 (get carReturned :tax))) )
  • 10. Bank functions (defn bank-deposit [bank-account value-to-deposit] (def value-to-credit (+ (get @bank-account :value) value-to-deposit)) (dosync (ref-set bank-account (assoc @bank-account :value value-to-credit)) ) ) (defn bank-withdraw[bank-account value-to-withdraw] (def value-to-dec (- (get @bank-account :value) value-to-withdraw)) (dosync (ref-set bank-account (assoc @bank-account :value value-to-dec)) ) ) (defn bank-assesment[bank-account] (str "Client " (get @bank-account :name)" has " (get @bank-account :value) " in his account") )
  • 11. Bank tests (deftest test-deposit-100 (def client-rich (ref (struct bank-account "Eike Batista" 100.02M))) (bank-deposit client-rich 100) (is (= 200.02 (get @client-rich :value))) ) (deftest test-withdraw-99.03 (def client-poor (ref (struct bank-account "Jackson" 224.07M))) (bank-withdraw client-poor 99.03M) (is (= 125.04 (get @client-poor :value))) ) (deftest test-assesment (def rich-client (ref (struct bank-account "Silvio Santos" 1000))) (bank-deposit rich-client 100) (is (= "Client Silvio Santos has 1100 in his account" (bank-assesment rich-client))) )