100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Racket Cheat Sheet

Racket Cheat Sheet

Fundamental Racket syntax covering definitions, higher-order functions, list operations, and pattern matching with match.

2 PagesIntermediateApr 10, 2026

Basics

Definitions and printing.

racket
#lang racket;; Definitions and printing(define name "World")(displayln (string-append "Hello, " name "!"))(define (square x) (* x x))(displayln (square 5))

Functions

Lambdas, local bindings, and higher-order functions.

racket
;; Anonymous functions (lambda)(define add (lambda (a b) (+ a b)))(displayln (add 2 3));; let for local bindings(let ([x 1] [y 2])  (displayln (+ x y)));; Higher-order functions(map (lambda (x) (* x x)) '(1 2 3 4))(filter even? '(1 2 3 4 5 6))(foldl + 0 '(1 2 3 4))

Lists

Core list operations.

  • '(1 2 3)- Quoted list literal
  • (cons 1 '(2 3))- Prepends an element, yields '(1 2 3)
  • (car lst)- First element of a list
  • (cdr lst)- Rest of the list after the first element
  • (list 1 2 3)- Constructs a list from its arguments
  • (append lst1 lst2)- Concatenates two lists

Pattern Matching

Destructuring with match.

racket
(define (describe x)  (match x    [(? number?) "a number"]    [(list a b) (format "pair of ~a and ~a" a b)]    ['() "empty list"]    [_ "something else"]))(displayln (describe 5))(displayln (describe (list 1 2)))

Special Forms

Core syntactic forms.

  • (define x 5)- Binds a value to a name
  • (if cond then else)- Conditional expression
  • (cond [test1 res1] [else default])- Multi-branch conditional
  • (lambda (args) body)- Anonymous function
  • (struct point (x y))- Defines a simple record type
  • (let loop ([i 0]) (when (< i 5) (loop (+ i 1))))- Named let for recursion/looping
Pro Tip

Prefer match over nested cond/if for destructuring lists and structs — it makes intent explicit and catches unhandled cases more readably.

Was this cheat sheet helpful?

Explore Topics

#Racket#RacketCheatSheet#Programming#Intermediate#Functions#Lists#PatternMatching#SpecialForms#DataStructures#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Related Glossary Terms

Share this Cheat Sheet