Walt Whitman wrote O Captain! My Captain! in 1865, in the weeks after Abraham Lincoln was assassinated. The whole poem is a single figure: the ship is the United States, the fearful trip is the Civil War just ended, the won prize is the Union preserved — and the captain who brought the ship through it lies dead on the deck as it reaches port. The bells and the cheering crowds are for a victory the one man who earned it did not live to see.
It became the most loved poem of Whitman's life, and the one he half regretted. It is nothing like the long, unrhymed, surging lines of the rest of Leaves of Grass; it rhymes, it keeps a regular beat, it repeats its refrain — a conventional elegy from the least conventional poet in America. "I'm almost sorry I ever wrote it," he said late in life, tired of being asked for it.
But the machinery works. Each stanza opens in public — flags, bugles, the swaying mass — and closes in private, the speaker's voice dropping to "But O heart! heart! heart!" and to the father lying still beneath his hand. This is the 1882 text, from the last edition Whitman himself arranged.