Computer Science 433
Programming Languages

Fall 2014, The College of Saint Rose

Program/Problem Set 5: Scheme
Due: 11:59 PM, Wednesday, October 8, 2014

This week's assignment is the first of two where you will write a collection of Scheme programs to practice your functional programming skills.

You may work alone or in a group of 2 or 3 on this assignment.

Fun with Recursion

Include your code for these functions in a scheme file named recursion.scm.

Question 1: Write a Scheme function called equalizer. It takes two lists as arguments and returns a list of elements that exist in both lists at the same position. (6 points)

Here are some example runs of a working equalizer function:

1 ]=> (equalizer '(mit scheme is a grumpy language)
                 '(strose scheme is a pretend language)) 

;Value 14: (scheme is a language)

1 ]=> (equalizer '(a b c d) '(a x c e f g))

;Value 15: (a c)

Question 2: Write a recursive Scheme function called reverse_parts which takes an integer n and a list as its arguments. It repeatedly takes n elements from the front of the lists, reverses those elements, and adds them to the list of results. If the length of the original list is not divisible by n, remainder elements are reversed. You will want to write some helper functions (or use some from previous assignments or class examples) to keep reverse_parts relatively simple. (12 points)

Here are some example runs of a working reverse_parts function:

1 ]=> (reverse_parts 2 '(cat the the in hat))

;Value 20: (the cat in the hat)

1 ]=> (reverse_parts 4 '(was universe whole our dense dark a in state))

;Value 22: (our whole universe was in a dark dense state)

1 ]=> (reverse_parts 3 (reverse_parts 5 '(m e s c h b i s t e e s t h e)))

;Value 25: (s c h e m e i s t h e b e s t)

Submission

Before 11:59 PM, Wednesday, October 8, 2014, submit your work for grading. Submit your file using Submission Box under assignment "PS5".

Grading

This assignment will be graded out of 18 points.

Feature

Value Score
equalizer 6
reverse_parts 12
Total 18