Code Style and Testing
? All code has been well indented and has been broken down into reasonably sized procedures (no single line should be too long; aim for about 80 characters each)
? Each procedure has been well documented (but not over-documented - don't just restate the code) with comments, including the purpose of the procedure, the expected inputs, and the expected output.
? When appropriate (Questions 1 and 2), there is sufficient testing using check-expect (or other check functions) and, at a minimum, no code is highlighted by DrRacket when the file is run.
Question 1
Write a function that produces a stream of positive prime numbers. Use that stream to create a list of the product of all pairs of consecutive prime numbers up to a given value.
For example, if we want the answer for prime numbers up to 20, the prime numbers are:
2, 3, 5, 7, 11, 13, 17, 19
The output list would be:
'(6, 15, 35, 77, 143, 221, 323)
Question 2
Write a function called stream-map :
(define (stream-map proc . argstreams)
)
The proc argument is the procedure to apply to one or more streams, while argstreams is a list of a variable number of streams to be used with proc.
Now write a function that uses stream-map to produce the sum of two streams element by element for the first x elements. Be sure to test with several different types of streams (for example, you could sum together the odd and even numbers between 1 and x).
Question 3
Using Prolog, establish a database of facts and rules for the following predicates:
father(X,Y) /* X is the father of Y */
mother(X,Y) /* X is the mother of Y */
male(X) /* X is male */
female(X) /* X is female */
parent(X, Y) /* X is the parent of Y */
difference(X,Y) /* X and Y are different */
Write Prolog clauses to define the following relationships:
is_mother(X) /* X is a mother */
is_father(X) /* X is a father */
aunt(X, Y) /* X is an aunt of Y */
uncle(X, Y) /* X is an uncle of Y */
sister_of(X,Y) /* X is a sister of Y */
grandfather_of(X, Y) /* X is a grandfather of Y */
grandmother_of(X, Y) /* X is a grandmother of Y */
grandchild(X,Y) /* X is a grandchild of Y */
sibling(X,Y) /* X is a sibling of Y, i.e they have the same parents */
half_sibling(X,Y) /*they have same mother but different fathers or
same father, different mothers */
related(X,Y) /* X is related to Y */
ancestor(X, Y) /* X is an ancestor of Y */
descendant(X,Y) /* X is a descendant of Y */