Docsity

CS421 Machine Problem Set 1 at UIUC - Scheme Programming, Assignments of Computer Science

Toggle sidebar
bg1
UIUC, Department of Computer Science Spring 2006
CS421 Programming Languages Machine Problem Set 1
Machine Problem Set 1
Assigned: January 24, 2006
Due: January 31, 2006
Objectives and Background
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:
•The basics of Scheme
•Recursive functions
•Higher order functions
•Induction
Problem 1
Write a hello world program in Scheme.
> (hello_world)
"Hello world!"
Problem 2
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
1
pf3
pf4

Partial preview of the text

Download CS421 Machine Problem Set 1 at UIUC - Scheme Programming and more Assignments Computer Science in PDF only on Docsity!

UIUC, Department of Computer Science Spring 2006 CS421 Programming Languages Machine Problem Set 1

Machine Problem Set 1

Assigned: January 24, 2006 Due: January 31, 2006

Objectives and Background

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:

  • The basics of Scheme
  • Recursive functions
  • Higher order functions
  • Induction

Problem 1

Write a hello world program in Scheme.

(hello_world) "Hello world!"

Problem 2

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

Problem 3

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

Problem 4

Brownie Points Problem^1

Can you implement the Fibonacci function that runs in O(log(n)) time?

Problem 5

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)

Problem 6

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.