Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. 1 ]=> ; Exercise 1.9. Each of the following two procedures defines a method for adding two positive integers in terms of the procedures inc, which increments its argument by 1, and dec, which decrements its argument by 1.
  2. (define (inc x)
  3. (+ x 1))
  4. ;Value: inc
  5.  
  6. 1 ]=> (define (dec x)
  7. (- x 1))
  8. ;Value: dec
  9.  
  10. 1 ]=> (define (+ a b)
  11. (display a)(newline)
  12. (if (= a 0)
  13. b
  14. (inc (+ (dec a) b))))
  15. ;Value: +
  16.  
  17. 1 ]=> (+ 4 5)4
  18. 3
  19. 2
  20. 1
  21. 0
  22. 5
  23. 4
  24. 3
  25. 2
  26. 1
  27. 0
  28. 1
  29. 0
  30. 1
  31. 0
  32. 1
  33. 0
  34. 1
  35. 0
  36. 1
  37. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement