Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Clojure's Reference Types
Search
Nate Smith
January 20, 2015
Technology
140
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
98
Clojure Through Ruby Coloured Glasses
nwjsmith
1
190
Refactoring to Middleware
nwjsmith
2
220
CAP Theorem
nwjsmith
2
180
Other Decks in Technology
See All in Technology
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
170
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
1.9k
LocalStack を使ったサーバーレスアプリケーション開発 / Serverless Development with LocalStack
kakakakakku
1
360
使いこなすために知っておきたい Azure SRE Agent アンチパターン
torumakabe
2
450
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
0
140
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
350
ビジネスを止めない技術的負債の返済のための戦略とその手法 - 技術的負債と向き合う / Complexity and Simplicity
soudai
PRO
3
680
Incremental HTTP
kazuho
5
2.1k
継続的なAIコスト最適化
bgpat
1
280
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
220
Cognition AI Japan - ウェビナー2_テストQA_運用監視
cogakira
0
120
Running Kotlin + Quarkus with Lambda
nealle
0
160
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
1
560
Are puppies a ranking factor?
jonoalderson
2
4k
So, you think you're a good person
axbom
PRO
2
2.2k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
560
Between Models and Reality
mayunak
4
490
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
270
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
260
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
Scaling GitHub
holman
464
140k
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