;; largest: list-of-number (non-empty) -> number ;; consumes a non-empty list of numbers and produces the largest number in the list (define (largest alon) (largest-accum (rest alon) (first alon))) ;; largest-accum: list-of-number number -> number ;; consumes a list of numbers and produces the largest number in the list, ;; keeping track of the largest number seen so far in largest-so-far (define (largest-accum alon largest-so-far) (cond [(empty? alon) largest-so-far] [(cons? alon) (cond [(> (first alon) largest-so-far) (largest-accum (rest alon) (first alon))] [else (largest-accum (rest alon) largest-so-far)])])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Change Language Level to Advanced ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; an account is a struct ;; (make-account number number) (define-struct account (acctnum balance)) ;; a list-of-account is etiehr ;; empty, or ;; (cons account list-of-account) ;; Citibank: list-of-account ;; remembers the current contents of each bank account (define Citibank (list (make-account 1 500) (make-account 2 1000) (make-account 3 10))) ;; original version of add-account, doesn't change Citibank ; ;; add-account: number number list-of-account -> list-of-account ;;;; makes a new account with the given account number and balance, and ;;;; adds the account to the list ; (define (add-account acctnum amt aloa) ; (cons (make-account acctnum amt) aloa)) ; ;; add-account: number number -> void ;; makes a new account with the given account number and balance, and ;; adds the account to the list ;; EFFECT: adds an account to Citibank (define (add-account acctnum amt) (set! Citibank (cons (make-account acctnum amt) Citibank))) ;; ticketnum: number ;; 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))