COSC 152 Programming Languages

Fall 2006

Homework Assignment #1

A gentle introduction to Scheme

Due: Friday, Sept 8, 2:00PM CDT
Submit: E-mail electronic copy to professor, with a subject header "COSC 152 HW#1".
Work is to be completed individually, using only the Scheme constructs covered in class (TLS Ch 1-3) and the arithmetic primitives (+, -, etc.).
Q1 - append-item
Define a function "append-item" which takes a list and an S-expression and returns a new list with the S-expression appended at the end. Do not use the built-in append.
Examples:
> (append-item 'a '())
(a)
> (append-item 'e '(a b c d))
(a b c d e)
Q2 - rotate-list
Define a function "rotate-list" which takes a list a returns a new list with the first S-expression now at the end of the list.
Examples:
> (rotate-list '(a b c d e))
(b c d e a)
Q3 - rotate-list-n
Define a function "rotate-list-n" which takes a list and an integer n, and returns a new list which has been rotated n times.
Examples:
> (rotate-list-n '(a b c d e) 2)
(c d e a b)
Q4 - reverse-list
Define a function "reverse-list" which takes a list and returns a new list with the S-expressions in reverse order. Do not use the built-in reverse.
Examples:
> (reverse-list '(a b c d e))
(e d c b a)

Back