exam10.1.4

413阅读 0评论2011-11-18 maunix
分类:LINUX

  1. ;; mht created on Nov 15, 2011

  2. ;; convert-euro : list-of-numbers -> list-of-numbers
  3. ;; exchange rate is 1.22 euro for each dollar
  4. (define (convert-euro a-list-of-nums)
  5.   (cond
  6.     [(empty? a-list-of-nums) empty]
  7.     [else
  8.      (cons
  9.       ( * 1.22 (first a-list-of-nums))
  10.       (convert-euro (rest a-list-of-nums)))]))

  11. ;; test
  12. (convert-euro (cons 10 (cons 20 empty)))

  13. ;; convert-euro : number list-of-numbers -> list-of-numbers
  14. (define (convert-euro-1 rate a-list-of-nums)
  15.   (cond
  16.     [(empty? a-list-of-nums) empty]
  17.     [else
  18.      (cons
  19.       ( * rate (first a-list-of-nums))
  20.       (convert-euro-1 1.22 (rest a-list-of-nums)))]))

  21. ;; test
  22. (convert-euro-1 1.22 (cons 10 (cons 20 empty)))
上一篇:exam10.1.2
下一篇:exam14.2.1