关闭

全民Scheme(3):为什么就不讲道理呢,女人?

标签: scheme
1298人阅读 评论(0) 收藏 举报
分类:


人生最美好的东西,就是他同别人的友谊。——林肯

(define set?
  (lambda (l)
    (cond
    ((null? l) #t)
    ((member? (car l) (cdr l)) #f)
    (else (set? (cdr l))))))
(set? '(apples peaches pear plums))
(set? '(apple peaches apple plum))
(define makesetx
  (lambda (lat)
    (cond
      ((null? lat) '())
      ((member? (car lat) (cdr lat)) (makesetx (cdr lat)))
      (else (cons (car lat) (makesetx (cdr lat)))))))
(makesetx '(apple peach pear peach plum apple lemon peach))
(define makeset
  (lambda (lat)
    (cond
      ((null? lat) '())
      ((member? (car lat) (cdr lat)) (cons (car lat) (makeset (multirember (car lat) (cdr lat)))))
      (else (cons (car lat) (makeset (cdr lat)))))))
(makeset '(apple peach pear peach plum apple lemon peach))
(makeset '(apple 3 pear 4 9 apple 3 4))
(define subset?
  (lambda (set1 set2)
    (cond
      ((null? set1) #t)
      ((member? (car set1) set2) (subset? (cdr set1) set2))
      (else #f))))
(subset? '(4 pounds of horseradish) '(four pounds chicken and 5 ounces horseradish))
(subset? '(5 chicken wings) '(5 hamburgers 2 pieces fried chicken and light duckling wings))
(define subsetx?
  (lambda (set1 set2)
    (cond
      ((null? set1) #t)
      (else (and (member? (car set1) set2)
                 (subsetx? (cdr set1) set2))))))
(define eqset?
  (lambda (set1 set2)
    (cond
      ((subset? set1 set2)
      (subset? set2 set1))
      (else #f))))
(define eqsetx?
  (lambda (set1 set2)
      (and (subsetx? set1 set2) (subsetx? set2 set1))))
(define intersect?
  (lambda (set1 set2)
    (cond
      ((null? set1) #f)
      (else
       (or (member? (car set1) set2)
           (intersect? (cdr set1) set2))))))
(intersect? '(stewed tomatoes and macaroni) '(macaroni and cheese))
(define union
  (lambda (set1 set2)
    (cond
      ((null? set1) set2)
      ((member? (car set1) set2)
       (union (cdr set1) set2))
      (else (cons (car set1)
                  (union (cdr set1) set2))))))


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人简介
    个人资料
    • 访问:760176次
    • 积分:7977
    • 等级:
    • 排名:第2700名
    • 原创:274篇
    • 转载:6篇
    • 译文:1篇
    • 评论:204条
    我的小站
    最新评论
    --
    我要啦免费统计