#lang racket (define balance 100) ;; ----------------------------------------------------------------- ;; Step 0 toward a bank account ;; ----------------------------------------------------------------- (define withdraw (lambda (amount) (if (>= balance amount) ;; balance is free (begin (define balance (- balance amount)) balance) (error "Insufficient funds" balance)))) ;; ----------------------------------------------------------------- ;; Step 1: use set! to modify existing object ;; Step 2: make balance a local variable ;; Step 3: swap the lambda and the let ;; Step 4: convert the let into a lambda ;; -----------------------------------------------------------------