Exercise: Rewriting with Result

In this exercise we’re revisiting the expression evaluator exercise that we did in day 2. Our initial solution ignores a possible error case: Dividing by zero! Rewrite eval to instead use idiomatic error handling to handle this error case and return an error when it occurs. We provide a simple DivideByZeroError type to use as the error type for eval.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Speaker Notes

This slide and its sub-slides should take about 20 minutes.
  • The starting code here isn’t exactly the same as the previous exercise’s solution: We’ve added in an explicit panic to show students where the error case is. Point this out if students get confused.