on master help sign in
Merge pull request #1099 from urbit/roll-reel-revise
d3d3aa6poprox
hoon/reference/stdlib/2b.md+60−9
@@ -564,6 +564,11 @@ the final value of the accumulator.
564(To "slam" means to call a gate and give it a sample/samples. In this instance,
564(To "slam" means to call a gate and give it a sample/samples. In this instance,
565`a` is the list of samples that are given to the gate b.)
565`a` is the list of samples that are given to the gate b.)
566
566
567+The initial value of the accumulator is the bunt of `b`'s second argument (`+<+`). This can occasionally produce
568+undesired behavior (see examples). If you need more control over the initial
569+value, try making use of `$_` and `|:`, or perhaps [`+spin`](#spin) or
570+[`+spun`](#spun).
571+
567#### Accepts
572#### Accepts
568
573
569`a` is a list.
574`a` is a list.
@@ -600,6 +605,27 @@ The accumulator, which is a noun.
600 ! exit
605 ! exit
601```
606```
602
607
608+`+mul`'s default sample is 1, so calling `+reel` with `+mul` yields the expected behavior:
609+```
610+> *mul
611+1
612+
613+> (reel `(list @)`~[1 2 3 4] mul)
614+24
615+```
616+However, if you build a gate that uses `+mul` like so, the sample defaults to 0
617+since that is the bunt of `@`:
618+```
619+> (reel `(list @)`~[1 2 3 4] |=([a=@ b=@] (mul a b)))
620+0
621+```
622+We can fix this with `|:`:
623+```
624+> (reel `(list @)`~[1 2 3 4] |:([a=1 b=1] (mul a b)))
625+24
626+```
627+
628+
603
629
604---
630---
605### `++roll`
631### `++roll`
@@ -613,6 +639,11 @@ producing the final value of the accumulator.
613(To "slam" means to call a gate and give it a sample/samples. In this instance,
639(To "slam" means to call a gate and give it a sample/samples. In this instance,
614`a` is the list of samples that are given to the gate b.)
640`a` is the list of samples that are given to the gate b.)
615
641
642+The initial value of the accumulator is `b`'s second argument (`+<+`). This can
643+occasionally produce undesired behavior (see examples). If you need more control
644+over the initial value, try making use of `$_` and `|:`, or perhaps
645+[`+spin`](#spin) or [`+spun`](#spun).
646+
616#### Accepts
647#### Accepts
617
648
618`a` is a list.
649`a` is a list.
@@ -638,15 +669,35 @@ The accumulator, which is a noun.
638#### Examples
669#### Examples
639
670
640```
671```
641− > (roll `(list @)`[1 2 3 4 5 ~] add)
672+> (roll `(list @)`[1 2 3 4 5 ~] add)
642− q=15
673+q=15
643
674
644− > (roll `(list @)`[6 3 1 ~] sub)
675+> (roll `(list @)`[6 3 1 ~] sub)
645− ! subtract-underflow
676+! subtract-underflow
646− ! exit
677+! exit
678+
679+> (roll `(list @)`[1 3 6 ~] sub)
680+q=4
681+```
682+
683+`+mul`'s default sample is 1, so calling `+roll` with `+mul` yields the expected behavior:
684+```
685+> *mul
686+1
647
687
648− > (roll `(list @)`[1 3 6 ~] sub)
688+> (roll `(list @)`~[1 2 3 4] mul)
649− q=4
689+24
690+```
691+However, if you build a gate that uses `+mul` like so, the sample defaults to 0
692+since that is the bunt of `@`:
693+```
694+> (roll `(list @)`~[1 2 3 4] |=([a=@ b=@] (mul a b)))
695+0
696+```
697+We can fix this with `|:`:
698+```
699+> (roll `(list @)`~[1 2 3 4] |:([a=1 b=1] (mul a b)))
700+24
650```
701```
651
702
652
703
@@ -1042,7 +1093,7 @@ A list
1042
1093
1043
1094
1044---
1095---
1045−### `++spin`
1096+### `++spin` {#spin}
1046
1097
1047Gate to list, with state
1098Gate to list, with state
1048
1099
@@ -1107,7 +1158,7 @@ is the continuation of the RNG.
1107
1158
1108
1159
1109---
1160---
1110−### `++spun`
1161+### `++spun` {#spun}
1111
1162
1112Gate to list, with state
1163Gate to list, with state
1113
1164