Weather Patterns Make Musical Patterns
When CYYZ reports “BKN008 OVC015” — broken clouds at 800 feet, overcast at 1500 — what chord should that become? A minor seventh for the low ceiling, perhaps, with a suspended fourth for the uncertainty above?
Pattern matching emerged in the 1980s as a way to elegantly destructure data by its shape rather than its position. Unlike conditional chains that ask “what is this?”, pattern matching declares “when this looks like that, do this.” It’s the difference between interrogation and recognition.
weatherToChord: metar
| matcher |
matcher := Dictionary new.
matcher at: #clear put: #majorSeventh;
at: #broken put: #minor;
at: #overcast put: #diminished;
at: #fog put: #suspended.
^ metar tokens collect: [:token |
(token beginsWith: 'BKN') ifTrue: [matcher at: #broken]
ifFalse: [(token beginsWith: 'OVC') ifTrue: [matcher at: #overcast]
ifFalse: [matcher at: #clear]]].
Smalltalk’s message-passing treats pattern matching as a conversation: “If you begin with BKN, you are broken clouds; respond with a minor chord.” The beauty lies in how naturally the language flows from question to answer.
Rust approaches the same problem with algebraic precision:
fn metar_to_chord(condition: &str) -> &'static str {
match condition {
s if s.starts_with("CLR") => "C-major-7",
s if s.starts_with("BKN") => "A-minor",
s if s.starts_with("OVC") => "F-diminished",
s if s.starts_with("FG") => "G-suspended",
_ => "silence"
}
}
Where Smalltalk flows like jazz improvisation, Rust’s match exhaustively covers all possibilities — there’s safety in knowing every weather pattern has its musical counterpart, and silence for the unrecognized. Both languages understand that good pattern matching isn’t just about parsing text; it’s about transforming one domain’s vocabulary into another’s poetry.