May 2018
Beginner to intermediate
290 pages
6h 43m
English
While the ideas behind let aren’t terribly challenging—it binds names to values in a purely local and temporary way—let does have some hidden superpowers, which only become visible when you combine it with fn. To get a glimpse of these hidden powers, imagine our book discounts are customer-dependent. Somewhere we have a map of the user’s name to the discount that user gets:
| | (def user-discounts |
| | {"Nicholas" 0.10 "Jonathan" 0.07 "Felicia" 0.05}) |
We could certainly add some parameters to compute-discount-amount to deal with this:
| | (defn compute-discount-amount [amount user-name user-discounts min-charge] |
| | (let [discount-percent (user-discounts user-name) |
| | discount (* amount discount-percent) |
| | discounted-amount (- amount ... |
Read now
Unlock full access