Steve's Roc Apps roc-apps on GitHub

Safari Ride Chapters

Appendix: the patterns

Nine patterns kept turning up along the way. They're patterns in a loose sense: shapes of code that Roc makes easy to write and hard to break.

Name What it is Where to see it
Carried and derived Carry the few things that must persist from step to step, and derive the rest each frame RideInstant, Sky, Beacon
A sighting decides, a sprite paints A pure function answers with plain data, or a refusal, and something else turns the data into shapes Pipeline.sighting_of, TowerSighting
Places and distances One opaque type for where, a second for how far apart, and only the sums that make sense Clock and Steps, Bearing and Turn, Along and Distance
Rule and timeline One function says how far along an animation is, and a timeline, plain data, says what the animal shows at each stage EncounterPlan.stage_at and CatCrossing.crossing_timeline
The step function A value goes in, and the next value comes out Rider.rider_at_next_step, TruckJourney.truck_progress_at_next_step, Tour.step_forward
The chain of limits One value passes through independent rules, each of which can only lower it Throttle.next_acceleration
One record per space Field names say which coordinate system a point is in RoadPoint, RiderPoint, PointAtHeight, Point
Rehearsal Run the real rules on a pretend copy, read the result, and throw it away Coast, LeanSearch, Motorcycle.cross_bend_if_on_road
Invariants by crash A fact that holds whenever the program is right is enforced with a crash, which stops the program at the first value that breaks it Fraction.of, Clock.minus, VehicleLimits.braking_to