Add lab and quiz contents
This commit is contained in:
28
labs/L07/short-circuit.rkt
Normal file
28
labs/L07/short-circuit.rkt
Normal file
@ -0,0 +1,28 @@
|
||||
#lang racket
|
||||
(define-syntax-rule (And a b)
|
||||
(if b a #f))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(define (die)
|
||||
(error 'die "don't run this"))
|
||||
|
||||
(check-equal? (And (die) #f) #f)
|
||||
(check-exn exn:fail? (lambda () (and (die) #f))))
|
||||
|
||||
(module+ test
|
||||
(define-syntax-rule (check-fail expr)
|
||||
(check-exn exn:fail? (lambda () expr)))
|
||||
(check-fail (and (die) #f))
|
||||
(check-fail (And #f (die))))
|
||||
|
||||
(define-syntax-rule (Or a b)
|
||||
(or b a))
|
||||
;(if (not a) b #t))
|
||||
|
||||
(module+ test
|
||||
(check-equal? (Or #t #t) #t)
|
||||
(check-equal? (Or #f #t) #t)
|
||||
(check-equal? (Or #t #f) #t)
|
||||
(check-equal? (Or (die) #t) #t)
|
||||
(check-fail (or (die) #t)))
|
0
labs/L07/short-circuit.rkt~
Normal file
0
labs/L07/short-circuit.rkt~
Normal file
Reference in New Issue
Block a user