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., 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. and CatCrossing. |
| The step function | A value goes in, and the next value comes out | Rider., TruckJourney., Tour. |
| The chain of limits | One value passes through independent rules, each of which can only lower it | Throttle. |
| 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. |
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., Clock., VehicleLimits. |