exam3.3.1

370阅读 0评论2011-12-07 maunix
分类:LINUX

  1. ;; mht created on Nov 9, 2011

  2. ;; constant definitions
  3. (define in2cm 2.54)
  4. (define ft2in 12)
  5. (define yd2ft 3)
  6. (define rd2yd (* 5 (/ 1 2)))
  7. (define fl2rd 40)
  8. (define ml2fl 8)

  9. ;; inches->cm : number -> number
  10. ;; to convert inch to cm
  11. (define (inches->cm in)
  12.   (* in2cm in))

  13. ;; feet->inches : number -> number
  14. (define (feet->inches ft)
  15.   (* ft2in ft))

  16. ;; yards->feet : number -> number
  17. (define (yards->feet yd)
  18.   (* yd2ft yd))

  19. ;; rods->yards : number -> number
  20. (define (rods->yards rd)
  21.   (* rd2yd rd))

  22. ;; fulongs->rods : number -> number
  23. (define (furlongs->rods fl)
  24.   (* fl2rd fl))

  25. ;; miles->furlongs : number -> number
  26. (define (miles->furlongs ml)
  27.   (* ml2fl ml))


  28. ;; feet->cm : number -> number
  29. (define (feet->cm ft)
  30.   (inches->cm (feet->inches ft)))

  31. ;; test:
  32. (feet->cm 1)

  33. ;; yards->cm : number -> number
  34. (define (yards->cm yd)
  35.   (feet->cm (yards->feet yd)))

  36. ;; test:
  37. (yards->cm 1)

  38. ;; rods->inches : number -> number
  39. (define (rods->inches rd)
  40.   (feet->inches (yards->feet (rods->yards rd))))
  41. ;;test
  42. (rods->inches 1)

  43. ;; miles->feet: number -> number
  44. (define (miles->feet mi)
  45.   (yards->feet (rods->yards (furlongs->rods (miles->furlongs mi)))))

  46. ;; test
  47. (miles->feet 1)
  48. (* 3 (* 5 (/ 1 2)) 40 8)
上一篇:exam3.1.1-exam3.1.4
下一篇:exam3.3.2-3.3.4