| PSICS Fall 2004 - HW#3 |
|   Course Home   |   |
This assignment involves developing scheme code templates for various kinds of functions. For each template you must provide:
A descriptive name for the template
A description of the kind of problem the template should be used for.
A description of what the template function consumes and produces.
The general structure of a function based on the template. This should be pseudo-scheme code. See the example below.
Two complete examples of functions that match the template (in other words - two problems that can be solved by using the template for guidance). For each function include documentation, the function definition, example usage and test code.
Below is an example template for "arithmetic functions of a single variable":
This template describes scheme funcitons that use arithmetic
operations to compute to compute some mathematical function f(x) given a
value of x. This template can be used in situations where the
f is continuous (discrete functions generally would require
something different, probably involving a cond
statement).
The functions that match this template consume a number and produce a number.
General structure of the function definition:
(define (func x) ...some mathematical operations on x ... )
;; ;; function celcius-to-fahrenheit number => number ;; ;; (celcius-to-fahrenheit c) computes the temperature in ;; degrees fahrenheit that correspond to the temperature c in ;; celcius. The formula used is: ;; ;; fahrenheit = 32 + (celcius * 9/5) ;; ;; sample usage: (celcius-to-fahrenheit 100) (define (celcius-to-fahrenheit c) (+ 32 (* c 9/5))) ;; ;; test code ;; (celcius-to-fahrenheit 0) ;; should produce 32 (celcius-to-fahrenheit -40) ;; should produce -40 (celcius-to-fahrenheit 100) ;; should produce 212
;; ;; function cube number => number ;; ;; (cube x) calculates x raised to the 3rd power ;; ;; sample usage: (cube 2) (define (cube x) (* x (* x x))) ;; ;; test code ;; (cube 2) ;; should produce 8 (cude 1) ;; should produce 1 (cube -2) ;; should produce -8
You need to develop each of the templates described below. For each description below, make sure that your template is not an over-simplifications - it should address all functions that could be described by the statement.
counting functions - functions that iterate based on the value of some counter. (for example the hellos function).
modifying a structure
removing an item from a list
adding an item to a list
processing a list in order
processing a list in reverse order
processing a list of structures
Submit your functions by 11:59 PM, Monday, Oct 11th by submitting to the WebCT dropbox labeled "HW3".