Code as Poetry
Verse in the syntax of the languages the lab actually runs: a loop, a guard clause, a comment doing the work a line break would elsewhere. None of it compiles — that was never the point.
Worked example: Poem IV, line by line
The form's whole method is here in five lines: pick a language feature that already has a meaning, and don't translate it — let it stand for itself. Rust's borrow checker distinguishes owning a value from merely referencing it; that distinction, and only that one, is the entire poem.
struct Heart;
fn devotion(mine: &Heart) {
// I do not need to consume you to know you
// Immutably borrowed, completely safe
let _view = mine;
}
fn main() {
let my_heart = Heart;
devotion(&my_heart);
// Because I only borrowed your presence,
// you remain entirely whole when I leave
let _stills_yours = my_heart;
}
struct Heart;— a unit struct: no fields, nothing to extract or spend. The heart isn't data to be read out; it's just a thing that exists.fn devotion(mine: &Heart)— the function signature takes a reference to a Heart, not the Heart itself. In Rust this is a real, load-bearing distinction: a reference borrows; only a bareHeartparameter would take ownership.- The two comments inside
devotionstate the poem's claim directly, and the code backs it:let _view = minebinds a look at the value, never the value. devotion(&my_heart)inmainpasses a borrow across the call. Ownership ofmy_heartnever leaves the caller's scope — the compiler enforces this; a version that instead moved the value would fail to compile ifmaintried to usemy_heartagain afterward.let _stills_yours = my_heartis only legal because nothing upstream ever took ownership. The line that proves the poem's argument and the line that would fail to compile if the argument were false are the same line.
- Poem IRuby
loop do me.yield_to(you) break if eternity # A rhythm clean enough # to leave no traces behind ensure me.love(you) end
- Poem IISwift
func protect(relationship: Bond?) { guard let activeBond = relationship else { // If the connection drops, we return early; // we cannot run on hollow terms return } // Safe unboxing of the future print("Cherishing \(activeBond.depth)") } - Poem IIIRust
fn main() { // A love that cannot be corrupted from the outside let my_word: &'static str = "Unconditional"; { // Even when scoped inside the briefest moment, // it outlives the frame that created it let _moment = &my_word; } // Static lifetimes survive the closing of any door println!("Still here: {}", my_word); } - Poem IVRust
struct Heart; fn devotion(mine: &Heart) { // I do not need to consume you to know you // Immutably borrowed, completely safe let _view = mine; } fn main() { let my_heart = Heart; devotion(&my_heart); // Because I only borrowed your presence, // you remain entirely whole when I leave let _stills_yours = my_heart; } - Poem VRust
use std::cell::RefCell; struct Anchor { // To the world, we look quiet and unchanged core: RefCell<String>, } fn main() { let bond = Anchor { core: RefCell::new(String::from("Quiet")), }; // But internally, deep down, // we are constantly growing and rearranging *bond.core.borrow_mut() = String::from("Transformed"); } - Poem VIRust
use std::sync::Mutex; struct Focus { vision: String, } fn main() { // Protected against data races and chaos, // we share a single constant truth let NorthStar = Mutex::new(Focus { vision: String::from("Home"), }); { let mut guard = NorthStar.lock().unwrap(); // The rest of the universe must wait; // right now, we are perfectly locked in step guard.vision = String::from("Sustained"); } } - Poem VIIRust
enum Destiny { Distance(u32), Presence, Chaos, } fn encounter(state: Destiny) { match state { Destiny::Presence => println!("Silence drops its guard."), Destiny::Distance(miles) => println!("The thread holds across {} miles.", miles), // The compiler forces us to handle every possibility; // love leaves no loose ends to crash the system _ => println!("We handle the rest together."), } } - Poem VIIIGo
package main import "errors" // I hate and I love. // Why do I do this, perhaps you ask? func odiEtAmo() error { hate := true love := true if hate && love { // I do not know, but I feel it happening // and I am crucified. return errors.New("excrucior") } return nil } - Poem IXGo
package main import "fmt" func main() { // Let us live, my Lesbia, and let us love kisses := make(chan int) go func() { for i := 1; ; i++ { // Give me a thousand kisses, then a hundred, // then another thousand, then a second hundred... kisses <- i } }() // When we have mixed them all together, we will confuse the count // so that no evil person can cast an envious eye knowing the total. for total := range kisses { if total > 3300 { fmt.Println("Conturbabimus illa: The count is lost to the dark.") break } } } - Poem XGo
package main type Mind struct { Obstinate bool } func (m *Mind) resolve() { // Wretched Catullus, cease to play the fool // and what you see is lost, consider lost. m.Obstinate = true } func main() { catullus := &Mind{Obstinate: false} // She does not want you. // Do not chase what flees, nor live in misery. for sheWoos := false; sheWoos; { // This block never executes again } catullus.resolve() // Obdura: stand firm, steel yourself. } - Poem XIGo
package main type Woman struct{} func (w *Woman) Promise() string { // What a woman says to an eager lover return "I love no one more than you" } func main() { lesbia := Woman{} words := lesbia.Promise() // ...should be written in the wind var wind string = words // ...and running water. var rapidWater []byte = []byte(wind) // Mutable, transient, washed away instantly rapidWater = nil } - Poem XIIGo
package main type Soul struct { Vulnerability int } type Alliance struct { // Go uses composition instead of traditional inheritance. // We embed our structures directly into one another. Me Soul You Soul } func connect() *Alliance { // Explicit initialization, no hidden magic return &Alliance{ Me: Soul{Vulnerability: 100}, You: Soul{Vulnerability: 100}, } }