on master help sign in
Merge pull request #885 from urbit/bucpam

bucpam rune entry

commitac27980e6fd6483e66ca2d83c93f2d4fa1e3cb09 authorpoprox <51337059+syzygyzer@users.noreply.github.com> dateTue 23 Jun 2020, 13:04 (6 years ago) parent394e538f2bf9ca
1 file changed+43−1
reference/hoon-expressions/rune/buc.md+43−1
reference/hoon-expressions/rune/buc.md+43−1
@@ -301,11 +301,52 @@ Regular: **2-fixed**.
301301[%baz p=0]
302302```
303303
304+### $& "bucpam"
305+
306+`[%bspd p=spec q=hoon]`: repair a value of a tagged union type
307+
308+##### Syntax
309+
310+Regular: **2-fixed**.
311+
312+```hoon
313+$&(combined-mold=spec normalizing-gate=hoon)
314+```
315+Here `combined-mold` is a tagged union type (typically made with `$%`) and `normalizing-gate` is a
316+gate which accepts values of `combined-mold` and normalizes them to be of one particular type
317+in `combined-mold`.
318+
319+##### Normalizes to
320+
321+The product of the normalizing gate and sample.
322+
323+##### Defaults to
324+
325+The default of the last type listed in `p`, normalized with the normalizing gate.
326+
327+##### Discussion
328+
329+This rune is used to "upgrade" or "repair" values of a structure, typically from
330+an old version to a new version. For example, this may happen when migrating state after
331+updating an app.
332+
333+##### Examples
334+
335+```hoon
336++$ old [%0 @]
337++$ new [%1 ^]
338++$ combined $%(old new)
339++$ adapting $&(combined |=(?-(-.a %0 [%1 1 +.a], %1 a)))
340+```
341+Here `adapting` is a structure that bunts to `[%1 ^]` but also normalizes from
342+`[%0 @]` if called on such a noun.
343+
344+
304345### `$~` "bucsig"
305346
306347`[%bssg p=hoon q=spec]`: define a custom type default value
307348
308−## Product
349+##### Product
309350
310351Creates a structure (custom type) just like `q`, except its default value is `p`.
311352
@@ -343,6 +384,7 @@ First, let's define a type without using `$~`:
343384[%two 478.560.413.032]
344385
345386> *b
387+
346388%$
347389
348390> *@tas