annotate 6-Clojure/atomcache.clj @ 103:98be775c533c default tip

An odd "non-determinism" example from StackOverflow It is clever, but doesn't make much sense as to how it gets its results
author IBBoard <dev@ibboard.co.uk>
date Sun, 14 Jul 2019 13:44:13 +0100
parents eccc649d49a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
83
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 (defn create_price_list
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 []
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 (atom {}))
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 ; We can't use get because it's part of clojure.core
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 (defn get_price
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 [prices name]
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 (@prices name))
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 (defn set_price
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 ([prices new_price_map]
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 (swap! prices merge new_price_map))
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 ([prices name price]
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 (swap! prices assoc name price)))
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 (def my_shares (create_price_list))
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 (set_price my_shares :GW 299)
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 (set_price my_shares :BT 1563)
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 (set_price my_shares :ROYALMAIL 29)
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 (println (get_price my_shares :BT))
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 (println (get_price my_shares :FOO))
eccc649d49a2 Add Day 2 and Day 3 notes and example code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 (println my_shares)