Racket Cheat Sheet, Exercises of Advanced Computer Programming

Racket Cheat Sheet. Version 7.4. Jay McCarthy. August 4, 2019. EssentialsSitesmain download docs gitCommunitypackages users@ dev@ irc.

Typology: Exercises

2021/2022

Uploaded on 08/05/2022

dirk88
dirk88 🇧🇪

4.4

(222)

3.1K documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Racket Cheat Sheet
Version 7.4
Jay McCarthy
August 4, 2019
EssentialsSitesmain download docs gitCommunitypackages users@ dev@ irc
slack twitterRunningPut #lang racket "Hello, world!" in hello.rkt
and run racket hello.rktPrimitivesNumbersLiteralsinteger 1rational 1/2
complex 1+2i floating 3.14 double 6.02e+23 hex #x29 octal #o32 binary
#b010101Arithmetic+ - * / quotient remainder modulo add1 sub1 max min
round floor ceiling sqrt expt exp log sin ... atanCompare= < <= >
>=Bitwisebitwise-ior bitwise-and bitwise-xor bitwise-not arithmetic-
shift integer-lengthFormatnumber->string string->number real->decimal-
stringTestnumber? complex? ... exact-nonnegative-integer? ... zero?
positive? negative? even? odd? exact? inexact?MiscrandomMatch Pattern(?
number? n)42StringsLiterals"Racket" quoting "a \" approaches!" unicode
"λx:(µα.αÑα).xx"Createmake-string string string-append build-string
string-joinObservestring-length string-ref substring string-split
in-stringModifystring-downcase string-upcase string-trimTeststring?
string=? string<=? string-ci<=?Regexp#rx"a|b" #rx"^c(a|d)+r$" regexp-
quote regexp-match regexp-split regexp-replace regexp-replace*Match
Pattern(?string? s)"Banana?"BytesLiterals#"rawbytes\0"Createmake-
bytes bytesNumbersinteger->integer-bytes real->floating-point-
bytesObservebytes-length bytes-ref subbytes in-bytesModifybytes-set!
bytes-copy! bytes-fill!Conversionbytes->string/utf-8
string->bytes/utf-8Testbytes? bytes=?Match Pattern(?bytes? b)#"0xDEAD-
BEEF"OtherBooleans#t #f not equal?Characters#\a #\tab #\λchar? char-
>integer integer->char char<=? ... char-alphabetic? ...Symbols'Racket
symbol? eq? string->symbol gensymBoxesbox? box unbox set-box!
box-cas!Proceduresprocedure? apply compose compose1 keyword-apply
procedure-rename procedure-arity curry arity-includes?Voidvoid?
voidUndefinedundefinedDataListsCreateempty list list* build-list
for/listObserveempty? list? pair? length list-ref member count argmin
argmaxUseappend reverse map andmap ormap foldr in-listModifyfilter
remove ... sort take drop split-at partition remove-duplicates
shuffleMatch Pattern(list a b c ) (list* a b more ) (list top more
1
pf3
pf4

Partial preview of the text

Download Racket Cheat Sheet and more Exercises Advanced Computer Programming in PDF only on Docsity!

Racket Cheat Sheet

Version 7.

Jay McCarthy

August 4, 2019

EssentialsSitesmain download docs gitCommunitypackages users@ dev@ irc slack twitterRunningPut #lang racket "Hello, world!" in hello.rkt and run racket hello.rktPrimitivesNumbersLiteralsinteger 1 rational 1/ complex 1+2i floating 3.14 double 6.02e+23 hex #x29 octal #o32 binary #b010101Arithmetic+ - * / quotient remainder modulo add1 sub1 max min round floor ceiling sqrt expt exp log sin ... atanCompare= < <= >

=Bitwisebitwise-ior bitwise-and bitwise-xor bitwise-not arithmetic- shift integer-lengthFormatnumber->string string->number real->decimal- stringTestnumber? complex? ... exact-nonnegative-integer? ... zero? positive? negative? even? odd? exact? inexact?MiscrandomMatch Pattern(? number? n) 42StringsLiterals"Racket" quoting "a " approaches!" unicode "λx:(μα.αÑα).xx"Createmake-string string string-append build-string string-joinObservestring-length string-ref substring string-split in-stringModifystring-downcase string-upcase string-trimTeststring? string=? string<=? string-ci<=?Regexp#rx"a|b" #rx"^c(a|d)+r$" regexp- quote regexp-match regexp-split regexp-replace regexp-replace*Match Pattern(? string? s) "Banana?"BytesLiterals#"rawbytes\0"Createmake- bytes bytesNumbersinteger->integer-bytes real->floating-point- bytesObservebytes-length bytes-ref subbytes in-bytesModifybytes-set! bytes-copy! bytes-fill!Conversionbytes->string/utf- string->bytes/utf-8Testbytes? bytes=?Match Pattern(? bytes? b) #"0xDEAD- BEEF"OtherBooleans#t #f not equal?Characters#\a #\tab #\λ char? char- integer integer->char char<=? ... char-alphabetic? ...Symbols'Racket symbol? eq? string->symbol gensymBoxesbox? box unbox set-box!

box-cas!Proceduresprocedure? apply compose compose1 keyword-apply procedure-rename procedure-arity curry arity-includes?Voidvoid? voidUndefinedundefinedDataListsCreateempty list list* build-list for/listObserveempty? list? pair? length list-ref member count argmin argmaxUseappend reverse map andmap ormap foldr in-listModifyfilter remove ... sort take drop split-at partition remove-duplicates shuffleMatch Pattern(list a b c ) (list* a b more ) (list top more

...)Immutable HashCreatehash hasheqObservehash? hash-ref hash-has-key? hash-count in-hash in-hash-keys in-hash-valuesModifyhash-set hash- update hash-removeVectorCreatebuild-vector vector make-vector list-

vectorObservevector? vector-length vector-ref in-vectorModifyvector- set! vector-fill! vector-copy! vector-map!Match Pattern(vector x y z ) (vector x y calabi–yau ...)StreamsCreatestream stream* empty- streamObservestream-empty? stream-first stream-rest in-streamMutable HashCreatemake-hash make-hasheqObservehash? hash-ref hash-has-key? hash-count in-hash in-hash-keys in-hash-valuesModifyhash-set! hash- ref! hash-update! hash-remove!SystemsInput/OutputFormatting„a „v „s „e „r pretty-formatInputread read-bytes peek-byteOutputwrite write- bytes display displayln pretty-printPorts and Fileswith-input-from- file with-output-to-file flush-output file-position make-pipe with- output-to-string with-input-from-string port->bytes port->lines ...FilesPathsbuild-path bytes->path path->bytes path-replace-suffix ...Filesfile-exists? rename-file-or-directory copy-directory/files current-directory make-directory delete-directory/files directory- list filesystem-change-evt file->bytes file->lines make-temporary- fileMiscellaneousTimecurrent-seconds current-inexact-milliseconds date- string date-display-formatCommand-Line Parsingcommand-lineFFIffi- lib _uint32 ... _fun malloc freeNetworkingTCPtcp-listen tcp-connect tcp-accept tcp-closeHTTPhttp-conn http-conn-open! http-conn-send! http-conn-recv! http-conn-sendrecv! http-sendrecvURLsstring->url url->string url-queryEmailsmtp-send-message imap-connect ...JSONwrite- json read-jsonXMLread-xml write-xml write-xexprDatabasespostgresql- connect mysql-connect sqlite3-connect query-exec query-rows pre- pare start-transaction ...SecurityCustodiansmake-custodian custodian- shutdown-all current-custodianSandboxesmake-evaluator make-module- evaluatorConcurrencyThreadsthread kill-thread thread-wait make-thread- groupEventssync choice-evt wrap-evt handle-evt alarm-evt ...Channelsmake- channel channel-get channel-putSemaphoresmake-semaphore semaphore-post semaphore-waitAsync Channelsmake-async-channel async-channel-get async- channel-putParallelismFuturesfuture touch processor-count make-fsemaphore ...Placesdynamic-place place place-wait place-wait place-channel ...Pro- cessessubprocess systemSyntax (Beginner)BasicsModules(module+ main body ...) (module+ test body ...) (require mod-path ) (provide id )S-expressionsquote '(a b c) quasiquote unquote `(1 2 ,(+ 1 2))Procedure Applications(fn arg1 arg2 ) keyword args (fn arg1 #:key arg2 ) (apply fn arg1 (list arg2 ))Procedures(lambda (x) x) (λ (x) x) (λ (x [opt 1]) (+ x opt)) (λ (x #:req key) (+ x key)) (λ (x #:opt [key 1]) (+ x key))Binding(let ([x 1] [y 2]) (+ x y)) (let ([x 1] [x (+ x 1)]) x)Conditionals(if (zero? x) 0 (/ 1 x)) (cond [(even? x ) 0] [(odd? x ) 1]

parser cfg-parserToolsPackagesInspectionraco pkg showFindingpkgs.racket- lang.orgInstallingraco pkg installUpdatingraco pkg updateRemovingraco pkg removeMiscellaneousCompilingraco make program.rktTestingraco test program.rkt a-directoryBuilding Executablesraco exe program.rktExtending DrRacketdrracket:language:simple-module-based-language->module-based- language-mixinSlidesslide standard-fish code