Chinaunix首页 | 论坛 | 博客
  • 博客访问: 222389
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: LINUX

2011-11-18 11:12:10

  1. ;; mht created on Nov 15, 2011

  2. ;; check-range1? : list-of-numbers -> boolean
  3. ;; to check whether all items in a-list-of-nums are in interval [5, 95]
  4. (define (check-range1? a-list-of-nums)
  5.   (cond
  6.     [(empty? a-list-of-nums) true]
  7.     [else
  8.      (and
  9.       (is-between-5-and-95? (first a-list-of-nums))
  10.       (check-range1? (rest a-list-of-nums)))]))

  11. ;; is-between-5-and-95? : number -> boolean
  12. (define (is-between-5-and-95? n)
  13.   (and
  14.    (< 5 n)
  15.    (< n 95)))


  16. ;; test:
  17. (check-range1? empty)
  18. (check-range1? (cons 25 (cons 35 (cons 90 empty))))
  19. (not (check-range1? (cons 25 (cons 95 (cons 23 empty)))))

  20. ;; generalized-check-range1? : list-of-numbers number number -> boolean
  21. ;; to check whether all items in a-list-of-nums are in interval[n1 n2]
  22. (define (generalized-check-range1? a-list-of-nums n1 n2)
  23.   (cond
  24.     [(empty? a-list-of-nums) true]
  25.     [else
  26.      (and
  27.       (is-between-interval? (first a-list-of-nums) n1 n2)
  28.       (generalized-check-range1? (rest a-list-of-nums) n1 n2))]))

  29. ;; is-between-interval? : number number number -> boolean
  30. ;; to determine n is in [n1 n2]
  31. (define (is-between-interval? n n1 n2)
  32.   (and
  33.    (< n1 n)
  34.    (< n n2)))


  35. ;; test:
  36. (generalized-check-range1? empty 5 95)
  37. (generalized-check-range1? (cons 25 (cons 35 (cons 90 empty))) 5 95)
  38. (not (generalized-check-range1? (cons 25 (cons 95 (cons 23 empty))) 5 95))
阅读(250) | 评论(0) | 转发(0) |
0

上一篇:exam9.5.3

下一篇:exam9.5.6

给主人留下些什么吧!~~