Post Reply 
A LANGUAGE FOR DIGITAL DESIGN
03-05-2019, 10:25 PM
Post: #4
Clojure: A LANGUAGE FOR DIGITAL DESIGN
Clojure Code
Code:
(defn S
    "types the value and time of a signal (+ indicating +5V)."
    [x]
    (let [t (bit-and 0x7FFF x)]
        (if (zero? (bit-and 0x8000 x))
            (str t)
            (str "+" t))))
 
(defn _
    "complements a signal (without changing its time)."
    [a]
    (bit-xor a 0x8000))
 
(defn AND
    "combines 2 signals with worst case timing."
    [a b]
    (+  (max
            (bit-and a 0x7FFF)
            (bit-and b 0x7FFF))
        (bit-and
            (bit-and a 0x8000)
            (bit-and b 0x8000))))
 
(defn OR
    "combines 2 signals using DeMorgan's law."
    [a b]
    (_ (AND (_ a) (_ b))))
 
(defn AND2_
    "is a 2-input nand gate with 9ns delay."
    [a b]
    (+ (_ (AND a b)) 9))
 
(defn OR3
    "is a 3-input or gate with 30ns delay."
    [a b c]
    (+ (OR (OR a b) c) 30))
 
(defn XOR2
    "is a 2-input exclusive-or gate with 35ns delay."
    [a b]
    (+ (OR (AND a (_ b)) (AND (_ a) b)) 35))
 
(def A 0) ; is a signal known low at 0ns.
 
(def B 10) ; is a signal known low at 10ms.
 
(def C (_ 10)) ; is a signal known high at 10ms.
 
(defn ENB_
    "is a signal determined low by A and B at 45ns."
    []
    (XOR2 A B))
 
(defn XY
    "is a signal determined high by A, B and C at 84ns."
    []
    (OR3 (AND2_ (ENB_) C) A B))

Clojure REPL
Code:
user=> (S (ENB_))
"45"

user=> (S (XY))
"+84"
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Clojure: A LANGUAGE FOR DIGITAL DESIGN - Thomas Klemm - 03-05-2019 10:25 PM



User(s) browsing this thread: 1 Guest(s)