Skip to content

Racket Functions — Higher-Order Functions, Lambdas, and Closures

DodaTech Updated 2026-06-29 1 min read

In this tutorial, you will learn about Racket Functions. We cover key concepts, practical examples, and best practices to help you master this topic.

Functions are first-class in Racket — they can be created, passed as arguments, and returned as values.

Lambda

; Anonymous functions
(lambda (x) (* x x))
(map (lambda (x) (* x 2)) '(1 2 3))  ; => '(2 4 6)

; Shorthand using λ
(map (λ (x) (* x 2)) '(1 2 3))

Closures

; Functions that capture their environment
(define (make-counter)
  (define count 0)
  (λ ()
    (set! count (add1 count))
    count))

(define counter (make-counter))
(counter)  ; => 1
(counter)  ; => 2

Currying

(require racket/function)
(define add5 ((curry +) 5))
(add5 10)  ; => 15

; Function composition
(define f (compose1 add1 sqr))
(f 4)  ; => 17 (square then add1)

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro