CSE 413 -- Scheme Mini-Exercises

These mini-exercises are to do in class, or afterwards on your own or in groups. They are not to be handed in or graded. Check your answers on the computer as appropriate.

  1. Write a Scheme expression to compute 3*x+y+10. (Assume that the variables x and y are properly bound.)
  2. What is the result of evaluating the following expressions?
  3. Suppose we evaluate

    Then what is the result of evaluating

  4. Define a function to compute the cube of a number.
  5. Joe Hacker states loudly that there is no reason or in Scheme needs to be special -- it can just be defined by the programmer, like this:
    (define (or x y)
      (if x #t y))
    

    Is Joe right?

  6. Given the following definitions

    what is the result of evaluating

  7. Define a recursive function that takes a list of numbers and returns a list of their square roots. Thus (sqrts 1.0 2.0 4.0) should return (1.0 1.41421 2.0). (Hint: the answer to the question you were about to ask is sqrt.) What recursion pattern does this function use?
  8. Define a function that takes a list of numbers (nested to any depth) and returns the sum of the numbers. In other words, the argument can be a number, a list of lists of lists of numbers, etc. Thus (sum '(1 (2) ((3 4)) 5)) should return 15. What recursion pattern does this function use?
  9. Give a different (non-recursive) definition of the sqrts function using map.