Chapter 21
Records
Tour.step_back makes a new tour with a record update, and record updates run all through the ride. A Roc record stays as it was made, so a field with a new value means a new record.
The motorcycle is a record of four fields: its place on the route, which way it's turned, its speed and its lean. The rider's step uses this function to hold the bike at the end of the road:
## This motorcycle stopped dead at `at` on its segment.
stopped_at : Motorcycle, Along -> Motorcycle
stopped_at = |motorcycle, at| {
place = motorcycle.route_place
{
..motorcycle,
route_place: { ..place, road_point: { ..place.road_point, along: at } },
speed: Speed.at_rest,
}
}
Here's the function, piece by piece:
| Code | Term | What it says |
|---|---|---|
{ . |
record update | A new record with every field of motorcycle, except the ones named after it. |
route_ |
record update | The new route_ is an update of the old place in turn, and its road_ is an update of the old point. So the new motorcycle's along is at, three records deep. |
speed: Speed. |
field | A second field with a new value. |
motorcycle itself stays as it was, and so do place and its road point. Every step of the ride builds its next moment as a new record, out of the old moment's fields.