Update engine-pattern.md

This commit is contained in:
Sigilante 2022-11-11 13:52:31 -06:00 committed by GitHub
parent 22e700999c
commit 4e21e09102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,7 +180,7 @@ To recap at this point: the engine pattern represents a way of using a helper c
How could you use the engine pattern today? A Gall agent is a door with a sample of the `bowl` and an associated `state`. `card`s are issued from the agent to Arvo and other agents, while `gift`s and incoming `card`s are handled by the agent. This means that agents need to compose lists of `card`s—the ubiquitous `(quip card state)` return type. This pair of `(list card)` and `agent:gall` allow us to produce effects (`card`s) and maintain state.
A Gall agent sometimes needs to issue a lot of state changes using cards. This can lead to awkward chains of `=^` tisket pins as several cards are aggregated together before resolving. (Cards all happen “at the same time”, meaning before any mutations are applied to the state, but composing several cards together can be vexing.) As an alternative, a helper core (the “engine”) can be used to encapsulate complexity with card handling. When used well, the engine pattern can lead to cleaner code factoring and sequestration of more complex logic.
A Gall agent sometimes needs to issue a lot of state changes using cards. This can lead to awkward chains of `=^` tisket pins as several cards are aggregated together before resolving. (Card effects all resolve “at the same time” or in the same event like a `%=` centis resolution, meaning before any mutations are applied to the state, but composing several cards together can be vexing.) As an alternative, a helper core (the “engine”) can be used to encapsulate complexity with card handling. When used well, the engine pattern can lead to cleaner code factoring and sequestration of more complex logic.
Your basic approach will be to construct a helper core next to your Gall agent which
By convention these have been built in the same file as the Gall agent (rather than `/lib`) because they frequently need to access agent state, but as with `/lib/hood/kiln.hoon`, there are elegant ways to avoid this necessity.