on 65048fe help sign in
45 lines 856 B history raw
1### `++roll`
3Left fold
5Left fold: moves left to right across a list `a`, recursively slamming a
6binary [gate]() `b` with an element from the [`++list`]() and an accumulator,
7producing the final value of the accumulator.
9Accepts
10-------
12`b` is a binary [gate]().
14Produces
15--------
17The accumulator, which is a [noun]().
19Source
20------
22 ++ roll :: left fold
23 ~/ %roll
24 |* [a=(list) b=_|=([* *] +<+)]
25 |- ^+ +<+.b
26 ?~ a
27 +<+.b
28 $(a t.a, b b(+<+ (b i.a +<+.b)))
30Examples
31--------
33 ~zod/try=> =sum =|([p=@ q=@] |.((add p q)))
34 ~zod/try=> (roll (limo [1 2 3 4 5 ~]) sum)
35 q=15
36 ~zod/try=> =a =|([p=@ q=@] |.((sub p q)))
37 ~zod/try=> (roll (limo [6 3 1 ~]) a)
38 ! subtract-underflow
39 ! exit
40 ~zod/try=> (roll (limo [1 3 6 ~]) a)
41 q=4
45***