Department of Computer Science
Principles of Functional Languages
Fall Semester 2010
Dr. Maury Eggen
Homework Laboratory Assignment 2:
This homework will reinforce some of the things we learned in the previous
exercise. We shall continue to study lists. Add to your list library the
following functions: (if a native function exists for the solution to
any of these problems, it may not be used). (Also, note that all these
index problems should be 0 based, like C or Java)
- 1. index: an "index" function which will return the list element
at a particular index. For example, (index ls 5) will return the fifth
element of the list.
- 2. (reverse-index x ls): a "reverse-index" function which will return
a list of the indices of the positions of an element in a list.
- 3. (find-max ls): a function which will find the maximum element of a list.
- 4. (find-min ls): a function which will find the minimum element of a list.
- 5. (max-index ls): a function which will find the index of the maximum element of a list
- 6. (min-index ls): a function which will find the idnex of the minimum element of a list
- 7. (max-index-list ls): a function which will return a list of all of the maximum elements in
a list (in case the max was repeated).
- 8. (min-index-list ls): a function which will return a list of all of the minimum elements in
a list (in case the min was repeated).
- 9. (wrap-each ls): a function which will wrap each element of a list. For example,
(wrap-each '(1 (2 3) 4)) would return ((1) ((2 3)) (4)).
- 11. (wrap-n ls): a function which will wrap each element of a list n times.
- 12. (count-n x ls): a function which will count the number of instances of an particular
item in a list, no matter how deeply nested. (for example, how many 2's are
there in a deeply nested list?)
- 13. (remove-first x ls): a function which will remove only the first occurrance of a value
from a list.
- 14. remove-nth: a function which will remove only the nth occurrance of a value in a
list. (remove-nth 2 5 ls) will remove the fifth two from ls (if it exists).
- 15. isin?: write a predicate isin? which will determine whether an item is in
a list. (isin? 2 ls)
- 16. weave: a function which will weave two lists of the same length. For example,
(weave '(1 2 3 4) '(a b c d)) would produce (1 a 2 b 3 c 4 d)