CMSC15100 Autumn 2010: Homework 3

Due Tuesday, October 19 at 10pm.

Setup

This assignment should be done using the Beginning Student with List Abbreviations language.

Exercise 1: Formatting

Recall the definition of expressions from class:

;; An expression is either ;; - a number or ;; - a bexp (define-struct bexp (op ; : symbol left ; : expression right ; : expression ))

Develop a recursive function

;; expression->string : expression -> string ;; returns the fully-parenthesized string representation of e ;; (define (expression->string e) ...) (check-expect (expression->string (make-bexp '* (make-bexp '+ 1 2) 3)) "((1 + 2) * 3)")

For this question, you will need to use the following library functions:

; number->string : number -> string ; symbol->string : symbol -> string ; string-append : string ... -> string

Exercise 2: Family trees

;; a ftn (family-tree node) is either ;; - 'unknown, or ;; - a child ;; ;; where (define-struct child (name ; : string -- the child's name date ; : number -- the child's age mom ; : ftn -- the child's mother dad)) ; : ftn -- the child's mother

Write the following functions on family trees:

;; 30-year-old? : ftn -> boolean ;; to determine if a 30-year-old person is in a-ftn ;; (define (30-year-old? a-ftn) ...) ;; count-people : ftn -> integer ;; to count the number of people in a-ftn ;; (define (count-people a-ftn) ...) ;; age-by-1 : ftn -> ftn ;; add 1 to the age of every person in a-ftn ;; (define (age-by-1 a-ftn) ...) ;; average-age : ftn -> number ;; to determine the average age in a-ftn ;; (define (average-age a-ftn) ...)

Hint: for the last function, you will want to use a helper function.