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

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: LINUX

2011-11-18 11:07:35

  1. ;; mht created on Nov 15, 2011

  2. ;; data definition:
  3. ;; A list-of-numbers is either
  4. ;; 1. the empty list, empty, or
  5. ;; 2. (cons n lon) where n is a number and lon is a list of numbers.

  6. ;; sum : list-of-numbers -> number
  7. ;; to compute the sum of the numbers on a-list-of-nums

  8. ;; examples: (= (sum empty) 0)
  9. ;; (= (sum (cons 1.00 empty)) 1.00)
  10. ;; (= (sum (cons 1.22 (cons 2.59 empty)) 3.81)

  11. (define (sum a-list-of-nums)
  12.   (cond
  13.     [(empty? a-list-of-nums) 0]
  14.     [else
  15.      (+
  16.       (first a-list-of-nums)
  17.       (sum (rest a-list-of-nums)))]))

  18. ;; test
  19. (= (sum empty)
  20.    0)
  21. (= (sum (cons 1.00 empty))
  22.    1.00)
  23. (= (sum (cons 17.05 (cons 1.22 (cons 2.59 empty))))
  24.    20.86)
阅读(417) | 评论(0) | 转发(0) |
0

上一篇:HTDP习题答案说明

下一篇:exam9.5.2

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