add xor, adjust implies following Carl's comments
This commit is contained in:
parent
297db9b305
commit
b2a3b3a8a2
|
@ -3,7 +3,7 @@
|
|||
(provide true false false?
|
||||
boolean=?
|
||||
symbol=?
|
||||
implies nand nor)
|
||||
implies nand nor xor)
|
||||
(require (for-syntax racket/base))
|
||||
|
||||
(define true #t)
|
||||
|
@ -24,9 +24,7 @@
|
|||
(define-syntax (implies stx)
|
||||
(syntax-case stx ()
|
||||
[(implies x y)
|
||||
(syntax/loc stx (if x y #t))]
|
||||
[(implies x y z w ...)
|
||||
(syntax/loc stx (if x (implies y z w ...) #t))]))
|
||||
(syntax/loc stx (if x y #t))]))
|
||||
|
||||
(define-syntax (nor stx)
|
||||
(syntax-case stx ()
|
||||
|
@ -35,3 +33,10 @@
|
|||
(define-syntax (nand stx)
|
||||
(syntax-case stx ()
|
||||
[(_ expr ...) (syntax/loc stx (not (and expr ...)))]))
|
||||
|
||||
(define (xor a b)
|
||||
(if a
|
||||
(if b
|
||||
#f
|
||||
a)
|
||||
b))
|
||||
|
|
|
@ -268,17 +268,33 @@ Returns @racket[(not v)].}
|
|||
|
||||
}
|
||||
|
||||
@defform[(implies expr expr expr ...)]{
|
||||
@defform[(implies expr1 expr2)]{
|
||||
Checks to be sure that the first
|
||||
expression implies the second, implies
|
||||
the third, etc.
|
||||
expression implies the second.
|
||||
|
||||
Same as @racket[(if expr1 expr2 #f)].
|
||||
|
||||
@examples[#:eval
|
||||
bool-eval
|
||||
(implies #f #t)
|
||||
(implies #f #f)
|
||||
(implies #f #f #t)
|
||||
(implies #t #f)
|
||||
(implies #f (error 'ack "we don't get here"))]
|
||||
|
||||
}
|
||||
|
||||
@defproc[(xor [b1 any/c] [b2 any/c]) any]{
|
||||
Returns the exclusive or of @racket[b1] and @racket[b2].
|
||||
|
||||
If exactly one of @racket[b1] and @racket[b2] is
|
||||
not @racket[#f], then return it. Otherwise, returns
|
||||
@racket[#f].
|
||||
|
||||
@examples[#:eval
|
||||
bool-eval
|
||||
(xor 11 #f)
|
||||
(xor #f 22)
|
||||
(xor 11 22)
|
||||
(xor #f #f)]
|
||||
|
||||
}
|
|
@ -20,9 +20,8 @@
|
|||
|
||||
(for ([x (in-list '(#f #t))])
|
||||
(for ([y (in-list '(#f #t))])
|
||||
(for ([z (in-list '(#f #t))])
|
||||
(check-equal? (implies x y z)
|
||||
(or (not x) (or (not y) z))))))
|
||||
(check-equal? (implies x y)
|
||||
(or (not x) y))))
|
||||
(check-equal? (implies #f (car 'x)) #t)
|
||||
|
||||
|
||||
|
@ -37,3 +36,8 @@
|
|||
(check-equal? (nor #f #t) #f)
|
||||
(check-equal? (nor #t #t) #f)
|
||||
(check-equal? (nor #t (car 'x)) #f)
|
||||
|
||||
(check-equal? (xor 11 22) #f)
|
||||
(check-equal? (xor 11 #f) 11)
|
||||
(check-equal? (xor #f 22) 22)
|
||||
(check-equal? (xor #f #f) #f)
|
||||
|
|
Loading…
Reference in New Issue
Block a user