Notes on problem 7.1

let has two main uses:

  1. Make code easier to read and modify by using meaningful names in place of complex expressions
  2. Make code faster by executing complex code once and storing the value in a variable; that variable can then be looked up as often as desired without having to execute the complex code again.

The point of problem 7.1 is to address #2. The expression (if (vowel? (first wd)) 'an 'a) need not be executed three times. It could be executed once with the result being stored in a variable. Use let to do this.

It is fair to say that a weakness of this problem is that you won't be able to perceive the time savings when you run your solution. But avoiding redundant computations is important and we will see more powerful examples of that as we go through the rest of the class. Getting into good habits is also important, and part of that is getting more comfortable with using let.

You may also feel that the point of problem 7.1 is to that the code will end up easier to read. I won't quibble.