;; ticketnum: number ;; state variable that stores the last ticket number handed out (define ticketnum 0) ;; get-ticket: -> number ;; produces the next ticket number ;; EFFECT: increments ticketnum, or restarts it at 1 (define (get-ticket) (begin (cond [(= 4 ticketnum) (set! ticketnum 1)] [else (set! ticketnum (+ 1 ticketnum))]) ticketnum)) ;;------------------------------------------------------------------------ ;; an account is a struct ;; (make-account number number) (define-struct account (acctnum balance)) ;; a list-of-account is either ;; empty, or ;; (cons account list-of-account) ;; Citibank: list-of-account ;; state variable that remembers the current contents of each bank account (define Citibank (list (make-account 1 500) (make-account 2 1000) (make-account 3 10))) ;; add-account: number number -> void ;; consumes an acount number and amount, and adds a new account ;; EFFECT: changes the number of accounts in Citibank (define (add-account acctnum amt) (set! Citibank (cons (make-account acctnum amt) Citibank))) ;; remove-account: number -> void ;; removes the account with the given account number ;; EFFECT: removes an account from Citibank (define (remove-account acctnum) (set! Citibank (remove-from-list acctnum Citibank))) ;; remove-from-list: number list-of-account -> list-of-account ;; consumes a list of accounts and an account number and produces a list of accounts with the named account removed (define (remove-from-list acctnum aloa) (cond [(empty? aloa) (error "no such account") ] [(cons? aloa) (cond [(= acctnum (account-acctnum (first aloa))) (rest aloa)] [else (cons (first aloa) (remove-from-list acctnum (rest aloa)))])]))