Dots, Dashes, and State Machines
Picture this: You’re standing in a field at midnight, camera mounted on a tripod, watching a distant amateur radio beacon flash its callsign in Morse code. Over the next four hours, as stars trace their ancient arcs, your long exposure captures not just celestial motion but the rhythmic pulse of electromagnetic conversation—dots and dashes painting temporal brushstrokes across the sky.
Morse code is pure state machine poetry. Each character lives as a sequence of transitions: key down (dot or dash), key up (pause), longer pause (end of character). The beacon doesn’t think in letters—it thinks in states.
(def morse-states
{:idle {:dot :signal, :dash :signal}
:signal {:end-element :pause}
:pause {:dot :signal, :dash :signal, :end-char :idle}})
(defn morse-step [state input]
(get-in morse-states [state input] :error))
(defn encode-char [char timing]
(let [pattern (get {\A ".-", \S "..."} char)]
(map #(if (= % \.) (:dot timing) (:dash timing)) pattern)))
Clojure treats states as immutable transitions—data describing data. The machine becomes a simple lookup, elegant as starlight itself.
Ada, born in the era when automata theory was crystallizing into computer science, demands more ceremony but rewards with ironclad guarantees:
type Morse_State is (Idle, Signalling, Pause);
type Element_Type is (Dot, Dash, Space, End_Char);
function Next_State(Current : Morse_State; Input : Element_Type)
return Morse_State is
begin
case Current is
when Idle => return (if Input in Dot | Dash then Signalling else Idle);
when Signalling => return Pause;
when Pause => return (if Input = End_Char then Idle else Signalling);
end case;
end Next_State;
Both capture the same truth: communication protocols are just state machines dressed up for different occasions. Your beacon’s timing circuits implement this automaton in hardware, while your image stacking software implements another—detecting and aligning stellar patterns across frames. State machines all the way down, from silicon to stars to the satisfying click of a Morse key cutting through the darkness.