Racket Cheat Sheet
来源 http://docs.racket-lang.org/racket-cheat/index.html?q=Racket%20Cheat%20Sheet
Essentials
Sites | |
Community | |
Put "Hello, world!" in hello.rkt and run racket hello.rkt |
Primitives
Numbers
integer 1 rational 1/2 complex 1+2ifloating 3.14 double 6.02e+23 hex #x29 octal #o32 binary #b010101 | |
Arithmetic | ... |
Compare | |
Bitwise | |
Format | |
Test | ... ... |
Misc | |
Match Pattern | (? n) 42 |
Strings
"Racket" quoting "a \" approaches!"unicode "λx:(μα.α→α).xx" | |
Create | |
Observe | |
Modify | |
Test | |
#rx"a|b" #rx"^c(a|d)+r$" | |
Match Pattern | (? s) "Banana?" |
Bytes
#"rawbytes\0" | |
Create | |
Numbers | |
Observe | |
Modify | |
Conversion | |
Test | |
Match Pattern | (? b) #"0xDEADBEEF" |
Other
Booleans | #t #f |
#\a #\tab #\λ ... ... | |
'Racket | |
Boxes | |
Procedures | |
Void | |
Undefined |
Data
Lists
Create | |
Observe | |
Use | |
Modify | ... |
Match Pattern | ( a b c) ( a b more)( top more ...) |
Immutable Hash
Create | |
Observe | |
Modify |
Vector
Create | |
Observe | |
Modify | |
Match Pattern | ( x y z) ( x ycalabi–yau ...) |
Streams
Create | |
Observe |
Mutable Hash
Create | |
Observe | |
Modify |
Systems
Input/Output
Formatting | |
Input | |
Output | |
Ports and Files | ... |
Files
Paths | ... |
Files |
Miscellaneous
Time | |
Command-Line Parsing | |
FFI | ... |
Networking
TCP | |
HTTP | |
URLs | |
... | |
JSON | |
XML | |
Databases | ... |
Security
Custodians | |
Sandboxes |
Concurrency
Threads | |
Events | ... |
Channels | |
Semaphores | |
Async Channels |
Parallelism
Futures | ... |
Places | ... |
Processes |
Syntax (Beginner)
Basics
Modules | ( main body ...) ( test body ...) ( mod-path) (id) |
S-expressions | '(a b c) `(1 2 ,( 1 2)) |
Procedure Applications | (fn arg1 arg2) (fn arg1 #:keyarg2) ( fn arg1 ( arg2)) |
Procedures | ( (x) x) ( (x) x) ( (x [opt 1]) ( x opt)) ( (x #:req key) ( x key)) ( (x #:opt [key 1]) ( xkey)) |
Binding | ( ([x 1] [y 2]) ( x y)) ( ([x 1] [x ( x 1)]) x) |
Conditionals | ( ( x) 0 ( 1 x)) ( [( x) 0] [( x)1] [ "impossible!"]) |
Definitions | ( x 1) ( (f y) ( x y)) |
Iteration | |
Blocks | |
Require Sub-forms | ... |
Provide Sub-forms | ... |
Structures
Definition | ( dillo (weight color)) |
Create | ( danny (dillo 17.5'purple)) |
Observe | (dillo? danny) (dillo-weightdanny) (dillo-color danny) |
Modify | ( dillo danny([weight 18.0])) |
Match Pattern | (dillo w c) |
Pattern Matching
Basics | ( value [pat body] ...) |
Definitions | ( pat value) |
Patterns | (quote datum) ( lvp ...)(list-no-order pat ...) (vectorlvp ...) (struct-id pat ...)(regexp rx-expr pat) (or pat...) (and pat ...) (? expr pat...) |
Syntax (Intermediate)
Basics
Mutation | |
Exceptions | |
Promises | |
Continuations | |
Parameters | |
External Files Needed at Runtime | |
Continuation Marks | |
Multiple Values |
Contracts
Basics | ... |
Functions | |
Application |
Iteration
Sequences | |
Generators |
Structures
Sub-structures | ( 2d (x y)) ( 3d2d (z)) (2d-x (3d 1 2 3)) |
Mutation | ( monster (type [hp#:mutable])) ( healie(monster 'slime 10)) (set-monster-hp! healie 0) |
Transparency | ( cash ($ ¢)#:transparent) ( (cash 5 95)) |
Printing | ( nickname [n v]#:methods [( (write-proc nn pmode) ( p (nickname-nnn)))]) ( (nickname"evens" ( 0 100 2))) |
Serialization | ( txn (who what where)#:prefab) ( (txn"Mustard" "Spatula""Observatory")) |
Generics
Definition | |
Instantiation | ( even-set () #:methods [( (st i) ( i))]) |
Classes
Definition | |
Instantiation | |
Methods | |
Fields | |
Mixins | |
Traits | ... |
Contracts |
Syntactic Abstractions
Definition | |
Templates | |
Parsing ()-Syntax | |
Syntax Objects | ... |
Transformers | ... |
Syntax Parameters | |
Parsing Raw Syntax |
Tools
Inspection | raco pkg show |
Finding | |
Installing | raco pkg install |
Updating | raco pkg update |
Removing | raco pkg remove |
Miscellaneous
raco make program.rkt | |
raco test program.rkt a-directory | |
raco exe program.rkt | |
Extending DrRacket | |
Slides |
================= End