Certainly! Here's a Quick Cheatsheet: Racket for Experienced R7RS Scheme Developers — highlighting key differences, similarities, and Racket-specific idioms.
🚀 Basics
| Concept | Racket | Notes / Differences from R7RS |
|---|
| REPL | racket or raco repl | Similar to (scheme-report-environment 5) REPL |
| File Extension | .rkt or .rktl | Convention over standard |
🔧 Module System
Importing Modules
racket
#lang racket ; Top of every Racket file
(require racket/base) ; Base forms (can also use just `racket`)
(require racket/string) ; Specific libraries
- Racket uses a powerful module system (not R7RS libraries).
#lang racket is the default language.
- Multiple
require forms allowed per file.
Exporting (in custom modules)
racket
#lang racket
(provide (all-defined-out)) ; Export all defined bindings
(provide foo bar) ; Or selectively
(define foo 42)
(define (bar x) (+ x 1))
🧠 Syntax Differences
| Feature | Racket | Notes |
|---|
define-syntax-rule | Supported | Hygienic macros similar to syntax-rules |
let-values, let*-values | Built-in | Racket has better support for multiple values |
match | Pattern matching library | Powerful alternative to case-lambda, cond |
lambda vs λ | Prefer lambda | Racket supports λ, but not in #lang racket by default unless imported |
| Quasiquote | Backtick syntax same as R7RS | Supports , and ,@ as usual |
🧪 Libraries & Features
| Task | Racket Form |
|---|
| String manipulation | string-append, substring, etc. |
| List functions | Same as R7RS + extras (second, third, take, drop) |
| Hash tables | (make-hash) → hash-ref, etc. |
| Structs | (struct point (x y) #:transparent) |
| I/O | (displayln "Hi"), (read-line) |
| Mutable state | set!, box, vector-set!, etc. |
🧰 Commonly Used Libraries
| Library | Purpose |
|---|
racket/base | Core language (smaller than full racket) |
racket/string | String utilities |
racket/list | List helpers |
racket/match | Pattern matching |
racket/struct | Struct definitions with features |
racket/port | Ports and I/O |
racket/control | Continuations (let/cc, etc.) |
🧬 Macros
racket
(define-syntax-rule (twice x)
(begin
(displayln x)
(displayln x)))
(twice "hello")
For advanced macros:
- Use
syntax-rules, syntax-case, or syntax-parse.
- Racket's macro system is much more powerful and hygienic than R5RS/R7RS.
🧮 Multiple Values
racket
(define-values (a b) (values 1 2))
Racket supports multiple values natively (like R7RS), but with more helper functions.
🐍 Tail Calls & Continuations
Tail calls work as expected in Racket (R7RS-compatible).
racket
(define (fact n acc)
(if (zero? n)
acc
(fact (- n 1) (* n acc))))
Continuations:
racket
(require racket/control)
(let/cc k
(k 42)) ; => returns 42 immediately
📦 Defining Your Own Language (Advanced)
Racket shines at language creation:
racket
#lang racket
(require (for-syntax syntax/parse))
(define-syntax-parser my-lang
[(_ expr)
#'(+ expr 1)])
Useful for DSLs and experimental languages.
🛠 Tools
raco: Racket command-line tool
raco make: Compile
raco test: Run tests
raco doc: View docs
- DrRacket IDE: Highly recommended for exploration
📚 Resources
✅ Racket is largely compatible with R7RS Scheme at the core language level, but expands massively in libraries, macros, modules, and tooling.
Let me know if you want a comparison table of common forms side-by-side!