Please send questions to
st10@humboldt.edu .
CS 131
Homework Template and Design Recipe Template
Version as of 9-19-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.
(define-struct x (y1 y2 ... yn))
;---------------------------------------------------------------------------
;; CONTRACT:
;; PURPOSE:
;; EXAMPLES:
;; 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.
(define-struct mystruct (x1 x2 ... xn))
;--------------------------------------------------------------
;; 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.)
;; 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
;(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.
(define-struct prof (name office-num office-hours email))
;--------------------------------------------------------------