May 2018
Beginner to intermediate
290 pages
6h 43m
English
We’ll begin our exploration of local naming in Clojure by imagining that our book store runs periodic specials. Every now and then we offer our customers a percentage discount on their book purchases. Unfortunately, our deal does come with some fine print: there’s a minimum charge for each order that overrides the discount.
Armed with our hard-won knowledge of functions and if, it’s not difficult to turn this discount policy into Clojure code:
| | (defn compute-discount-amount [amount discount-percent min-charge] |
| | (if (> (* amount (- 1.0 discount-percent)) min-charge) |
| | (* amount (- 1.0 discount-percent)) |
| | min-charge)) |
As a bit of everyday software engineering, compute-discount-amount ...
Read now
Unlock full access