diff options
author | Ben Sima <ben@bsima.me> | 2019-10-27 09:48:52 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-10-27 12:14:40 -0700 |
commit | c790672cc244ac4caba1bda3572829a6c6862891 (patch) | |
tree | 2706bb8044f7b14840c5f90f215b79b433e81045 /lore/sicp/set.scm | |
parent | 44df4ba39f65c3afd84bee6b03f47d9b061e9038 (diff) |
move everything to namespace directories
Diffstat (limited to 'lore/sicp/set.scm')
-rw-r--r-- | lore/sicp/set.scm | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/lore/sicp/set.scm b/lore/sicp/set.scm deleted file mode 100644 index 3d60c5c..0000000 --- a/lore/sicp/set.scm +++ /dev/null @@ -1,42 +0,0 @@ -;; A set module, based on binary trees (from sicp) - -(define (entry tree) (car tree)) -(define (left-branch tree) (cadr tree)) -(define (right-branch tree) (caddr tree)) - -(define (make-tree entry left right) - (list entry left right)) - -(define (element-of-set? x set) - (cond ((null? set) #f) - ((= x (entry set)) #t) - ((< x (entry set)) - (element-of-set? x (left-branch set))) - ((> x (entry set)) - (element-of-set? x (right-branch set))))) - -(define (adjoin-set x set) - (cond ((null? set) (make-tree x '() '())) - ((= x (entry set)) set) - ((< x (entry set)) - (make-tree (entry set) - (adjoin-set x (left-branch set)) - (right-branch set))) - ((> x (entry set)) - (make-tree (entry set) - (left-branch set) - (adjoin-set x (right-branch set)))))) - -(define (intersection-set set1 set2) - (if (or (null? set1) (null? set2)) - '() - (let ((x1 (car set1)) - (x2 (car set2))) - (cond ((= x1 x2) - (cons x1 - (intersection-set (cdr set1) - (cdr set2)))) - ((< x1 x2) - (intersection-set (cdr set1) set2)) - ((< x2 x1) - (intersection-set set1 (cdr set2))))))) |