Scheme for all (3): Why not make sense, female ?, Scheme for all
The best thing in life is his friendship with others. -- Lincoln
(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 ))))))
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.