added nand, nor, and implies to racket/bool
This commit is contained in:
parent
ce6d1c042c
commit
4b2f78477a
|
@ -162,14 +162,6 @@
|
|||
[(t a ...) (raise-syntax-error #f "invalid clause" stx s)]))
|
||||
(syntax->list (syntax (something ...))))]))
|
||||
|
||||
(define-syntax (nor stx)
|
||||
(syntax-case stx ()
|
||||
[(_ expr ...) (syntax/loc stx (not (or expr ...)))]))
|
||||
|
||||
(define-syntax (nand stx)
|
||||
(syntax-case stx ()
|
||||
[(_ expr ...) (syntax/loc stx (not (and expr ...)))]))
|
||||
|
||||
(define-syntax (let+ stx)
|
||||
(syntax-case stx ()
|
||||
[(_ [clause ...] body1 body ...)
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
@mzlib[#:mode title etc]
|
||||
|
||||
The @racketmodname[mzlib/etc] library re-exports the following
|
||||
The @racketmodname[mzlib/etc] library re-exports the following from
|
||||
@racketmodname[scheme/base] and other libraries:
|
||||
|
||||
@racketblock[
|
||||
|
@ -35,6 +35,8 @@ The @racketmodname[mzlib/etc] library re-exports the following
|
|||
compose
|
||||
local
|
||||
symbol=?
|
||||
nand
|
||||
nor
|
||||
]
|
||||
|
||||
@defform[(begin-lifted expr ...+)]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#lang scheme/base
|
||||
#lang racket/base
|
||||
|
||||
(provide true false false?
|
||||
boolean=?
|
||||
symbol=?)
|
||||
symbol=?
|
||||
implies nand nor)
|
||||
(require (for-syntax racket/base))
|
||||
|
||||
(define true #t)
|
||||
(define false #f)
|
||||
|
@ -19,3 +21,17 @@
|
|||
(raise-type-error 'symbol=? "symbol" (if (symbol? x) 1 0) x y))
|
||||
(eq? x y))
|
||||
|
||||
(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))]))
|
||||
|
||||
(define-syntax (nor stx)
|
||||
(syntax-case stx ()
|
||||
[(_ expr ...) (syntax/loc stx (not (or expr ...)))]))
|
||||
|
||||
(define-syntax (nand stx)
|
||||
(syntax-case stx ()
|
||||
[(_ expr ...) (syntax/loc stx (not (and expr ...)))]))
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#lang scribble/doc
|
||||
@(require "mz.rkt")
|
||||
|
||||
@(define bool-eval (make-base-eval))
|
||||
@(bool-eval '(require racket/bool))
|
||||
|
||||
@title[#:tag "booleans"]{Booleans and Equality}
|
||||
|
||||
True and false @deftech{booleans} are represented by the values
|
||||
|
@ -242,3 +245,37 @@ Returns @racket[(equal? a b)] (if @racket[a] and @racket[b] are booleans).}
|
|||
|
||||
Returns @racket[(not v)].}
|
||||
|
||||
@defform[(nand expr ...)]{
|
||||
Same as @racket[(not (and expr ...))].
|
||||
|
||||
@examples[#:eval
|
||||
bool-eval
|
||||
(nand #f #t)
|
||||
(nand #f (error 'ack "we don't get here"))]
|
||||
}
|
||||
|
||||
@defform[(nor expr ...)]{
|
||||
Same as @racket[(not (or expr ...))].
|
||||
|
||||
@examples[#:eval
|
||||
bool-eval
|
||||
(nor #f #t)
|
||||
(nor #t (error 'ack "we don't get here"))]
|
||||
|
||||
|
||||
}
|
||||
|
||||
@defform[(implies expr expr expr ...)]{
|
||||
Checks to be sure that the first
|
||||
expression implies the second, implies
|
||||
the third, etc.
|
||||
|
||||
@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"))]
|
||||
|
||||
}
|
|
@ -18,3 +18,22 @@
|
|||
(check-false (false? #t))
|
||||
(check-false (false? "11"))
|
||||
|
||||
(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 #f (car 'x)) #t)
|
||||
|
||||
|
||||
(check-equal? (nand #f #f) #t)
|
||||
(check-equal? (nand #f #t) #t)
|
||||
(check-equal? (nand #t #f) #t)
|
||||
(check-equal? (nand #t #t) #f)
|
||||
(check-equal? (nand #f (car 'x)) #t)
|
||||
|
||||
(check-equal? (nor #f #f) #t)
|
||||
(check-equal? (nor #t #f) #f)
|
||||
(check-equal? (nor #f #t) #f)
|
||||
(check-equal? (nor #t #t) #f)
|
||||
(check-equal? (nor #t (car 'x)) #f)
|
||||
|
|
Loading…
Reference in New Issue
Block a user