adjust
parent
e631c39bf2
commit
99158a360a
@ -1,28 +1,13 @@
|
|||||||
#lang br
|
#lang br
|
||||||
|
|
||||||
(define Nand-a
|
(define+provide (Nand #:a a #:b b)
|
||||||
(let ([Nand-a-val 0])
|
(if (< (+ a b) 2)
|
||||||
(λ ([val #f])
|
|
||||||
(if val
|
|
||||||
(set! Nand-a-val val)
|
|
||||||
Nand-a-val))))
|
|
||||||
|
|
||||||
(define Nand-b
|
|
||||||
(let ([Nand-b-val 0])
|
|
||||||
(λ ([val #f])
|
|
||||||
(if val
|
|
||||||
(set! Nand-b-val val)
|
|
||||||
Nand-b-val))))
|
|
||||||
|
|
||||||
|
|
||||||
(define (Nand-out)
|
|
||||||
(if (< (+ (Nand-a) (Nand-b)) 2)
|
|
||||||
1
|
1
|
||||||
0))
|
0))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit)
|
(require rackunit)
|
||||||
(check-equal? (begin (Nand-a 0) (Nand-b 0) (Nand-out)) 1)
|
(check-equal? (Nand #:a 0 #:b 0) 1)
|
||||||
(check-equal? (begin (Nand-a 0) (Nand-b 1) (Nand-out)) 1)
|
(check-equal? (Nand #:a 0 #:b 1) 1)
|
||||||
(check-equal? (begin (Nand-a 1) (Nand-b 0) (Nand-out)) 1)
|
(check-equal? (Nand #:a 1 #:b 0) 1)
|
||||||
(check-equal? (begin (Nand-a 1) (Nand-b 1) (Nand-out)) 0))
|
(check-equal? (Nand #:a 1 #:b 1) 0))
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
#lang br
|
||||||
|
|
||||||
|
(define Nand-in-a
|
||||||
|
(let ([Nand-a-val 0])
|
||||||
|
(λ ([val #f])
|
||||||
|
(if val
|
||||||
|
(set! Nand-a-val val)
|
||||||
|
Nand-a-val))))
|
||||||
|
|
||||||
|
(define Nand-in-b
|
||||||
|
(let ([Nand-b-val 0])
|
||||||
|
(λ ([val #f])
|
||||||
|
(if val
|
||||||
|
(set! Nand-b-val val)
|
||||||
|
Nand-b-val))))
|
||||||
|
|
||||||
|
|
||||||
|
(define (Nand-out-out)
|
||||||
|
(if (< (+ (Nand-in-a) (Nand-in-b)) 2)
|
||||||
|
1
|
||||||
|
0))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(require rackunit)
|
||||||
|
(check-equal? (begin (Nand-in-a 0) (Nand-in-b 0) (Nand-out-out)) 1)
|
||||||
|
(check-equal? (begin (Nand-in-a 0) (Nand-in-b 1) (Nand-out-out)) 1)
|
||||||
|
(check-equal? (begin (Nand-in-a 1) (Nand-in-b 0) (Nand-out-out)) 1)
|
||||||
|
(check-equal? (begin (Nand-in-a 1) (Nand-in-b 1) (Nand-out-out)) 0))
|
||||||
|
|
||||||
|
|
||||||
|
(struct ins ([a #:auto] [b #:auto]) #:transparent
|
||||||
|
#:auto-value (open-input-bytes #""))
|
||||||
|
(struct outs ([out #:auto]) #:transparent)
|
||||||
|
(struct Nand (i o) #:transparent)
|
||||||
|
|
||||||
|
(define f (Nand (ins) (outs)))
|
Loading…
Reference in New Issue