CSE 341
Assignment 1: Scheme Warmup

Due on Monday, June 28, 1999


Write and test these functions using the Dr. Scheme development environment:

  1. a function that computes the absolute value of a number, i.e. takes one numerical parameter and returns its absolute value

    example usage:

    > (abs-val -2.1221)
    2.1221
    
  2. a function that takes a list of numbers and returns a list of the squares of the numbers (again, in the same order)

    example usage:

    > (square-list-alt '(1 5.2 7 -3 0))
    (1 27.04 49 9 0)
    
  3. a function that takes a list of numbers and a number k and returns a list containing only those list elements which are greater than or equal to k

    Ordering should be preserved, i.e. the numbers in the returned list should be in the same order as in the original list.

    example usage:

    > (filter-ge '(1 5 7 -3 8 3 -4 4) 4)
    (5 7 8 4)
    
    Hint: See Exercise 10.5 in the Sethi text.

  4. a function that takes a unary predicate (as a function) and a list and returns a list containing only those list elements for which the predicate is true, i.e. a list filtered according to the predicate

    example usage:

    > (define (non-negative x) (>= x 0))
    > (filter non-negative '(-2 3 -1 1 4))
    (3 1 4)
    
    Hint: Note that this function is just a generalization of the function in the previous exercise.


Back to the 341 home page...
Last modified: Wed Jun 23 10:26:57 PDT 1999