Mercurial > repos > other > SevenLanguagesInSevenWeeks
comparison 6-Clojure/atomcache.clj @ 83:eccc649d49a2
Add Day 2 and Day 3 notes and example code
Clojure STILL doesn't make much sense in lots of places
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 08 Jun 2019 21:23:27 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
82:cf7182bca068 | 83:eccc649d49a2 |
---|---|
1 (defn create_price_list | |
2 [] | |
3 (atom {})) | |
4 | |
5 ; We can't use get because it's part of clojure.core | |
6 (defn get_price | |
7 [prices name] | |
8 (@prices name)) | |
9 | |
10 (defn set_price | |
11 ([prices new_price_map] | |
12 (swap! prices merge new_price_map)) | |
13 ([prices name price] | |
14 (swap! prices assoc name price))) | |
15 | |
16 (def my_shares (create_price_list)) | |
17 (set_price my_shares :GW 299) | |
18 (set_price my_shares :BT 1563) | |
19 (set_price my_shares :ROYALMAIL 29) | |
20 (println (get_price my_shares :BT)) | |
21 (println (get_price my_shares :FOO)) | |
22 (println my_shares) |