


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



UIUC, Department of Computer Science Spring 2006 CS421 Programming Languages Machine Problem Set 1
Assigned: January 24, 2006 Due: January 31, 2006
This MP is meant to give you practice writing and using higher order functions. In this assignment, you may not use any higher order functions provided by scheme, such as length or map. You may, however, write helper functions. Upon completion of this MP, you should understand:
Write a hello world program in Scheme.
(hello_world) "Hello world!"
Implement your own list length function. It should return the number of elements in the list.
(define mylist (list -1 0 1 2 3 )) (mylength mylist) 5
Implement the Fibonacci function f ib(n) that runs in O(n) time: that is, the computation time required to compute f ib(n) grows linearly with n. The Fibonacci function is defined as follows:
f ib(n) :=
0 if n = 0; 1 if n = 1; f ib(n − 1) + f ib(n − 2) if n > 1.
(fib 7) 13 (fib 0) 0 (fib 1) 1
Can you implement the Fibonacci function that runs in O(log(n)) time?
Implement our own reverse function called myreverse. myreverse function should take a list of data, and reverse it.
(myreverse (list 1 2 3 4 5)) (5 4 3 2 1)
Implement your own map function called mymap. mymap should take a function and a list as arguments, and apply the function to each element of the list, returning a list of results. So the ith^ item in the returned list is the result of applying the function to the ith^ item in the passed-in list.
(mymap fib (list -1 0 1 2 3 7 )) (0 0 1 1 2 13)
(^1) Brownie Points are the kind of points that have no tangible value, but you still feel good when you get them. Besides, the solutions to these may be useful to you later in the course or in your CS career. To clarify, Brownie Point problems will not be graded and will have no effect on your grade.
should be the same as in the problems. Please see the CS 421 FAQ web page for handin instructions.