Racket Cheat Sheet
Essentials
Primitives
Data
Systems
Syntax (Beginner)
Syntax (Intermediate)
Syntactic Abstractions
Tools
8.16

Racket Cheat Sheet🔗ℹ

Jay McCarthy

Essentials
Sitesmaindownloaddocsgit
Communitypackagesusers@dev@ircslacktwitter
RunningPut #langracket"Hello, world!" in hello.rkt and run racket hello.rkt
Primitives
Systems
Syntax (Beginner)

Basics

Modules(module+mainbody...)
(module+testbody...)
(requiremod-path)(provideid)
S-expressionsquote'(abc)quasiquoteunquote`(12,(+12))
Procedure Applications(fnarg1arg2)
keyword args(fnarg1#:keyarg2)
(applyfnarg1(listarg2))
Procedures(lambda(x)x)(λ(x)x)
(λ(x[opt1])(+xopt))
(λ(x#:reqkey)(+xkey))
(λ(x#:opt[key1])(+xkey))
Binding(let([x1][y2])(+xy))
(let*([x1][x(+x1)])x)
Conditionals(if(zero?x)0(/1x))
(cond[(even?x)0][(odd?x)1]
     [else"impossible!"])
andor
Definitions(definex1)
(define(fy)(+xy))
Iterationforfor/listfor*
Blocksbeginwhenunless
Require Sub-formsprefix-inonly-inexcept-inrename-infor-syntaxfor-label...
Provide Sub-formsall-defined-outall-from-outrename-out...contract-out

Structures

Definition(structdillo(weightcolor))
Create(definedanny(dillo17.5'purple))
Observe(dillo?danny)(dillo-weightdanny)(dillo-colordanny)
Modify(struct-copydillodanny([weight18.0]))
Match Pattern(dillowc)

Pattern Matching

Basics(matchvalue[patbody]...)
Definitions(match-definepatvalue)
Patterns(quotedatum)(listlvp...)(list-no-orderpat...)(vectorlvp...)(struct-idpat...)(regexprx-exprpat)(orpat...)(andpat...)(?exprpat...)
Syntax (Intermediate)

Structures

Sub-structures(struct2d(xy))(struct3d2d(z))(2d-x(3d123))
Mutation(structmonster(type[hp#:mutable]))(definehealie(monster'slime10))(set-monster-hp!healie0)
Transparency(structcash($¢)#:transparent)(struct->vector(cash595))
Printing(structnickname[nv]#:methodsgen:custom-write[(define(write-procnnpmode)(fprintfp(nickname-nnn)))])(displayln(nickname"evens"(in-range01002)))
Serialization(structtxn(whowhatwhere)#:prefab)(write(txn"Mustard""Spatula""Observatory"))

Generics

Definitiondefine-generics
Instantiation(structeven-set()#:methodsgen:set[(define(set-member?sti)(even?i))])
Tools

Packages

Inspectionraco pkg show
Findingpkgs.racket-lang.org
Installingraco pkg install
Updatingraco pkg update
Removingraco pkg remove

Miscellaneous

Compilingraco make program.rkt
Testingraco test program.rkt a-directory
Building Executablesraco exe program.rkt
Extending DrRacketdrracket:language:simple-module-based-language->module-based-language-mixin
Slidesslidestandard-fishcode

 
close