#lang racket ;;; balance-global.rkt ;;; ================== ;;; A naive implementation of a back-account using a global ;;; variable *balance* to store the bank account's balance. (provide *balance* deposit withdraw) ;;; *balance* : nat? (define *balance* 100) ;; opening balance in account ;;; deposit : nat? -> nat? (define (deposit m) ;; deposit an amount m into the account (set! *balance* (+ *balance* m))) ;;; withdraw : nat? -> void? (define (withdraw m) (if (< *balance* m) (error 'account "balance ~a less than requested withdrawal ~a" *balance* m) (set! *balance* (- *balance* m)))) (set! *balance* -500)