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
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
More Decks by Nate Smith
See All by Nate Smith
Building Unbreakable Software
nwjsmith
0
93
Clojure Through Ruby Coloured Glasses
nwjsmith
1
190
Refactoring to Middleware
nwjsmith
2
220
CAP Theorem
nwjsmith
2
170
Other Decks in Technology
See All in Technology
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
ラジオの科学
frievea
0
290
AI時代の強いチームの作り方
yuukiyo
26
16k
Goでデータパイプラインを作ろう
sansantech
PRO
1
370
TypeScript入門 2026
recruitengineers
PRO
3
520
グローバル基準のSREは、運用現場でどう機能したか:成熟度アセスメントの実践 / SRE NEXT 2026
sorawatanabe
0
170
サイバー捜査員研修(前半)
nomizone
1
1.9k
GitHub CopilotのFinOps- AI CreditのObservabilityと価値を生むためのエージェント設計
yuriemori
0
150
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
230
システム思考で問題に対処する
yussak
0
220
【CEDEC2026】『Relink』を拡張せよ - 『GRANBLUE FANTASY: Relink - Endless Ragnarok』の開発速度と品質を守るCI運用
cygames
PRO
0
140
FPGAが実現する遠方宇宙の高空間分解能天体撮影 -大型地上望遠鏡の視力を補正する「補償光学」とは?-
komei_mt
0
210
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
240
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
550
A better future with KSS
kneath
240
18k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Documentation Writing (for coders)
carmenintech
77
5.4k
Marketing to machines
jonoalderson
1
5.7k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
210
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
480
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1.1k
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