From 99158a360aa8765910839d59579a140ab329a42f Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 16 May 2016 17:27:02 -0700 Subject: [PATCH] adjust --- beautiful-racket/br/demo/hdl/Nand.hdl.rkt | 27 ++++------------ beautiful-racket/br/demo/hdl/Nand2.hdl.rkt | 36 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 beautiful-racket/br/demo/hdl/Nand2.hdl.rkt diff --git a/beautiful-racket/br/demo/hdl/Nand.hdl.rkt b/beautiful-racket/br/demo/hdl/Nand.hdl.rkt index 40b2504..8655fa2 100644 --- a/beautiful-racket/br/demo/hdl/Nand.hdl.rkt +++ b/beautiful-racket/br/demo/hdl/Nand.hdl.rkt @@ -1,28 +1,13 @@ #lang br -(define Nand-a - (let ([Nand-a-val 0]) - (λ ([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) +(define+provide (Nand #:a a #:b b) + (if (< (+ a b) 2) 1 0)) (module+ test (require rackunit) - (check-equal? (begin (Nand-a 0) (Nand-b 0) (Nand-out)) 1) - (check-equal? (begin (Nand-a 0) (Nand-b 1) (Nand-out)) 1) - (check-equal? (begin (Nand-a 1) (Nand-b 0) (Nand-out)) 1) - (check-equal? (begin (Nand-a 1) (Nand-b 1) (Nand-out)) 0)) + (check-equal? (Nand #:a 0 #:b 0) 1) + (check-equal? (Nand #:a 0 #:b 1) 1) + (check-equal? (Nand #:a 1 #:b 0) 1) + (check-equal? (Nand #:a 1 #:b 1) 0)) diff --git a/beautiful-racket/br/demo/hdl/Nand2.hdl.rkt b/beautiful-racket/br/demo/hdl/Nand2.hdl.rkt new file mode 100644 index 0000000..139d2db --- /dev/null +++ b/beautiful-racket/br/demo/hdl/Nand2.hdl.rkt @@ -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))) \ No newline at end of file