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
Primitives

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?"
Data

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 ...)

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 ...)
Systems

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...)
Syntax (Intermediate)

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))])
Tools

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的更多相关文章

  1. 转:PostgreSQL Cheat Sheet

    PostgreSQL Cheat Sheet CREATE DATABASE CREATE DATABASE dbName; CREATE TABLE (with auto numbering int ...

  2. Git Cheat Sheet

    Merge Undo git merge with conflicts $ git merge --abort Archive $ git archive --format zip --output ...

  3. CSS3 Animation Cheat Sheet:实用的 CSS3 动画库

    CSS3 Animation Cheat Sheet 是一组预设的动画库,为您的 Web 项目添加各种很炫的动画.所有你需要做的是添加样式表到你的网站,为你想要添加动画效果的元素应用预制的 CSS 类 ...

  4. XSS (Cross Site Scripting) Prevention Cheat Sheet(XSS防护检查单)

    本文是 XSS防御检查单的翻译版本 https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sh ...

  5. IOS Application Security Testing Cheat Sheet

    IOS Application Security Testing Cheat Sheet    [hide]  1 DRAFT CHEAT SHEET - WORK IN PROGRESS 2 Int ...

  6. XSS Filter Evasion Cheat Sheet 中文版

    前言 译者注: 翻译本文的最初原因是当我自己看到这篇文章后,觉得它是非常有价值.但是这么著名的一个备忘录却一直没有人把它翻译成中文版.很多人仅仅是简单的把文中的 各种代码复制下来,然后看起来很刁的发在 ...

  7. HTML5 Cheat sheet PNG帮助手册(标签、事件、兼容)

    HTML5 Cheat sheet PNG帮助手册(标签.事件.兼容) 1.HTML5标签 2.HTML5事件 3.HTML5兼容 最新HTML5手册资料请参考:http://www.inmotion ...

  8. [转]Swift Cheat Sheet

    原文:http://kpbp.github.io/swiftcheatsheet/ A quick cheat sheet and reference guide for Apple's Swift ...

  9. The iOS Design Cheat Sheet 界面设计速参

    http://ivomynttinen.com/blog/the-ios-7-design-cheat-sheet/ With the release of iOS 7, app designers ...

随机推荐

  1. Iframe和Frame中实现cookie跨域的方法(转载)

    在Iframe和Frame中默认是不支持Cookie跨域的,但通过设置P3P协议相关的响应头可以解决这一问题.关于p3p协议: P3P: Platform for Privacy Preference ...

  2. solr服务器搭建与Tomact整合及使用

    一:solr服务器的搭建 1:搭建全新的为solr专用的solr服务器: 在自己电脑上搭建两台Tomact服务器,一台仍为应用服务器,一台作为solr服务器,应用服务器按照正常Tomact服务器搭建即 ...

  3. C# HtmlAgilityPack和AngleSharp 解析HTML

     C# HtmlAgilityPack和AngleSharp 解析HTML by:wgscd date:2018-1-17 HtmlAgilityPack 有点是只有一个单独DLL.AngleShar ...

  4. 20155204 王昊《网络对抗技术》EXP4

    20155204 王昊<网络对抗技术>EXP4 一.实验后回答问题 (1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有 ...

  5. 20155229《网络对抗技术》Exp3:免杀原理与实践

    实验预习 免杀: 看为一种能使病毒木马避免被杀毒软件查杀的技术. 免杀的分类: 开源免杀:指在有病毒.木马源代码的前提下,通过修改源代码进行免杀.. 手工免杀:指在仅有病毒.木马的可执行文件(.exe ...

  6. Android开发——RecyclerView特性以及基本使用方法(二)

    0.  前言 随着Android的发展,虽然ListView依旧重要,但RecyclerView确实越来越多的被大家使用.但显然并不能说RecyclerView就一定优于ListView,而是应该根据 ...

  7. 文章翻译:Recommending items to more than a billion people(面向十亿级用户的推荐系统)

    Web上数据的增长使得在完整的数据集上使用许多机器学习算法变得更加困难.特别是对于个性化推荐问题,数据采样通常不是一种选择,需要对分布式算法设计进行创新,以便我们能够扩展到这些不断增长的数据集. 协同 ...

  8. linux下ipython无法保存历史记录

    在Centos7下使用ipython时,发现有个warning,提示无法保存历史记录 [root@localhost pip-]# ipython /usr/local/lib/python3./si ...

  9. [CF983D]Arkady and Rectangles[线段树+可删堆/set]

    题意 你有一个无限大的绘图板,开始颜色是\(0\) , 你将进行\(n\) 次绘图,第\(i\) 次绘图会将左下角为 \((x_1, y_1)\),右上角为\((x_2, y_2)\) 的矩形涂成颜色 ...

  10. [Direct2D开发] 绘制网格

    转载请注明出处:http://www.cnblogs.com/Ray1024 一.引言 最近在使用Direct2D进行绘制工作中,需要实现使用Direct2D绘制网格的功能.在网上查了很多资料,终于实 ...