- What is the difference between the Scheme values
'(1 2) and '(1 . 2)?
- From The Schemer's Guide, Question 1 in Problem Set 2 (p.55)
- Write a function list-length, that returns
the number of elements in a given list. So:
(list-length '(eeny meeny miney mo)) --> 4
(list-length '()) --> 0
- Write a function list-append, that takes
two lists as arguments, and returns the result of appending the
latter to the end of the former. So:
(list-append '(mary had a little lamb) '(her fleece was white as snow))
-> '(mary had a little lamb her fleece was white as snow)
(list-append '() '(eeny meeny miney mo))
-> '(eeny meeny miney mo)
(list-append '(eeny meeny miney mo) '())
-> '(eeny meeny miney mo)
(list-append '() '())
-> '()
- Write a function nth, that takes two
arguments, an integer (n) and a list, and returns the nth element from
the list. If n is larger than the length of the list, return
null (the empty list). If n is less than 1, return null. So:
(nth 2 '(eeny meeny miney mo)) --> 'meeny
(nth 4 '(eeny meeny miney mo)) --> 'mo
(nth 5 '(eeny meeny miney mo)) --> '()
(nth 0 '(eeny meeny miney mo)) --> '()
- Write a function marry, that takes
two lists of equal length as arguments, and returns a list of
pairs of the first elements, the second elements, etc.
Don't worry about the case when the arguments are of unequal length.
So:
(marry '(a b c) '(1 2 3)) --> '((a . 1) (b . 2) (c . 3))
(marry '() '()) --> '()
- Write a function reverse-list, that takes a
list as argument and returns a list of the same elements in
reverse order. So:
(reverse-list '(a b c d)) --> '(d c b a)
(reverse-list '() '()) --> '()
Hint: You may need to write a "helper function" for
reverse-list to call.