Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clojure's Reference Types
Search
Nate Smith
January 20, 2015
Technology
0
130
Clojure's Reference Types
A short introduction to Clojure's reference types that I gave to the Clojure Toronto meetup.
Nate Smith
January 20, 2015
Tweet
Share
More Decks by Nate Smith
See All by Nate Smith
Building Unbreakable Software
nwjsmith
0
81
Clojure Through Ruby Coloured Glasses
nwjsmith
1
180
Refactoring to Middleware
nwjsmith
2
220
CAP Theorem
nwjsmith
2
150
Other Decks in Technology
See All in Technology
GSIが複数キー対応したことで、俺達はいったい何が嬉しいのか?
smt7174
3
140
What happened to RubyGems and what can we learn?
mikemcquaid
0
250
ZOZOにおけるAI活用の現在 ~開発組織全体での取り組みと試行錯誤~
zozotech
PRO
5
4.9k
ファインディの横断SREがTakumi byGMOと取り組む、セキュリティと開発スピードの両立
rvirus0817
1
1.2k
Frontier Agents (Kiro autonomous agent / AWS Security Agent / AWS DevOps Agent) の紹介
msysh
3
150
GCASアップデート(202510-202601)
techniczna
0
250
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
200
Bedrock PolicyでAmazon Bedrock Guardrails利用を強制してみた
yuu551
0
110
仕様書駆動AI開発の実践: Issue→Skill→PRテンプレで 再現性を作る
knishioka
2
590
AzureでのIaC - Bicep? Terraform? それ早く言ってよ会議
torumakabe
1
380
AWS Network Firewall Proxyを触ってみた
nagisa53
0
130
Context Engineeringの取り組み
nutslove
0
290
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
0
2k
A better future with KSS
kneath
240
18k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
170
The World Runs on Bad Software
bkeepers
PRO
72
12k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
So, you think you're a good person
axbom
PRO
2
1.9k
Embracing the Ebb and Flow
colly
88
5k
The agentic SEO stack - context over prompts
schlessera
0
630
Java REST API Framework Comparison - PWX 2021
mraible
34
9.1k
Documentation Writing (for coders)
carmenintech
77
5.2k
Practical Orchestrator
shlominoach
191
11k
Transcript
NATE SMITH @nwjsmith theinternate.com
Clojure's REFERENCE TYPES
ATOMS AGENTS REFS
VARS
(def wayne-gretzky {:number 99 :position "C" :goals 45}) wayne-gretzky ;;
=> {:number 99 :position "C" :goals 45}
wayne_gretzky = { number: 99, position: "C", goals: 45 }
(def wayne-gretzky {:number 99 :position "C" :goals 45}) (defn score
[player] (update-in player [:goals] inc))
wayne-gretzky ;; => {:number 99 :position "C" :goals 45} (score
wayne-gretzky) ;; => {:number 99 :position "C" :goals 46}
wayne-gretzky ;; => {:number 99 :position "C" :goals 45} (score
wayne-gretzky) ;; => {:number 99 :position "C" :goals 46} wayne-gretzky ;; => {:number 99 :position "C" :goals 45}
IDENTITY and STATE
None
None
None
None
IDENTITY ≠ STATE
None
None
BOTH MICHAEL JACKSON
WHAT CHANGED?
HIS IDENTITY
STATE IS IMMUTABLE, IDENTITIES CHANGE
wayne_gretzky = { number: 99, position: "C", goals: 45 }
wayne_gretzky[:goals] += 1 wayne_gretzky # => { number: 99, position: "C", goals: 46 }
ATOMS AGENTS REFS
ATOMS
(def atomic-wayne-gretzky (atom {:position "C" :number 99 :goals 0})) (deref
atomic-wayne-gretzky) ;; => {:position "C" :number 99 :goals 0} @atomic-wayne-gretzky ;; => {:position "C" :number 99 :goals 0}
(def atomic-wayne-gretzky (atom {:position "C" :number 99 :goals 0})) (dothreads!
(fn [] (swap! atomic-wayne-gretzky score)) :threads 100 :times 100) @atomic-wayne-gretzky ;; => {:position "C" :number 99 :goals 10000}
AGENTS
(def agent-gretzky (agent {:position "C" :number 99 :goals 0})) @agent-gretzky
;; => {:position "C" :number 99 :goals 0}
(defn score-slowly [player] (Thread/sleep 5000) (update-in player [:goals] inc)) (send
agent-gretzky score-slowly) @agent-gretzky ;; => {:position "C" :number 99 :goals 0} @agent-gretzky ;; => {:position "C" :number 99 :goals 0} ;; 5 seconds later... @agent-gretzky ;; => {:position "C" :number 99 :goals 1}
REFS
THEY'RE FRIGGIN' MAGIC
(def gretzky-curr (ref {:position "C" :number 99 :goals 0})) (def
gretzky-prev (ref @gretzky-curr)) @gretzky-curr ;; => {:position "C" :number 99 :goals 0} @gretzky-prev ;; => {:position "C" :number 99 :goals 0}
(dothreads! (fn [] (dosync (ref-set gretzky-prev @gretzky-curr) (alter gretzky-curr score)))
:threads 100 :times 100) @gretzky-prev ;; => {:position "C" :number 99 :goals 9999} @gretzky-curr ;; => {:position "C" :number 99 :goals 10000}
Atoms: independent, synchronous Agents: independent, asynchronous Refs: coordinated, synchronous
THANKS!
None