If someone can figure out how to implement a flip-flop, then we're in business. (http://en.wikipedia.org/wiki/Flip-flop_%28electronics%29)
http://dwarffortresswiki.net/index.php/Mechanical_logic#Flip...
One of the best things about dwarf fortress is that playing it using that initially-confusing interface rather than shiny graphics is like doing math using symbols and equations rather than paragraphs and paragraphs of words.
A
→o * o→M O
o * o
B
The mechanical power goes in the first →, and the [M O] part is the output. A and B are the AND inputs. Gearboxes actually look like *, but o is also being used for gearboxes, albeit gearboxes that are just there to drain power.