Please send questions to
st10@humboldt.edu .
CS 131
Homework Template and Design Recipe Template
Version as of 10-11-02
at the beginning of the homework file:
;***********************************************************
; type in your name (or both names, IF working as a pair)
; CS 131 HW X
; last modified:
;***********************************************************
...for each problem on the homework:
;***********************************************************
; Problem X
;
Order of design recipe steps:
- data analysis and definition (including data definitions, IF needed)
- contract, header, and purpose statement
- template (IF needed)
- examples
- body
- tests
function "template" for easier cut-and-paste:
;;----------------------------------------------------------
;; a x is a structure:
;; (make-x y1 y2 ... yn)
;; ...where y1 is a dt, y2 is a dt, ...
;; and yn is a dt.
;; THEN, add a brief sentence EXPLAINING x's meaning.
(define-struct x (y1 y2 ... yn))
;;----------------------------------------------------------
;; a y is either:
;; 1. a x structure, or
;; 2. a y structure, or
;; ...
;; n. a z structure.
;; (note: assuming that data definitions for x-z have been given)
;; THEN, add a a brief sentence EXPLAINING y's meaning, if not obvious.
;;----------------------------------------------------------
;; a list-of-type is either:
;; 1. the empty list, empty, or
;; 2. (cons type-inst type-list)
;; ...where type-inst is a type and type-list is a
;; list-of-type.
;; THEN, add a brief sentence EXPLAINING list-of-type's meaning, if not obvious.
;;----------------------------------------------------------
;; CONTRACT:
;; PURPOSE:
;; EXAMPLES:
;; (note: modify template as appropriate to include cond's, selectors, list operators, etc.)
;; TEMPLATE:
;; (define (process-x a-x)
;; ... (x-y1 a-x) ...
;; ... (x-y2 a-x) ...
;; ...
;; ... (x-yn a-x) ...)
(define
; expr to go here
)
;; TESTS:
;;---------------------------------------------------------------------------
function "template" with more explanation:
...to be done for EACH function (auxiliary OR main):
;;-----------------------------------------------------------
;; (ONLY IF APPROPRIATE FOR PROBLEM; note that a data definition used for
;; several functions within a program only needs to appear ONCE,
;; before the first function using that compound data.)
;; DATA ANALYSIS and DEFINITIONS:
;; (include a data definition for EACH structure needed)
;------------------------------------------------------------
;; a mystruct is a structure:
;; (make-mystruct x1 x2 ... xn)
;; ...where x1 is a x1-datatype, x2 is a x2-datatype, ...
;; and xn is a xn-datatype.
;; THEN, add a brief sentence EXPLAINING mystruct's meaning.
(define-struct mystruct (x1 x2 ... xn))
;; note that the following supertype definition is assumed to be preceded
;; by data definitions of all of the subtypes x-z that it uses.
;-----------------------------------------------------------
;; a supertype is either:
;; 1. a x structure, or
;; 2. a y structure, or
;; ...
;; n. a z structure.
;; THEN, add a a brief sentence EXPLAINING supertype's meaning, if not obvious.
;;----------------------------------------------------------
;; a list-of-type is either:
;; 1. the empty list, empty, or
;; 2. (cons type-inst type-list)
;; ...where type-inst is a type and type-list is a
;; list-of-type.
;; THEN, add a brief sentence EXPLAINING list-of-type's meaning, if not obvious.
;;----------------------------------------------------------
;; CONTRACT: function-name : input types -> output types
;; PURPOSE: type in PURPOSE STATEMENT for function-name, making
;; use of parameter names from header/definition
;; EXAMPLES:
;; (function-name specific-arguments) should produce actual-value
;; (how many examples? We'll refine this --- but, for now, try to
;; have one for each main "category" of data that might occur,
;; plus "boundary" situations.)
;; (note: modify template as appropriate to include cond's, selectors, list operators, etc.)
;; TEMPLATE:
;; (define (process-mystruct a-mystruct)
;; ... (mystruct-x1 a-mystruct) ...
;; ... (mystruct-x2 a-mystruct) ...
;; ...
;; ... (mystruct-xn a-mystruct) ...)
(define (function-name parameter-names)
; expr for function-name's body, indented. BUT final parenth can be here: )
) ; ...or here.
;; TESTS:
; type in your specific tests (from examples above) here.
; you may choose to compare your function call result to your expected
; result, as in:
(= (function-name actual-arguments)
expected-result)
; or, you may type so both will show on consecutive lines:
(function-name actual-arguments)
; expected result
expected-result
; (and these two styles may be mixed and matched as needed, as long
; as all examples are actually run as tests)
;;-----------------------------------------------------------
data definition examples:
;------------------------------------------------------------
; general structure of a DATA DEFINITION:
;------------------------------------------------------------
;; a my-new-struct is a structure:
;; (make-my-new-struct info-1 info-2 ... info-n)
;; ...where info-1 is a data-type and info-2 is a data-type ...
;; and info-n is a data-type
;; THEN, add a brief sentence EXPLAINING my-new-struct's meaning.
;(define-struct my-new-struct (info-1 info-2 ... info-n))
;------------------------------------------------------------
; for example,
;------------------------------------------------------------
;; a prof is a structure:
;; (make-prof name office-hours office-num email)
;; ...where name, office-hours, office-num, and email are symbols.
;; prof represents a professor at Fictional State University.
(define-struct prof (name office-num office-hours email))
;------------------------------------------------------------