码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-07 00:55:57      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:scheme


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

(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))))))


版权声明:本文为博主原创文章,未经博主允许不得转载。

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

标签:scheme

原文地址:http://blog.csdn.net/booirror/article/details/46781653

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!