You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket/br/demo/hdl/Xor0.hdl

38 lines
1006 B
Plaintext

#lang racket/base
(provide Xor)
(define Xor
(make-keyword-procedure
(λ (kws kw-args . rest)
(define kw-pairs (map cons kws kw-args))
(let ([a (cdr (assq (string->keyword (format "~a" 'a)) kw-pairs))]
[b (cdr (assq (string->keyword (format "~a" 'b)) kw-pairs))])
(define nota
(let ()
(local-require "Not.hdl")
(Not #:in a)))
(define notb
(let ()
(local-require "Not.hdl")
(Not #:in b)))
(define w1
(let ()
(local-require "And.hdl")
(And #:a a #:b notb)))
(define w2
(let ()
(local-require "And.hdl")
(And #:a nota #:b b)))
(define out
(let ()
(local-require "Or.hdl")
(Or #:a w1 #:b w2)))
out))))
(module+ test
(require rackunit)
(check-equal? (Xor #:a 0 #:b 0) 0)
(check-equal? (Xor #:a 0 #:b 1) 1)
(check-equal? (Xor #:a 1 #:b 0) 1)
(check-equal? (Xor #:a 1 #:b 1) 0))