Racket and Scheme Tutorial
Learn Racket and Scheme step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Are Scheme and Racket? Meet Scheme and Racket, two small, elegant Lisp languages: where they come from, what makes them special, and why learning them changes how you program.
- Installing Racket and Running Your First Program Install Racket, open DrRacket, write a #lang racket program, and run it from the editor or the command line. Includes how files and modules are laid out.
- The REPL and Developer Tools Use the Racket REPL and DrRacket effectively: interactive evaluation, the stepper, error messages, printing values, comments, and the raco command-line tools.
- Racket, Scheme Dialects and the Ecosystem A map of the Scheme and Racket world: the R5RS, R6RS and R7RS standards, major implementations, the Racket package catalog, and how to choose where to start.
Syntax and Evaluation
- S-expressions and How Evaluation Works Learn how Lisp code is built from S-expressions and how the evaluator reduces them: atoms, lists, the substitution model, special forms and the quote operator.
- Numbers and Booleans Work with numbers and booleans in Racket and Scheme: the numeric tower, exact versus inexact values, arithmetic and comparison functions, and truthiness rules.
- Defining Names with define and let Bind names to values with define, let, let* and letrec in Racket and Scheme. Learn lexical scope, shadowing, internal definitions and when to use set!.
- Strings, Characters and Symbols Learn the text types of Racket and Scheme: strings, characters and symbols. Includes string functions, conversion, comparison and when to use a symbol.
- Conditionals: if, cond, case, when and unless Make decisions in Racket and Scheme with if, cond, case, when and unless. Learn else clauses, the => form, predicates, and how to write clear nested conditions.
Lists and Recursion
- Pairs and Lists Understand the pair, the building block of Lisp lists. Learn cons, car, cdr, list, quote, dotted pairs, list functions and why lists are linked chains.
- Recursion Basics Learn recursion in Racket and Scheme: base cases, recursive steps, factorial, Fibonacci, accumulators, tracing calls with the substitution model, and common mistakes.
- Recursion on Lists: Patterns Master the list recursion template in Racket and Scheme: empty case, first and rest, sum, filter, map, append, reverse, nested lists and tree recursion.
- Association Lists and Hash Tables Store key-value data in Racket and Scheme with association lists and hash tables: assoc, hash, make-hash, hash-ref, hash-set, counting words and choosing between them.
- Vectors and Structs Use vectors for fast indexed access and structs to define your own record types in Racket. Covers vector-ref, vector-set!, struct fields, transparency and pattern matching.
Higher-order Functions
- Lambda and Closures Learn anonymous functions with lambda, functions as values, and closures that remember their surroundings. Build counters, adders and private state step by step.
- map, filter and fold Replace hand-written recursion with map, filter, foldl, foldr, andmap and ormap in Racket. Learn argument order, building pipelines and how fold generalizes list recursion.
- Function Composition and Currying Build small functions into bigger ones with compose, curry and partial application in Racket and Scheme. Write your own helpers and see functions that make functions.
- apply, Variadic Functions and Optional Arguments Write functions that accept any number of arguments in Racket and Scheme: rest parameters, apply, optional and keyword arguments, and a small statistics toolkit.
Continuations and Tail Calls
- Tail Calls and Loops Learn tail position, proper tail calls, named let and why Scheme and Racket have no loop keyword. Includes runnable JavaScript stand-ins that show the stack problem.
- Accumulators and Trampolines Turn non-tail recursion into tail recursion with accumulators, see how reverse fixes list building, and learn trampolines for languages without tail-call support.
- call/cc and Escapes Understand continuations: what the rest of the computation is, how call/cc captures it, early exit from loops, and runnable JavaScript stand-ins for escaping continuations.
- Generators and Coroutines Build generators and coroutines from continuations, use Racket's racket/generator library, and model the same ideas with JavaScript generators in runnable stand-ins.
Macros and Languages
- Quote and Code as Data Learn why Lisp code is just lists: quote, quasiquote, unquote, eval and namespaces, plus runnable JavaScript stand-ins that treat programs as nested arrays.
- Syntax-rules Macros Write pattern-based macros with define-syntax-rule and syntax-rules: patterns, templates, ellipses, literals, recursive macros, and a JavaScript pattern-expander stand-in.
- Hygiene and syntax-case Understand hygienic macros and variable capture, then move to syntax-case, with-syntax and syntax-parse in Racket, with a runnable JavaScript capture demo and renaming stand-in.
- Languages with #lang See how Racket's #lang line selects a language, how a module language is built from provide and macros, and run a JavaScript stand-in for a tiny reader plus evaluator.
Modules and Contracts
- Modules and provide Organize Racket programs into modules: require and provide, rename and prefix imports, submodules like main and test, collections and paths, plus a JavaScript module-registry stand-in.
- Contracts Basics Learn Racket contracts: -> and contract-out, predicates and combinators like or/c and listof, blame at module boundaries, and a JavaScript contract-wrapper stand-in.
- Structs and Contracts Define Racket structs, guard fields with contracts, use struct-out and #:transparent, immutable updates with struct-copy, and run a JavaScript record validator stand-in.
- Testing with rackunit Write tests with rackunit: check-equal?, check-true, check-exn, test-case and test-suite, the test submodule and raco test, plus a runnable JavaScript mini test framework stand-in.
Applications
- Text Processing and Ports Read and write files with Racket ports, process lines and words, use regexps and string functions, and run a JavaScript text-pipeline stand-in with a string port model.
- Web Servers and Servlets Build web apps with Racket's web-server: request and response structs, dispatch-rules routing, X-expressions for HTML, forms, and a JavaScript routing and templating stand-in.
- Concurrency and Places Compare Racket's green threads, channels, synchronization with sync, futures and places for parallelism, with runnable JavaScript stand-ins for channels and a worker pool.
- Drawing with pict Create graphics as values in Racket with the pict and 2htdp/image libraries: shapes, hc-append, vc-append, recursion for fractals, and a runnable SVG-generating JavaScript stand-in.
Projects and Practice
- Project: A Mini Scheme Interpreter Build a small Scheme interpreter: tokenizer, parser, environments, closures, if, define, let and tail calls. Racket version read-only, a full runnable JavaScript version included.
- Project: A Pattern Matcher Learn Racket's match form, then build your own pattern matcher with variables, wildcards, list patterns and ellipsis rules, and use it to write a symbolic differentiator.
- Practice: Recursion Problems Eight practice problems on recursion, accumulators, tail calls and higher-order functions, each with a Racket solution, hints, and runnable JavaScript checks to compare against.
- Practice: Macros and Course Review Practice macros, continuations, contracts and modules with exercises and solutions, a runnable macro-expander challenge, and a final review of the Racket and Scheme course.