Add invert-filter and use it in -imp.
This commit is contained in:
parent
2fda610c54
commit
a662f72c9e
|
@ -110,14 +110,26 @@
|
||||||
(loop (cdr props) others)]
|
(loop (cdr props) others)]
|
||||||
[p (loop (cdr props) (cons p others))]))))
|
[p (loop (cdr props) (cons p others))]))))
|
||||||
|
|
||||||
|
;; invert-filter: Filter/c -> Filter/c
|
||||||
|
;; Logically inverts a filter.
|
||||||
|
(define (invert-filter p)
|
||||||
|
(match p
|
||||||
|
[(Bot:) -top]
|
||||||
|
[(Top:) -bot]
|
||||||
|
[(TypeFilter: t p o) (-not-filter t o p)]
|
||||||
|
[(NotTypeFilter: t p o) (-filter t o p)]
|
||||||
|
[(AndFilter: fs) (apply -or (map invert-filter fs))]
|
||||||
|
[(OrFilter: fs) (apply -and (map invert-filter fs))]
|
||||||
|
[(ImpFilter: f1 f2) (-and f1 (invert-filter f2))]))
|
||||||
|
|
||||||
|
;; -imp: Filter/c Filter/c -> Filter/c
|
||||||
|
;; Smart constructor for make-ImpFilter
|
||||||
(define (-imp p1 p2)
|
(define (-imp p1 p2)
|
||||||
(match* (p1 p2)
|
(match* (p1 p2)
|
||||||
[((Bot:) _) -top]
|
[((Bot:) _) -top]
|
||||||
[(_ (Top:)) -top]
|
[(_ (Top:)) -top]
|
||||||
[((Top:) _) p2]
|
[((Top:) _) p2]
|
||||||
[((TypeFilter: t p o) (Bot:)) (-not-filter t o p)]
|
[(_ (Bot:)) (invert-filter p1)]
|
||||||
[((NotTypeFilter: t p o) (Bot:)) (-filter t o p)]
|
|
||||||
[(_ _) (make-ImpFilter p1 p2)]))
|
[(_ _) (make-ImpFilter p1 p2)]))
|
||||||
|
|
||||||
(define (-or . args)
|
(define (-or . args)
|
||||||
|
|
|
@ -111,6 +111,8 @@
|
||||||
(check-equal? (-imp (-filter -Symbol #'x) -top) -top)
|
(check-equal? (-imp (-filter -Symbol #'x) -top) -top)
|
||||||
(check-equal? (-imp (-filter -Symbol #'x) -bot) (-not-filter -Symbol #'x))
|
(check-equal? (-imp (-filter -Symbol #'x) -bot) (-not-filter -Symbol #'x))
|
||||||
(check-equal? (-imp (-not-filter -Symbol #'x) -bot) (-filter -Symbol #'x))
|
(check-equal? (-imp (-not-filter -Symbol #'x) -bot) (-filter -Symbol #'x))
|
||||||
|
(check-equal? (-imp (-imp (-not-filter -Symbol #'x) (-not-filter -Symbol #'y)) -bot)
|
||||||
|
(-and (-not-filter -Symbol #'x) (-filter -Symbol #'y)))
|
||||||
(check-equal?
|
(check-equal?
|
||||||
(-imp (-not-filter -Symbol #'x)
|
(-imp (-not-filter -Symbol #'x)
|
||||||
(-not-filter -Symbol #'y))
|
(-not-filter -Symbol #'y))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user