Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • All assigned programming problems should be done in the same .ss file.
  • At the top of your programming solution file, please put a header with the assignment number, your name and e-mail address, and your partner's name and e-mail address, like this:
    Code Block
          ;; COMP 211 HW #01
          ;; Christopher Warrington <chrisw@rice.edu>
          ;; Gregory Malecha <gmalecha@rice.edu>
    
  • Strictly follow the formatting and documentation directives given below under the heading Requirements. The easiest way to follow these requirements is to imitate the Sample Program solution below.

Requirements

You must include a data definition and corresponding template for each form of data processed used in your homework submissions unless instructed otherwise. You only need to include a data definition and corresponding template once for an assignment, not once for every problem that uses that data defintion.

Data Definitions and Templates:

You must include any data definitions introduced in your homework submissions. You need to think devise (and document) your data design for data definitions before you start writing functions that process this data of this type. Data definitions should be documented as follows:

  • Example 3. Data definition of shape:
    Code Block
          ;; A shape is either
          ;; * a triangle (make-triangle b h),
          ;;   where b and h are positive-reals
          ;; * a square (make-square s),
          ;;   where s is a positive-real.
          (define-struct triangle (base height))
          (define-struct square (side))
          ;;
          ;; Examples:
          ;; (make-triangle 1 2)
          ;; (make-triangle 2 5)
          ;; (make-square 4)
          ;; (make-square 2.5)
          ;;
          ;; Template: (enclosed in block comment brackets)for shape
          #|
          ;; shape-function : shape -> ...
          (define (shape-function ... shape ...)
            (cond [(triangle? shape) ... (triangle-base shape)   ...
                                     ... (triangle-height shape) ...]
                  [(square? shape)   ... (square-side shape)     ...]))
          |#
    
  • Example 4. Data definition of list-of-numbers:
    Code Block
          ;; A list-of-numbers is either
          ;;    empty, or
          ;;    (cons n lon)
          ;; where n is a number, and lon is a list-of-numbers
          ;;
          ;; Examples:
          ;; empty
          ;; (cons 1 empty)
          ;; (cons 1 (cons 4 empty))
          ;;
          ;; Template: (enclosed in block comment brackets)for list-of-numbers
          #|
          ;; lon-f : list-of-numbers -> ...
          (define (lon-f ... a-lon ...)
            (cond
              [(empty? a-lon) ...]
              [(cons? a-lon) ... (first a-lon) ...
                             ... (lon-f ... (rest a-lon) ...) ... ]))
          |#
    
  • Once your have written your a data definition, you can use it in the rest of the assignment.
  • The template for writing a function that consumes processes a particular datatype kind of data (data type) is based only on the type corresponding data definition, and should not depend in anyway on the particular functions that you happen define on that type. In other wordsHence, there is only one template per data type. This same template is used as the starting point for writing all functions that process that data type.
  • If the type is a structure, the template should have include the field extraction operations. If the type is a varietyunion, the template needs to have an appropriate cond statement (see example 3). If the type is recursive, the template tells us how the recursion should be done(includes the expected recursive calls on the recursive data components (see example 4).

Basic form of a function definition

...