CS330 Spring 2004 Lecture 6

George Tzanetakis

Slides 

This lecture will not contain any slides as it consists mainly of
programming examples in sml.

SML code

Code in text format
 

Suggested exercises

6.1) Declare an SML function rmodd removing the odd-numbered elements from a list:

rmod[x1,x2,x3,x4,....] = [x2, x4, ... ]

6.2) Declare an SML function nubmer(x,ys) to find the number of times x occurs in the list ys.

6.3) Declare an SML function split such that:

split [x1,x2,x3,x4,.....xn] = ([x1,x3,....], [x2, x4,....])


6.3) A string is called a palindrome if it is identical with the reversed string instance
"ole elo" is a palindrome, while "ol elo" is not. Write a function determining whether
a stirng is a palindrome.

6.4) Declare a function sum (p,xs) where p is a predicate of type int->bool and xs is a list
of integers. The value of sum(p,xs) is the sum of the elements in xs satisfying the predicate
p. Test the function on different predicates (e.g p(x) = x > 0).