/racket-clojure-cheat-sheet

My working notes about Racket and Clojure equivalencies organized as a cheat sheet.

Warning: These are just my personal working notes as I learn Clojure, coming from Racket.

Racket -> Clojure

Given a Racket function, what’s the clojure.core equivalent?

Note: This only includes things with a different name or behavior.

RacketClojureComment
begindo
printprn
displayprint
writewrite
pretty-printpprintclojure.pprint
currypartial
curryrN/A
negatecomplement
andmapevery?
ormapsomeReturns 1st item not #t
(length xs)(count coll)Note: list vs collection.
countN/A ?
appendconcat
(take xs n)(take n coll)Note: args reversed
takeftake-whileNote: args reversed
hashhash-map or {}
sethash-set or #{}
vectorvector or []
unlesswhen-not
#t or truetrue
#f or falsefalse
formatformat~s vs %s. See also: str
fordoseqfor-effect iteration form
for/list etc.forNote: specific vs. generic collections
,~
unquote~
,@~@
unquote-splicing~@
partitionN/AClj partition different
regexp pregexpre-matchesImplicit ^ and $
regexp pregexpre-findNo implicit ^ and $
regexp-match*re-seq
regexp-replace*replace
#rx”\w”#”\w”Clj regexps ~= px (?)
#px”\w”#”\w”Note 2 vs. 1 backslashes
string->symbolsymbol
symbol->stringstr
#:keyword:keyword
keyword->stringname or str
string->keywordkeyword
dict-valuesvals
hash-valuesvals
dict-keyskeys
hash-keyskeys
genericsprotocolsapproximately
(define x (make-parameter 10))(def ^:dynamic x 10)
(parameterize ([x 42]) ___)(binding [x 42] ___)

Clojure -> Racket

See table above.

Also some clojure.core functions are available in #lang rackjure:

FunctionComment
{ k v … … }Dictionary literal.
(dict key)Applicable dictionaries.
(key dict)Applicable dictionaries.
~> and ~>>Threading macros. -> is contract combinator in Racket
#(+ % 2)#λ(+ % 2) – #λ() b/c #() is array literal in Racket
str
swap!
partial

NOTE: The following work with lists not collections.

NOTE: Not yet pushed to public repo.

FunctionComment
partitionClojure partition unlike Racket’s
(take<= xs n)When < n avail, returns ‘() instead of erroring.
juxt
every?Alias for andmap
someormap returns #t or #f. some returns first item or #f

NOTE: Not yet pushed to public repo.

FunctionComment
get
get-in