CS 491/591 Advanced Scheme Programming and Implementation

Homework 4 (Spring 2004)

  1. Define the infinite stream of increasingly accurate Taylor series approximations for e:

    e(0) = 1/0! e(1) = 1/0! + 1/1! e(2) = 1/0! + 1/1! + 1/2! e(3) = 1/0! + 1/1! + 1/2! + 1/3!...

  2. The positive rational numbers, which are ratios of two positive integers, a/b, can be enumerated by listing them in order of increasing sums a+b, with those numbers having the same sum listed in order of increasing numerator a. Those fractions that are not in lowest terms are omitted from the enumeration. Thus, the enumeration begins with 1/1, 1/2, 2/1, 1/3, 3/1,... Define a stream, positive-rationals, that contains all of the positive rational numbers with numerator and denominator having no common divisor greater than one. Represent the rational number a/b as a list (a b) and use the Scheme procedure gcd to test whether a/b is in lowest terms. Test your program by listing the first twenty elements of the stream.

  3. Give a definition for Scheme's equal? written in continuation passing style. Call your function equal-cps?. Define equal-cps? so that it takes a success continuation succ and a failure continuation fail. The failure continuation is applied if any two atoms are not eq?.

  4. Using either define-macro or define-syntax, define a macro, string-case, which is similar to Scheme's case macro but works with strings. For example, > (string-case "dog" (("dove" "turkey") "bird") (("cat" "dog") "mammal") (else "reptile")) "mammal" >
  5. Using the stream file interface given here write a Scheme program which reads a file containing DNA base pairs (represented by the letters A, G, C, and T) and translates the file into the twenty amino acids (represented by the letters F, L, I, M, V, S, P, T, A, etc.) and one stop symbol (represented by $) using the following genetic code. Test your program on the chromosomal DNA for the bacterium, buchnera, which can be downloaded here.