ML Lecture 9

Announcements:

  1. Questions on Lab3, Lab4

More List Topics

  1. The operator :: lets you build a list out of a value and an existing list. It simply puts the value into the list as the first element (the head). This operator is called cons for historical reasons
  2. The operator @ also builds a list, but out of two lists. It just concatenates them together, just as they are.

Exam-taking strategies

  1. My job: to determine how much you know
  2. Your own goal: to maximize your points
  3. Your job: to show me how much you know
    1. Can say too little, or too much
  4. Usually a bad idea to just do problem 1, then problem 2, etc.
  5. First, read through the exam quickly -- just check each problem out
    1. While doing this, look at how many points each is worth
  6. Next, do the problems that look easy to you first
  7. Then do the hard (for you) problems
  8. Very important concept: partial credit
    1. A partly correct answer will get some points
    2. If you can't figure out a problem, don't leave it blank. That's the worst thing you can do (unless you ran out of time)
    3. Try to solve part of the problem.

Programming examples

  1. Go over good solutions to assignments in class, for Lab1 and Lab2.
  2. Do some list processing examples

Carrying values or a result through recursive calls

  1. Examples of recursion we've seen so far tend to accumulate a result. For example, we've summed up all the elements in a list, or multiplied them, etc.
  2. We've done this by using the recursive call in an expression
  3. Some problems simply need for you to find a certain value, or determine where in a list a certain value is

Searching in a list

  1. Generally, two base cases
    1. One where the thing you search for is found (i.e. you reach the element in the list that matches)
    2. One where it is not found (i.e., you reach the end of the list)