The trap is a stateful roon with two states.
vacant mode
In vacant mode, the trap supports two operations:
- If a
enters the left side, it passes directly through.
- If a
enters the right side, the trap holds it in place and enters occupied mode.
occupied mode
In occupied mode, the trap’s behaviour changes:
- If a
enters the left side, it dislodges the trapped
. The trap ejects both
and returns to vacant mode.
- If a
enters the right side, it is deflected by half a cell to the right. The trapped
remains in place.
application
The trap allows us to delay operations so we can sync them up to an appropriate time.
We’re going to build a zero checker. This is a device that checks whether a number in a stream is zero.
If we’re using (say) 4-bit numbers, then zero is . If we encounter
at any point in the cycle, such as
or
, we know the number isn’t zero. But we don’t want to release this
immediately — we want to wait until the entire number is processed, and then release either a
(to indicate a non-zero number) or a
(to indicate zero).
Traps are perfect for this:
This device receives a stream of 4-bit numbers, and releases a stream indicating whether they are zero or non-zero.
Note the presence of a pause hole p. Even though our words are 4 bit, the device repeats on a cycle of 5, where the 5th bit is always . This is to ensure there’s no data
to interfere with the trap when it releases any captured
.
Next, we’ll upgrade this into a more powerful checker.
continue