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
160
Other Decks in Technology
See All in Technology
開発組織の課題解決を加速するための権限委譲 -する側、される側としての向き合い方-
daitasu
5
280
Claude Cowork Plugins を読む - Skills駆動型業務エージェント設計の実像と構造
knishioka
0
280
kintone開発のプラットフォームエンジニアの紹介
cybozuinsideout
PRO
0
830
バクラクのSREにおけるAgentic AIへの挑戦/Our Journey with Agentic AI
taddy_919
2
1.1k
トップマネジメントとコンピテンシーから考えるエンジニアリングマネジメント
zigorou
4
680
20260305_【白金鉱業】分析者が地理情報を武器にするための軽量なアドホック分析環境
yucho147
1
190
Security Diaries of an Open Source IAM
ahus1
0
200
Ultra Ethernet (UEC) v1.0 仕様概説
markunet
3
220
聲の形にみるアクセシビリティ
tomokusaba
0
120
クラウド時代における一時権限取得
krrrr38
1
170
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.1k
チームメンバー迷わないIaC設計
hayama17
5
4k
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
68
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
140
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
980
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
460
Speed Design
sergeychernyshev
33
1.6k
Building an army of robots
kneath
306
46k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
430
Building the Perfect Custom Keyboard
takai
2
710
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
65
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
100
Building Applications with DynamoDB
mza
96
6.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
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