ClojureScript LogoClojureScript Cheatsheet

Basics

" " Strings

Create"abc"strname
Use(.-length my-str)countgetsubs(clojure.string/)joinescapesplitsplit-linesreplacereplace-firstreverse
Regex#"pattern"re-findre-seqre-matchesre-pattern(clojure.string/)replacereplace-first
Letters(clojure.string/)capitalizelower-caseupper-case
Trim(clojure.string/)trimtrim-newlinetrimltrimr
Testcharstring?(clojure.string/)blank?

Atoms / State

Createatom
Get Value@my-atom → (deref my-atom)
Set Valueswap!reset!compare-and-set!
Watchadd-watchremove-watch
Validatorsset-validator!get-validator

JavaScript Interop

Create Object#js {}js-obj
Create Array#js []arraymake-arrayaclone
Get Property
(.-innerHTML el)
(aget el "innerHTML")
Set Property
(set! (.-innerHTML el) "Hi!")
(aset el "innerHTML" "Hi!")
Delete Propertyjs-delete
Convert Betweenclj->jsjs->clj
Type Testsarray?fn?number?object?string?
Exceptionstrycatchfinallythrow
External Library
(js/alert "Hello world!")
(js/console.log my-obj)
(.html (js/jQuery "#myDiv") "Hi!")

JavaScript Interop

Create Object#js {}js-obj
Create Array#js []arraymake-arrayaclone
Get Property
(.-innerHTML el)
(aget el "innerHTML")
Set Property
(set! (.-innerHTML el) "Hi!")
(aset el "innerHTML" "Hi!")
Delete Propertyjs-delete
Convert Betweenclj->jsjs->clj
Type Testsarray?fn?number?object?string?
Exceptionstrycatchfinallythrow
External Library
(js/alert "Hello world!")
(js/console.log my-obj)
(.html (js/jQuery "#myDiv") "Hi!")

" " Strings

Create"abc"strname
Use(.-length my-str)countgetsubs(clojure.string/)joinescapesplitsplit-linesreplacereplace-firstreverse
Regex#"pattern"re-findre-seqre-matchesre-pattern(clojure.string/)replacereplace-first
Letters(clojure.string/)capitalizelower-caseupper-case
Trim(clojure.string/)trimtrim-newlinetrimltrimr
Testcharstring?(clojure.string/)blank?

Atoms / State

Createatom
Get Value@my-atom → (deref my-atom)
Set Valueswap!reset!compare-and-set!
Watchadd-watchremove-watch
Validatorsset-validator!get-validator

Collections

[ ] Vectors

Create[]vectorvec
Examine
(my-vec idx) → (nth my-vec idx)
getpeek
'Change'assocpopsubvecreplaceconjrseq
Loopmapvfiltervreduce-kv

#{ } Sets

Create#{}sethash-setsorted-setsorted-set-by
Examine
(my-set itm) → (get my-set itm)
contains?
'Change'conjdisj
Set Ops(clojure.set/)uniondifferenceintersectionselect
Test(clojure.set/)subset?superset?

[ ] Vectors

Create[]vectorvec
Examine
(my-vec idx) → (nth my-vec idx)
getpeek
'Change'assocpopsubvecreplaceconjrseq
Loopmapvfiltervreduce-kv

#{ } Sets

Create#{}sethash-setsorted-setsorted-set-by
Examine
(my-set itm) → (get my-set itm)
contains?
'Change'conjdisj
Set Ops(clojure.set/)uniondifferenceintersectionselect
Test(clojure.set/)subset?superset?

Sequences

Create a Seq

From Collectionseqvalskeysrseqsubseqrsubseq
Producer Functionslazy-seqrepeatedlyiterate
From Constantrepeatrange
From Otherre-seqtree-seq
From Sequencekeepkeep-indexed

Misc