chapter 8 exercise 8-4: implement swap