Here are some more netlist examples. As I get questions, I will update this file, so check it if you have questions and before submitting your solutions.
Consider the following code segment (which is the same as on the main page for the project).
(defconst *defs1*
'((maj (a b c)
(d)
((0 (and a b))
(1 (and a c))
(2 (and b c))
(d (or 0 1 2))))
(fa (a b cin)
(s cout)
((s (xor a b cin))
(cout (maj a b cin))))
(adder-2-bit (a1 a0 b1 b0 cin)
(cout c1 c0)
(((c0 0) (fa a0 b0 cin))
((c1 cout) (fa a1 b1 0))))))
Now, here are some examples of evaluating expressions that use the above definitions.
(net-val *defs1*
'(((out d1 d0)
(adder-2-bit e1 e0 a1 a0 in)))
'(out d1 d0)
'((e1 . 1) (e0 . 0)
(a1 . 1) (a0 . 1)
(in . 1)))
It returns
(1 1 0)
Another way of assigning values to the wires is to use the const
construct and wire builtin functions. To show how a few ways in
which they can be used, consider the following.
(net-val *defs1*
'(((e1 e0) (const 1 0))
((a1) (const 1))
(a0 (wire a1))
(in (const 1))
((out d1 d0)
(adder-2-bit e1 e0 a1 a0 in)))
'(out d1 d0)
nil)
This returns the same answer as before, namely
(1 1 0)
Note that the second line of the expression could have been written (a1 (const 1)). This shows how to create constants using const and how to assign values using wire.