;; revers : list-of-string -> list-of-string ;; produce list of string with strings in opposite order from given list (define (revers alos) (rev-accum alos empty)) ;; rev-accum : list-of-string list-of-string -> list-of-string ;; accumulates reverse of first list in second list (define (rev-accum alos revalos) (cond [(empty? alos) revalos] [(cons? alos) (rev-accum (rest alos) (cons (first alos) revalos))])) ;; reverse2 : list-of-string -> list-of-string ;; produce list of string with strings in opposite order from given list (define (reverse2 alos) (cond [(empty? alos) empty] [(cons? alos) (append (reverse (rest alos)) (list (first alos)))])) ------------------------------------------------------------------ ;; 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)))