Racket Cheat Sheet
Racket Cheat Sheet
来源 http://docs.racket-lang.org/racket-cheat/index.html?q=Racket%20Cheat%20Sheet
Essentials
| Sites | main download docs git |
| Community | packages users@ dev@ irc slack twitter |
| Running | Put #lang racket "Hello, world!" in hello.rkt and run racket hello.rkt |
Numbers
| Literals | integer 1 rational 1/2 complex 1+2ifloating 3.14 double 6.02e+23 hex #x29 octal #o32 binary #b010101 |
| Arithmetic | + - * / quotient remaindermodulo add1 sub1 max min roundfloor ceiling sqrt expt exp logsin ... atan |
| Compare | = < <= > >= |
| Bitwise | bitwise-ior bitwise-andbitwise-xor bitwise-notarithmetic-shift integer-length |
| Format | number->string string->numberreal->decimal-string |
| Test | number? complex? ... exact-nonnegative-integer? ... zero?positive? negative? even? odd?exact? inexact? |
| Misc | random |
| Match Pattern | (? number? n) 42 |
Strings
| Literals | "Racket" quoting "a \" approaches!"unicode "λx:(μα.α→α).xx" |
| Create | make-string string string-appendbuild-string string-join |
| Observe | string-length string-refsubstring string-split in-string |
| Modify | string-downcase string-upcasestring-trim |
| Test | string? string=? string<=?string-ci<=? |
| Regexp | #rx"a|b" #rx"^c(a|d)+r$" regexp-quote regexp-match regexp-splitregexp-replace regexp-replace* |
| Match Pattern | (? string? s) "Banana?" |
Bytes
| Literals | #"rawbytes\0" |
| Create | make-bytes bytes |
| Numbers | integer->integer-bytes real->floating-point-bytes |
| Observe | bytes-length bytes-refsubbytes in-bytes |
| Modify | bytes-set! bytes-copy! bytes-fill! |
| Conversion | bytes->string/utf-8 string->bytes/utf-8 |
| Test | bytes? bytes=? |
| Match Pattern | (? bytes? b) #"0xDEADBEEF" |
Other
| Booleans | #t #f not equal? |
| Characters | #\a #\tab #\λ char? char->integer integer->char char<=?... char-alphabetic? ... |
| Symbols | 'Racket symbol? eq? string->symbol gensym |
| Boxes | box? box unbox set-box! box-cas! |
| Procedures | procedure? apply composecompose1 keyword-applyprocedure-rename procedure-arity curry arity-includes? |
| Void | void? void |
| Undefined | undefined |
Lists
| Create | empty list list* build-listfor/list |
| Observe | empty? list? pair? length list-ref member count argmin argmax |
| Use | append reverse map andmap ormapfoldr in-list |
| Modify | filter remove ... sort take dropsplit-at partition remove-duplicates shuffle |
| Match Pattern | (list a b c) (list* a b more)(list top more ...) |
Immutable Hash
| Create | hash hasheq |
| Observe | hash? hash-ref hash-has-key?hash-count in-hash in-hash-keysin-hash-values |
| Modify | hash-set hash-update hash-remove |
Vector
| Create | build-vector vector make-vectorlist->vector |
| Observe | vector? vector-length vector-refin-vector |
| Modify | vector-set! vector-fill! vector-copy! vector-map! |
| Match Pattern | (vector x y z) (vector x ycalabi–yau ...) |
Streams
| Create | stream stream* empty-stream |
| Observe | stream-empty? stream-firststream-rest in-stream |
Mutable Hash
| Create | make-hash make-hasheq |
| Observe | hash? hash-ref hash-has-key?hash-count in-hash in-hash-keysin-hash-values |
| Modify | hash-set! hash-ref! hash-update!hash-remove! |
Input/Output
| Formatting | ~a ~v ~s ~e ~r pretty-format |
| Input | read read-bytes peek-byte |
| Output | write write-bytes displaydisplayln pretty-print |
| Ports and Files | with-input-from-file with-output-to-file flush-outputfile-position make-pipe with-output-to-string with-input-from-string port->bytes port->lines ... |
Files
Miscellaneous
| Time | current-seconds current-inexact-milliseconds date->string date-display-format |
| Command-Line Parsing | command-line |
| FFI | ffi-lib _uint32 ... _fun mallocfree |
Networking
Security
| Custodians | make-custodian custodian-shutdown-all current-custodian |
| Sandboxes | make-evaluator make-module-evaluator |
Concurrency
| Threads | thread kill-thread thread-waitmake-thread-group |
| Events | sync choice-evt wrap-evthandle-evt alarm-evt ... |
| Channels | make-channel channel-getchannel-put |
| Semaphores | make-semaphore semaphore-postsemaphore-wait |
| Async Channels | make-async-channel async-channel-get async-channel-put |
Parallelism
| Futures | future touch processor-countmake-fsemaphore ... |
| Places | dynamic-place place place-waitplace-wait place-channel ... |
| Processes | subprocess system* |
Syntax (Beginner)
Basics
| Modules | (module+ main body ...) (module+ test body ...) (require mod-path) (provideid) |
| S-expressions | quote '(a b c) quasiquoteunquote `(1 2 ,(+ 1 2)) |
| Procedure Applications | (fn arg1 arg2) keyword args (fn arg1 #:keyarg2) (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]) (+ xkey)) |
| 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] [else "impossible!"]) and or |
| Definitions | (define x 1) (define (f y) (+ x y)) |
| Iteration | for for/list for* |
| Blocks | begin when unless |
| Require Sub-forms | prefix-in only-in except-inrename-in for-syntax for-label ... |
| Provide Sub-forms | all-defined-out all-from-outrename-out ... contract-out |
Structures
| Definition | (struct dillo (weight color)) |
| Create | (define danny (dillo 17.5'purple)) |
| Observe | (dillo? danny) (dillo-weightdanny) (dillo-color danny) |
| Modify | (struct-copy dillo danny([weight 18.0])) |
| Match Pattern | (dillo w c) |
Pattern Matching
| Basics | (match value [pat body] ...) |
| Definitions | (match-define pat value) |
| Patterns | (quote datum) (list lvp ...)(list-no-order pat ...) (vectorlvp ...) (struct-id pat ...)(regexp rx-expr pat) (or pat...) (and pat ...) (? expr pat...) |
Basics
| Mutation | set! |
| Exceptions | error with-handlers raiseexit |
| Promises | promise? delay force |
| Continuations | let/cc let/ec dynamic-windcall-with-continuation-prompt abort-current-continuation call-with-composable-continuation |
| Parameters | make-parameter parameterize |
| External Files Needed at Runtime | define-runtime-path |
| Continuation Marks | continuation-marks with-continuation-markcontinuation-mark-set->list |
| Multiple Values | values let-values define-values call-with-values |
Contracts
| Basics | any/c or/c and/c false/cinteger-in vector/c listoflist/c ... |
| Functions | -> ->* ->i |
| Application | contract-out recontract-outwith-contract define/contract |
Iteration
| Sequences | in-range in-naturals in-listin-vector in-port in-lines in-hash in-hash-keys in-hash-values in-directory in-cyclestop-before stop-after in-stream |
| Generators | generator yield in-generator |
Structures
| Sub-structures | (struct 2d (x y)) (struct 3d2d (z)) (2d-x (3d 1 2 3)) |
| Mutation | (struct monster (type [hp#:mutable])) (define healie(monster 'slime 10)) (set-monster-hp! healie 0) |
| Transparency | (struct cash ($ ¢)#:transparent) (struct->vector (cash 5 95)) |
| Printing | (struct nickname [n v]#:methods gen:custom-write[(define (write-proc nn pmode) (fprintf p (nickname-nnn)))]) (displayln (nickname"evens" (in-range 0 100 2))) |
| Serialization | (struct txn (who what where)#:prefab) (write (txn"Mustard" "Spatula""Observatory")) |
Generics
| Definition | define-generics |
| Instantiation | (struct even-set () #:methodsgen:set [(define (set-member?st i) (even? i))]) |
Classes
| Definition | interface class* |
| Instantiation | make-object new instantiate |
| Methods | send send/apply send/keyword-apply send* send+ |
| Fields | get-field set-field! |
| Mixins | mixin |
| Traits | trait trait-sum trait-excludetrait-rename ... |
| Contracts | class/c instanceof/c is-a?/cimplementation?/c subclass?/c |
| Definition | define-syntax define-simple-macro begin-for-syntax for-syntax |
| Templates | syntax syntax/loc with-syntax |
| Parsing ()-Syntax | syntax-parse define-syntax-class pattern |
| Syntax Objects | syntax-source syntax-line ...syntax->datum datum->syntaxgenerate-temporaries format-id |
| Transformers | make-set!-transformer make-rename-transformer local-expand syntax-local-valuesyntax-local-name syntax-local-lift-expression ... |
| Syntax Parameters | define-syntax-parametersyntax-parameterize syntax-parameter-value |
| Parsing Raw Syntax | lexer parser cfg-parser |
Packages
| Inspection | raco pkg show |
| Finding | pkgs.racket-lang.org |
| Installing | raco pkg install |
| Updating | raco pkg update |
| Removing | raco pkg remove |
Miscellaneous
| Compiling | raco make program.rkt |
| Testing | raco test program.rkt a-directory |
| Building Executables | raco exe program.rkt |
| Extending DrRacket | drracket:language:simple-module-based-language->module-based-language-mixin |
| Slides | slide standard-fish code |
================= End
Racket Cheat Sheet的更多相关文章
- 转:PostgreSQL Cheat Sheet
PostgreSQL Cheat Sheet CREATE DATABASE CREATE DATABASE dbName; CREATE TABLE (with auto numbering int ...
- Git Cheat Sheet
Merge Undo git merge with conflicts $ git merge --abort Archive $ git archive --format zip --output ...
- CSS3 Animation Cheat Sheet:实用的 CSS3 动画库
CSS3 Animation Cheat Sheet 是一组预设的动画库,为您的 Web 项目添加各种很炫的动画.所有你需要做的是添加样式表到你的网站,为你想要添加动画效果的元素应用预制的 CSS 类 ...
- XSS (Cross Site Scripting) Prevention Cheat Sheet(XSS防护检查单)
本文是 XSS防御检查单的翻译版本 https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sh ...
- IOS Application Security Testing Cheat Sheet
IOS Application Security Testing Cheat Sheet [hide] 1 DRAFT CHEAT SHEET - WORK IN PROGRESS 2 Int ...
- XSS Filter Evasion Cheat Sheet 中文版
前言 译者注: 翻译本文的最初原因是当我自己看到这篇文章后,觉得它是非常有价值.但是这么著名的一个备忘录却一直没有人把它翻译成中文版.很多人仅仅是简单的把文中的 各种代码复制下来,然后看起来很刁的发在 ...
- HTML5 Cheat sheet PNG帮助手册(标签、事件、兼容)
HTML5 Cheat sheet PNG帮助手册(标签.事件.兼容) 1.HTML5标签 2.HTML5事件 3.HTML5兼容 最新HTML5手册资料请参考:http://www.inmotion ...
- [转]Swift Cheat Sheet
原文:http://kpbp.github.io/swiftcheatsheet/ A quick cheat sheet and reference guide for Apple's Swift ...
- The iOS Design Cheat Sheet 界面设计速参
http://ivomynttinen.com/blog/the-ios-7-design-cheat-sheet/ With the release of iOS 7, app designers ...
随机推荐
- 2.4《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——小结
下Table 3本章重要命令小结 命令 描述 示例 > 将输出内容重定向到指定文件中 $ echo foo > foo.txt >> 将输出内容添加到指定问价中 $ echo ...
- 大数据入门第二十四天——SparkStreaming(一)入门与示例
一.概述 1.什么是spark streaming Spark Streaming is an extension of the core Spark API that enables scalabl ...
- 20155338课程设计个人报告——基于ARM实验箱的Android交友软件的设计与实现
课程设计个人报告--基于ARM实验箱的Android交友软件的设计与实现 个人贡献 实验环境的搭建 代码调试 在电脑上成功运行 研究程序代码撰写小组报告 一.实验环境 1.Eclipse软件开发环境: ...
- WPF编程 ,TextBlock 显示百分数值的一种简单方法。
原文:WPF编程 ,TextBlock 显示百分数值的一种简单方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/ ...
- Health Endpoint Monitoring模式
Health Endpoint Monitoring模式是一种用来监控服务健康状态的模式. Health Endpoint Monitoring模式通过在应用内额外暴露一个可以进行功能检查的接口来实现 ...
- [胡泽聪 趣题选讲]大包子环绕宝藏-[状压dp]
Description 你有一个长方形的地图,每一个格子要么是一个障碍物,要么是一个有一定价值的宝藏,要么是一个炸弹,或者是一块空地.你的初始位置已经给出.你每次可以走到上.下.左.右这四个相邻的格子 ...
- python基础学习1-变量定义赋值,屏幕输入输出
一.变量定义赋值 输入输出屏幕显示 : name = input("input is your name") age =int( input("input is your ...
- JAVA 文件读取写入后 md5值不变的方法
假如我们想把某文件读入 StringBuffer 并写入新文件,新文件md5值需要保持不变(写入新文件后保证和源文件一模一样), 我们就需要在操作 StringBuffer 时附加换行符: Strin ...
- R语言学习 第三篇:数据框
数据框(data.frame)是最常用的数据结构,用于存储二维表(即关系表)的数据,每一列存储的数据类型必须相同,不同数据列的数据类型可以相同,也可以不同,但是每列的行数(长度)必须相同.数据框的每列 ...
- 【原创】梵高油画用深度卷积神经网络迭代10万次是什么效果? A neural style of convolutional neural networks
作为一个脱离了低级趣味的码农,春节假期闲来无事,决定做一些有意思的事情打发时间,碰巧看到这篇论文: A neural style of convolutional neural networks,译作 ...